• 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!

Compiling add total damage on function onkill (rev 0.4)

knightxd

Member
Joined
Feb 21, 2009
Messages
211
Reaction score
16
Location
Rio de Janeiro
well i'm trying to add total damage to function on kill... to work like this..

//onKill(cid, target, damage, flags, total)

but here is the thing, total returns aways "20" idk why...
[cpp]
uint32_t CreatureEvent::executeKill(Creature* creature, Creature* target, const DeathEntry& entry)
{
//onKill(cid, target, damage, flags, total)
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 total = " << entry.getTot() << std::endl;
#ifdef __WAR_SYSTEM__
scriptstream << "local war = " << entry.getWar().war << std::endl;
#endif

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.getTot());
#ifndef __WAR_SYSTEM__

bool result = m_interface->callFunction(5);
#else
lua_pushnumber(L, entry.getWar().war);

bool result = m_interface->callFunction(6);
#endif
m_interface->releaseEnv();
return result;
}
}
else
{
std::clog << "[Error - CreatureEvent::executeKill] Call stack overflow." << std::endl;
return 0;
}
}[/cpp]

and on creature.cpp and creature.h..
[cpp]
int32_t damage;
int32_t totaldamage;[/cpp]

[cpp]
int32_t getDamage() const {return damage;}
int32_t getTot() const {return totaldamage;}
[/cpp]

[cpp]
DeathList Creature::getKillers()
{
DeathList list;
CountMap::const_iterator it;

Creature* lhc = NULL;
if((lhc = g_game.getCreatureByID(lastHitCreature)))
{
int32_t damage = 0;
if((it = damageMap.find(lastHitCreature)) != damageMap.end())
damage = it->second.total;

list.push_back(DeathEntry(lhc, damage));
}
else
list.push_back(DeathEntry(getCombatName(lastDamageSource), 0));

int32_t requiredTime = g_config.getNumber(ConfigManager::DEATHLIST_REQUIRED_TIME);
int64_t now = OTSYS_TIME();

CountBlock_t cb;
for(it = damageMap.begin(); it != damageMap.end(); ++it)
{
cb = it->second;
if((now - cb.ticks) > requiredTime)
continue;

int32_t totaldamage = 0;
totaldamage += it->second.total;

Creature* mdc = g_game.getCreatureByID(it->first);
if(!mdc || mdc == lhc || (lhc && (mdc->getMaster() == lhc || lhc->getMaster() == mdc)))
continue;

bool deny = false;
for(DeathList::iterator fit = list.begin(); fit != list.end(); ++fit)
{
if(fit->isNameKill())
continue;

Creature* tmp = fit->getKillerCreature();
if(!(mdc->getName() == tmp->getName() && mdc->getMaster() == tmp->getMaster()) &&
(!mdc->getMaster() || (mdc->getMaster() != tmp && mdc->getMaster() != tmp->getMaster()))
&& (mdc->getSummonCount() <= 0 || tmp->getMaster() != mdc))
continue;

deny = true;
break;
}

if(!deny)
list.push_back(DeathEntry(mdc, cb.total));
}

if(list.size() > 1)
std::sort(list.begin() + 1, list.end(), DeathLessThan());

return list;
}[/cpp]
 
Back
Top Bottom