• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua onKill not working with test script?

kuhi

Premium User
Premium User
Joined
Aug 26, 2012
Messages
197
Solutions
1
Reaction score
79
Location
x64dbg
GitHub
Kuhicop
I'm trying to make an onKill event script just for learning:
Code:
function onKill(cid, target, lastHit)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "On script")
    return true
end

It's very simple, and I don't know why it's not working... no errors in console neither other infos...
This is the creaturescripts.xml line I've added:
Code:
<event name="tasks" type="kill" script="tasks.lua"/>

And yea my file name is tasks.lua and it's inside data\creaturescripts\scripts xd

This is the creatureevent.cpp:
Code:
bool CreatureEvent::executeOnKill(Creature* creature, Creature* target, bool lastHit)
{
    //onKill(cid, target, lasthit)
    if(m_scriptInterface->reserveScriptEnv()){
        ScriptEnviroment* env = m_scriptInterface->getScriptEnv();

        #ifdef __DEBUG_LUASCRIPTS__
        std::stringstream desc;
        desc << creature->getName();
        env->setEventDesc(desc.str());
        #endif

        env->setScriptId(m_scriptId, m_scriptInterface);
        env->setRealPos(creature->getPosition());

        uint32_t cid = env->addThing(creature);
        uint32_t targetId = env->addThing(target);

        lua_State* L = m_scriptInterface->getLuaState();

        m_scriptInterface->pushFunction(m_scriptId);
        lua_pushnumber(L, cid);
        lua_pushnumber(L, targetId);
        lua_pushboolean(L, (lastHit ? true : false) );

        bool result = m_scriptInterface->callFunction(3);
        m_scriptInterface->releaseScriptEnv();

        return result;
    }
    else{
        std::cout << "[Error] __ENABLE_SERVER_DIAGNOSTIC__Call stack overflow. CreatureEvent::executeOnKill" << std::endl;
        return 0;
    }
}

I'm just trying to kill rats and nothing happens, this should bring a msg after killing the rat

This is OTHire 0.0.3
 
Back
Top