HowTo: Developing New LUA Functions
Posted: Fri Aug 02, 2013 5:57 pm
In all my years here, I do not think I have ever successfully developed a LUA Function on my own - today is no different. So my attempt with this post is to get some things documented so I don't have to ask questions anymore.
New LUA Function: Interrupt
Just getting the new function into the LUA system seems to take 3 parts - LuaInterface.cpp (registering), and the function/declaration in LuaFunctions.cpp/h.
Register the LUA Function (LuaInterface.cpp):
Declare a new function (LuaFunctions.h):
Build out the new function (LuaFunctions.cpp):
That part is easy. Now the part I do not understand is how to access all the functions outside the Lua system that will cause the target to become Interrupted by my spell/script.
UPDATED! With the guidance below, I have updated this OP to show the full build out of this function. Thanks guys!
FYI, this is for my first CoE+ spell "Provoke", and already ran into something I need help with
Thanks in advance
New LUA Function: Interrupt
Just getting the new function into the LUA system seems to take 3 parts - LuaInterface.cpp (registering), and the function/declaration in LuaFunctions.cpp/h.
Register the LUA Function (LuaInterface.cpp):
Code: Select all
lua_register(state, "Interrupt", EQ2Emu_lua_Interrupt);Code: Select all
int EQ2Emu_lua_Interrupt(lua_State* state);Code: Select all
int EQ2Emu_lua_Interrupt(lua_State* state)
{
if (!lua_interface)
return 0;
Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
Spawn* target = lua_interface->GetSpawn(state, 2);
if (!caster) {
lua_interface->LogError("LUA Interrupt command error: caster is not a valid spawn");
return 0;
}
if(!target) {
lua_interface->LogError("LUA Interrupt command error: target is not a valid spawn");
return 0;
}
if (!target->IsEntity()) {
lua_interface->LogError("LUA Interrupt command error: Target is not an entity");
return 0;
}
caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
return 0;
}UPDATED! With the guidance below, I have updated this OP to show the full build out of this function. Thanks guys!
FYI, this is for my first CoE+ spell "Provoke", and already ran into something I need help with
Thanks in advance