• 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 Last hit tfs 1.1

Scrappy Coco

Member
Joined
Dec 27, 2014
Messages
95
Reaction score
17
there is a function that meets last hit
Code:
onKill function ( cid , target, lasthit )
not work

¿there will be some other function that meets that or any way to edit the source code thanks ..?
 
Code:
function onKill(cid, target)
    local creature = Creature(target)
    local targetGray = creature:getName():lower()

    if not targetGray then
      return true
    end

    for id, damage in pairs(creature:getDamageMap()) do
      local player = Player(id)
      if player then
    target:say(target:getName()..  "Owned By:"  .. player:getName() ..  "!", TALKTYPE_MONSTER_SAY)
    end
   end
end

example : Kill 3 players 1 and this message appears with the name of the 3 players who attacked him

Owned By:" chicoche "!"
Owned By:" .. maria .. "!"
Owned By:" .. evil puncker .. "!"

I want esque single out the name of the player who made the last hit
 
so I had it but did not work

Code:
function onKill(cid, target, lasthit)
     if(isPlayer(cid) and isPlayer(target) and lasthit) then
        local player = Player(cid)
        target:say(target:getName()..  "Owned By:"  .. player:getName() ..  "!", TALKTYPE_MONSTER_SAY)
    end
    return true
end
 
Since you are using TFS 1.1, you have to change your function parametters.
Code:
onKill(creature, target)

not tested.
Code:
function onKill(creature, target)
    if creature:isPlayer and target:isPlayer then
        target:say(target:getName().. "Owned By:" .. creature:getName() .. "!", TALKTYPE_MONSTER_SAY)
     end
    return true
end
 
Last edited:
Since you are using TFS 1.1, you have to change your function parametters.
Code:
onKill(creature, target)

not tested.
Code:
function onKill(creature, target)
    if creature:isPlayer and target:isPlayer then
        target:say(target:getName().. "Owned By:" .. creature:getName() .. "!", TALKTYPE_MONSTER_SAY)
     end
    return true
end

to What I mean is that occupied the lasthit when kill a player just say the name of who gave the lasthit .
however if I add also you give me
all who attacked the ( target) will leave message and tell you that ( target) dead by all who attacked not know if you understand me ?
 
You should use onDeath instead of onKill then.

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);
 
Back
Top