• 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 Problem HELP! [TFS 1.1]

  • Thread starter Thread starter Deleted member 141899
  • Start date Start date
D

Deleted member 141899

Guest
Hi friends,

Have a problem with this script here on the last boss of wote in which to kill the "Snake God Essence" it will summoning new forms ..

The problem is that it seems that onKill function is not correctly running "LastHit" I think there is no such parameter in tfs 1.1 ... that is, if two people kill the boss, the event runs twice, leading to summon multiple bosses : S ..

Already I tried to change the function to onDeath and onPrepareDeath but as I am not very experienced in lua it still fails ..

Code:
local bossForms = {
['snake god essence'] = {
text = 'IT\'S NOT THAT EASY MORTALS! FEEL THE POWER OF THE GOD!',
newForm = 'snake thing'
},
['snake thing'] = {
text = 'NOOO! NOW YOU HERETICS WILL FACE MY GODLY WRATH!',
newForm = 'lizard abomination'
},
['lizard abomination'] = {
text = 'YOU ... WILL ... PAY WITH ETERNITY ... OF AGONY!',
newForm = 'mutated zalamon'
}
}

function onKill(player, target)
local targetMonster = target:getMonster()
if not targetMonster then
return true
end

if targetMonster:getName():lower() == 'mutated zalamon' then
Game.setStorageValue(Storage.WrathoftheEmperor.Mission11, -1)
return true
end

local bossConfig = bossForms[targetMonster:getName():lower()]
if not bossConfig then
return true
end

Game.createMonster(bossConfig.newForm, targetMonster:getPosition(), false, true)
player:say(bossConfig.text, TALKTYPE_MONSTER_SAY)
return true
end

can someone help me please?
 
onKill is meant to fire for the killer, not the dead. It will fire multiple times if multiple players kill the monster, too.
 
to add the function lasthit, evan I fix check out .
https://otland.net/threads/last-hit-tfs-1-1.231271/#post-2228840


Then he'd have to register every creature for this "lasthit" thing to work.

There is no clean way of doing this without source editing.

Look at this line (Creature: onKilledCreature()), the 'bool' is for lastHit.
It's currently unnamed and has no use for general creature kills.
If you want to use it, just give the parameter a name and pass it into the executeOnKill() event function.
Now you can use that boolean value inside the onKill() script event function.

Below are the code changes for it to work, good luck.
creature.cpp
Code:
bool Creature::onKilledCreature(Creature* target, bool lastHit)
{
    if (master) {
        master->onKilledCreature(target);
    }

    //scripting event - onKill
    const CreatureEventList& killEvents = getCreatureEvents(CREATURE_EVENT_KILL);
    for (CreatureEvent* killEvent : killEvents) {
        killEvent->executeOnKill(this, target, lastHit);
    }
    return false;
}

creatureevent.cpp
Code:
bool CreatureEvent::executeOnKill(Creature* creature, Creature* target, bool lastHit)
{
    //onKill(creature, target, lastHit)
    if (!m_scriptInterface->reserveScriptEnv()) {
       std::cout << "[Error - CreatureEvent::executeOnKill] Call stack overflow" << std::endl;
       return false;
    }

    ScriptEnvironment* env = m_scriptInterface->getScriptEnv();
    env->setScriptId(m_scriptId, m_scriptInterface);

    lua_State* L = m_scriptInterface->getLuaState();

    m_scriptInterface->pushFunction(m_scriptId);
    LuaScriptInterface::pushUserdata<Creature>(L, creature);
    LuaScriptInterface::setCreatureMetatable(L, -1, creature);
    LuaScriptInterface::pushUserdata<Creature>(L, target);
    LuaScriptInterface::setCreatureMetatable(L, -1, target);
    LuaScriptInterface::pushBoolean(L, lastHit);

    return m_scriptInterface->callFunction(3);
}

creatureevent.h
Code:
bool executeOnKill(Creature* creature, Creature* target, bool lastHit);
 
I saw this topic but I was looking for another way to solve it, maybe changing for a onDeath function, but do not know how to do: S
 
Back
Top