1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-06-07 17:11:56 +00:00

Implement scripts to send msg() to shots

+ Lua func shot_msg()
This commit is contained in:
fgenesis 2025-04-01 05:56:16 +02:00
parent 65248a274f
commit a477c6d59b
3 changed files with 40 additions and 0 deletions

View file

@ -5915,6 +5915,19 @@ luaFunc(node_msg)
luaReturnNil();
}
luaFunc(shot_msg)
{
Shot *s = getShot(L);
if (s)
{
// pass everything on the stack except the entity pointer
int res = s->messageVariadic(L, lua_gettop(L) - 1);
if (res >= 0)
return res;
}
luaReturnNil();
}
luaFunc(entity_updateCurrents)
{
Entity *e = entity(L);
@ -10366,6 +10379,7 @@ static const struct {
luaRegister(entity_getPushDamage),
luaRegister(entity_msg),
luaRegister(node_msg),
luaRegister(shot_msg),
luaRegister(entity_updateMovement),
luaRegister(entity_updateCurrents),
luaRegister(entity_updateLocalWarpAreas),

View file

@ -933,3 +933,25 @@ void Shot::rotateToVec(Vector addVec, float time, int offsetAngle)
}
}
void Shot::luaDebugMsg(const std::string &func, const std::string &msg)
{
debugLog(std::string("luaScriptError: Shot [") + this->getName() + "]: " + func + " : " + msg);
}
int Shot::callVariadic(const char* func, lua_State* L, int nparams)
{
if (script)
{
int res = script->callVariadic(func, L, nparams, this);
if (res < 0)
luaDebugMsg(func, script->getLastError());
else
return res;
}
return 0;
}
int Shot::messageVariadic(lua_State * L, int nparams)
{
return callVariadic("msg", L, nparams);
}

View file

@ -124,6 +124,10 @@ public:
inline bool isActive() const { return !dead; }
inline const char *getName() const { return shotData ? shotData->name.c_str() : ""; }
int callVariadic(const char *func, lua_State *L, int nparams);
int messageVariadic(lua_State *L, int nparams);
void luaDebugMsg(const std::string &func, const std::string &msg);
float extraDamage;
float homingness;
float lifeTime;