• 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 Function onKill

_Aion_

Nothing Else
Joined
Jan 19, 2010
Messages
400
Solutions
4
Reaction score
10
Location
Jequie,Bahia,Brazil
Hello.
I'm tring to make on creatureevent that player kill boss and win reward.
script work fine, but i have one question,
how i put for only one player or 2 players win reward?
what is difference function onKill(cid, target, damage, flags,war) for function onKill(cid, target, lastHit)
I'm using OTX 2.x for 8.60
Here my script
Lua:
function onKill(cid, target, lastHit) 
--function onKill(cid, target, damage, flags,war)
  if isPlayer(cid) and isMonster(target) then
  local monster = config[getCreatureName(target)]
  if monster then
  local bag = doCreateItemEx(monster.BagId, 1)
  for i = 1,#monster.loot do
  if monster.loot[i][2] >= math.random(1,100) then
  local item = doAddContainerItem(bag, monster.loot[i][1],monster.loot[i][3])
      if (monster.use_stats) then
         for z = 1,#monster.chance_attr do
           if(monster.chance_attr[z][2] >= math.random(1,100) and ItemInfo(monster.chance_attr[z][4], monster.loot[i][1]))then
             doItemSetAttribute(item, monster.chance_attr[z][1], math.random(monster.chance_attr[z][3][1],monster.chance_attr[z][3][2]))
           end
         end
       end
  end
  end
  if(getContainerItem(bag, 0).uid > 0)then
  doSendMagicEffect(getThingPos(cid), monster.effect)
  doSendAnimatedText(getThingPos(cid), monster.animatedText[2],monster.animatedText[1])
  if monster.SendToDepot then
  doPlayerSendMailByName(getCreatureName(cid), bag, getPlayerTown(cid), "Admin")
  else
  doPlayerAddItemEx(cid, bag,true)
  doAddVipDays(cid, monster.vipDays)
  setPK(cid, monster.Pk)
  addPontos(cid, monster.Events)
  setCreatureMaxMana(cid, (getCreatureMaxMana(cid)+monster.Mana))
  setCreatureMaxHealth(cid, (getCreatureMaxHealth(cid)+monster.Health))
  doBroadcastMessage("O ".. getCreatureName(cid) .. " derrotou o ".. monster.Name .. " e recebeu a recompensa.")
  doPlayerSendTextMessage(cid, 18, "You received ".. monster.vipDays .." VIP Days, ".. monster.Events .." Events Points, ".. monster.Pk .." Pk Points, ".. monster.Mana .." Mana and ".. monster.Health .." Health.")
  end
  doPlayerSendTextMessage(cid, 25, monster.message)
  else
  doPlayerSendTextMessage(cid, 25, "Better Luck Next Time,You Got No Reward.")
  end
  end
  end
  return true
end
 
Check your source and you'll see the difference.

If you post the section for onKill in your server, we can probably help.

When your calling variables like
Code:
function onKill(cid, target, lastHit)
-- cid, target lastHit -- these are variables
If you label like this..
Code:
function onKill(a, b, c)
function onKill(dog, rabbit, frog)
It does the exact same thing as the above function.
So if your function is..
Code:
function onKill(cid, target, lastHit)
but your using the function..
Code:
function onKill(cid, target, damage, flags, war)
The server would be seeing this..
Code:
function onKill(value_1, value_2, value_3, nil, nil)
Because the last 2 variables are unknown.

And of course the values called on two different server's for these variables are different.. so the code to check player interactions are different for each server using each function.

:D

So tldr;

Post your sources onKill function.
 
Check your source and you'll see the difference.

If you post the section for onKill in your server, we can probably help.
Post your sources onKill function.

Here my sourcer code.

