knightxd
Member
solved ~ close plz
Hey guys, i was trying to make an onKill script that executes an action by loading the damage done on the monster killed, its working just fine as executing the action, but its the same action for everybody, don't matter how much damage they did on it.
example, if i and a friend get a dragon down, and i did 800 damage and he 200, we get the same rewards, i was looking at tfs 0.4 source and i found "onKill(cid, target, damage, flags)", this one in 0.3.6 is "onKill(cid, target, lasthit)" i've tryed to mix it some times, but i get no result but errors...
anyone knows how to add damage to 0.3.6 source??
hope someone can find it a way :thumbup:
here 0.4 onkill
and here 0.3.6 one
Hey guys, i was trying to make an onKill script that executes an action by loading the damage done on the monster killed, its working just fine as executing the action, but its the same action for everybody, don't matter how much damage they did on it.
example, if i and a friend get a dragon down, and i did 800 damage and he 200, we get the same rewards, i was looking at tfs 0.4 source and i found "onKill(cid, target, damage, flags)", this one in 0.3.6 is "onKill(cid, target, lasthit)" i've tryed to mix it some times, but i get no result but errors...
anyone knows how to add damage to 0.3.6 source??
hope someone can find it a way :thumbup:
here 0.4 onkill
Code:
//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;
#ifdef __WAR_SYSTEM__
scriptstream << "local war = " << entry.getWar().war << std::endl;
#endif
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);
#ifndef __WAR_SYSTEM__
bool result = m_interface->callFunction(4);
#else
lua_pushnumber(L, entry.getWar().war);
bool result = m_interface->callFunction(5);
#endif
m_interface->releaseEnv();
return result;
}
}
else
{
std::clog << "[Error - CreatureEvent::executeKill] Call stack overflow." << std::endl;
return 0;
}
}
and here 0.3.6 one
Code:
//onKill(cid, target)
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);
int32_t result = m_scriptInterface->callFunction(2);
m_scriptInterface->releaseScriptEnv();
return (result == LUA_TRUE);
}
else
{
std::cout << "[Error - CreatureEvent::executeOnKill] Call stack overflow." << std::endl;
return 0;
}
}
Last edited: