New LUA Function: AddSpellTimer

Discussions on development of both the EQ2Emulator LUA Script Engine and Script specifications

Moderator: Team Members

Post Reply
Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

New LUA Function: AddSpellTimer

Post by Jabantiz » Tue Dec 10, 2013 8:20 pm

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.
Last edited by Jabantiz on Thu Jan 16, 2014 3:00 pm, edited 1 time in total.
Reason: Added wiki link

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: New LUA Function: AddSpellTimer

Post by John Adams » Wed Dec 11, 2013 9:52 am

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?

User avatar
Zcoretri
Team Member
Posts: 1642
Joined: Fri Jul 27, 2007 12:55 pm
Location: SoCal

Re: New LUA Function: AddSpellTimer

Post by Zcoretri » Wed Dec 11, 2013 10:46 am

I think he is saying we have to include all the parameters that are in the cast, tick remove functions.

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: New LUA Function: AddSpellTimer

Post by Jabantiz » Wed Dec 11, 2013 1:53 pm

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

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: New LUA Function: AddSpellTimer

Post by Jabantiz » Tue Jan 07, 2014 4:51 pm

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

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: New LUA Function: AddSpellTimer

Post by John Adams » Fri Jan 10, 2014 3:53 pm

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

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: New LUA Function: AddSpellTimer

Post by Jabantiz » Fri Jan 10, 2014 4:17 pm

Thought ZeroMemory was standard, sorry about that, and yes your code will fix the issue, will add it and commit.

EDIT: committed

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: New LUA Function: AddSpellTimer

Post by John Adams » Sat Jan 11, 2014 3:44 pm

I stole it from somewhere else that had ZeroMemory used :D

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

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: New LUA Function: AddSpellTimer

Post by Jabantiz » Thu Jan 16, 2014 3:02 pm

Found a rare crash bug when the timer is removed and fixed it, also added a wiki link to the first post.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests