Page 1 of 1

New LUA Function: AddSpellTimer

Posted: Tue Dec 10, 2013 8:20 pm
by Jabantiz
No wiki yet as this function will change, just wanted to get basic functionality committed so others can test.
AddSpellTimer()

AddSpellTimer(int32 time, string function)
time = time, in milliseconds, when the function should be called
function = function to call when time has passed

Example:

Code: Select all

function cast(Caster, Target)
	AddSpellTimer(2000, "TestFunction")
end

function TestFunction(Caster, Target)
	Say(Caster, "Timer Test")
end
This is a spell only function so the call back function, TestFunction in the example, will get the same parameters as cast, tick, and remove (including the spell data)

Let me know if this works for every one before I expand on it.

Re: New LUA Function: AddSpellTimer

Posted: Wed Dec 11, 2013 9:52 am
by John Adams
Jabantiz wrote:This is a spell only function so the call back function, TestFunction in the example, will get the same parameters as cast, tick, and remove (including the spell data)
Does this mean we do not have to put all the params in the function TestFunction(Caster, Target, param1, param2, param3)? They are inherited?

If so, couldn't we do that for tick and remove, so we're not filling LUA with tons of function params?

Re: New LUA Function: AddSpellTimer

Posted: Wed Dec 11, 2013 10:46 am
by Zcoretri
I think he is saying we have to include all the parameters that are in the cast, tick remove functions.

Re: New LUA Function: AddSpellTimer

Posted: Wed Dec 11, 2013 1:53 pm
by Jabantiz
Zcoretri wrote:I think he is saying we have to include all the parameters that are in the cast, tick remove functions.
This is correct

Re: New LUA Function: AddSpellTimer

Posted: Tue Jan 07, 2014 4:51 pm
by Jabantiz
Added two more params to this function, both optional, both spawns, they will allow you to override the caster and target that is sent to the call back function.

Code: Select all

function cast(Caster, Target)
    local Spawn1 = GetSomeRandomSpawn()
    local Spawn2 = GetSomeRandomSpawn()
    AddSpellTimer(1000, TestFunction, Spawn1, Spawn2)
end

function TestFunction(Caster, Target)
    -- Caster = Spawn1
    -- Target = Spawn2
end

Re: New LUA Function: AddSpellTimer

Posted: Fri Jan 10, 2014 3:53 pm
by John Adams
Linux won't compile with this.
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_AddSpawnIDAccess(lua_State*)’:
LuaFunctions.cpp:5202: warning: comparison between signed and unsigned integer expressions
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State*)’:
LuaFunctions.cpp:5233: warning: comparison between signed and unsigned integer expressions
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_AddSpellTimer(lua_State*)’:
LuaFunctions.cpp:6291: error: ‘ZeroMemory’ was not declared in this scope

LuaFunctions.cpp: In function ‘int EQ2Emu_lua_Resurrect(lua_State*)’:
LuaFunctions.cpp:6334: warning: comparison between signed and unsigned integer expressions
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_SetVision(lua_State*)’:
LuaFunctions.cpp:6434: warning: comparison between signed and unsigned integer expressions
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_BlurVision(lua_State*)’:
LuaFunctions.cpp:6470: warning: comparison between signed and unsigned integer expressions
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_BreatheUnderwater(lua_State*)’:
LuaFunctions.cpp:6506: warning: comparison between signed and unsigned integer expressions
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_CureByType(lua_State*)’:
LuaFunctions.cpp:6729: warning: comparison between signed and unsigned integer expressions
LuaFunctions.cpp: In function ‘int EQ2Emu_lua_CureByControlEffect(lua_State*)’:
LuaFunctions.cpp:6769: warning: comparison between signed and unsigned integer expressions
make: *** [LuaFunctions.o] Error 1
make: *** Waiting for unfinished jobs....
LuaInterface.cpp: In member function ‘bool LuaInterface::GetBooleanValue(lua_State*, int8)’:
LuaInterface.cpp:1142: warning: ‘val’ may be used uninitialized in this function
Compile of WorldServer FAILED! Aborting!
Might need this:

Code: Select all

	#ifdef WIN32
       ZeroMemory(timer, sizeof(SpellScriptTimer));
    #else
       bzero(timer, sizeof(SpellScriptTimer));
    #endif

Re: New LUA Function: AddSpellTimer

Posted: Fri Jan 10, 2014 4:17 pm
by Jabantiz
Thought ZeroMemory was standard, sorry about that, and yes your code will fix the issue, will add it and commit.

EDIT: committed

Re: New LUA Function: AddSpellTimer

Posted: Sat Jan 11, 2014 3:44 pm
by John Adams
I stole it from somewhere else that had ZeroMemory used :D

I'm not really a smart guy, just play one on TV.

Re: New LUA Function: AddSpellTimer

Posted: Thu Jan 16, 2014 3:02 pm
by Jabantiz
Found a rare crash bug when the timer is removed and fixed it, also added a wiki link to the first post.