C++:
uint32_t CreatureEvent::executeKill(Creature* creature, Creature* target, const DeathEntry& entry)
{
    //onKill(cid, target, damage, flags)
    if(m_interface->reserveEnv())
    {
        uint32_t flags = 0;
        if(entry.isLast())
            flags |= 1;

        if(entry.isJustify())
            flags |= 2;

        if(entry.isUnjustified())
            flags |= 4;

        ScriptEnviroment* env = m_interface->getEnv();
        if(m_scripted == EVENT_SCRIPT_BUFFER)
        {
            env->setRealPos(creature->getPosition());
            std::stringstream scriptstream;
            scriptstream << "local cid = " << env->addThing(creature) << std::endl;

            scriptstream << "local target = " << env->addThing(target) << std::endl;
            scriptstream << "local damage = " << entry.getDamage() << std::endl;
            scriptstream << "local flags = " << flags << std::endl;
            scriptstream << "local war = " << entry.getWar().war << std::endl;

            if(m_scriptData)
                scriptstream << *m_scriptData;

            bool result = true;
            if(m_interface->loadBuffer(scriptstream.str()))
            {
                lua_State* L = m_interface->getState();
                result = m_interface->getGlobalBool(L, "_result", true);
            }

            m_interface->releaseEnv();
            return result;
        }
        else
        {
            #ifdef __DEBUG_LUASCRIPTS__
            std::stringstream desc;
            desc << creature->getName();
            env->setEvent(desc.str());
            #endif

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

            lua_State* L = m_interface->getState();
            m_interface->pushFunction(m_scriptId);

            lua_pushnumber(L, env->addThing(creature));
            lua_pushnumber(L, env->addThing(target));

            lua_pushnumber(L, entry.getDamage());
            lua_pushnumber(L, flags);
            lua_pushnumber(L, entry.getWar().war);

            bool result = m_interface->callFunction(5);
            m_interface->releaseEnv();
            return result;
        }
    }
    else
    {
        std::clog << "[Error - CreatureEvent::executeKill] Call stack overflow." << std::endl;
        return 0;
    }
}
 
Here my sourcer code.

C++:
uint32_t CreatureEvent::executeKill(Creature* creature, Creature* target, const DeathEntry& entry)
{
    //onKill(cid, target, damage, flags)
    if(m_interface->reserveEnv())
    {
        uint32_t flags = 0;
        if(entry.isLast())
            flags |= 1;

        if(entry.isJustify())
            flags |= 2;

        if(entry.isUnjustified())
            flags |= 4;

        ScriptEnviroment* env = m_interface->getEnv();
        if(m_scripted == EVENT_SCRIPT_BUFFER)
        {
            env->setRealPos(creature->getPosition());
            std::stringstream scriptstream;
            scriptstream << "local cid = " << env->addThing(creature) << std::endl;

            scriptstream << "local target = " << env->addThing(target) << std::endl;
            scriptstream << "local damage = " << entry.getDamage() << std::endl;
            scriptstream << "local flags = " << flags << std::endl;
            scriptstream << "local war = " << entry.getWar().war << std::endl;

            if(m_scriptData)
                scriptstream << *m_scriptData;

            bool result = true;
            if(m_interface->loadBuffer(scriptstream.str()))
            {
                lua_State* L = m_interface->getState();
                result = m_interface->getGlobalBool(L, "_result", true);
            }

            m_interface->releaseEnv();
            return result;
        }
        else
        {
            #ifdef __DEBUG_LUASCRIPTS__
            std::stringstream desc;
            desc << creature->getName();
            env->setEvent(desc.str());
            #endif

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

            lua_State* L = m_interface->getState();
            m_interface->pushFunction(m_scriptId);

            lua_pushnumber(L, env->addThing(creature));
            lua_pushnumber(L, env->addThing(target));

            lua_pushnumber(L, entry.getDamage());
            lua_pushnumber(L, flags);
            lua_pushnumber(L, entry.getWar().war);

            bool result = m_interface->callFunction(5);
            m_interface->releaseEnv();
            return result;
        }
    }
    else
    {
        std::clog << "[Error - CreatureEvent::executeKill] Call stack overflow." << std::endl;
        return 0;
    }
}
lol, so your server doesn't even use either of these lines you originally gave.
Code:
onKill(cid, target, damage, flags)
Ironically, this is the same as 0.3.7 tfs, which I use.
I did some testing awhile back.. let me find my post..
Kill player get 5 platinums

So you'd be able to give the person who performed the killing blow an award..
And with some clever jankiness.. you could see who's done the most damage to the creature as well. (addEvent with global tables)
 
Back
Top