Dankoo
Active Member
- Joined
- Sep 4, 2010
- Messages
- 1,007
- Reaction score
- 27
Maybe I found the source of the bug ( literally lol source ~ sources *-* )
creature.cpp 0.3b1pl1
creature.cpp 0.4
creatureevent.cpp 0.4
creatureevent.cpp 0.3b1pl1
So, I've tried to add that code on creature.cpp to 0.4 but didn't work.
Based on this there's any modification I can do to make it work? (Both in script or sources) I'll keep trying here, but if you could take a look at the codes and give me a light, I would be very grateful!
Edit
An screenshot of the error message I receive when add onkill function to creature.cpp on 0.4:
http://img256.imageshack.us/img256/7420/63661316.jpg
creature.cpp 0.3b1pl1
Code:
void Creature::onKilledCreature(Creature* target)
{
if(getMaster())
getMaster()->onKilledCreature(target);
//scripting event - onKill
CreatureEvent* eventKill = getCreatureEvent(CREATURE_EVENT_KILL);
if(eventKill)
eventKill->executeOnKill(this, target);
}
creature.cpp 0.4
Code:
bool Creature::onKilledCreature(Creature* target, DeathEntry& entry)
{
bool ret = true;
if(master)
ret = master->onKilledCreature(target, entry);
CreatureEventList killEvents = getCreatureEvents(CREATURE_EVENT_KILL);
if(!entry.isLast())
{
for(CreatureEventList::iterator it = killEvents.begin(); it != killEvents.end(); ++it)
(*it)->executeKill(this, target, entry);
return true;
}
for(CreatureEventList::iterator it = killEvents.begin(); it != killEvents.end(); ++it)
{
if(!(*it)->executeKill(this, target, entry) && ret)
ret = false;
}
return ret;
}
creatureevent.cpp 0.4
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;
}
}
uint32_t CreatureEvent::executeDeath(Creature* creature, Item* corpse, DeathList deathList)
{
creatureevent.cpp 0.3b1pl1
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;
}
}
uint32_t CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* lastHitKiller, Creature* mostDamageKiller)
{
So, I've tried to add that code on creature.cpp to 0.4 but didn't work.
Based on this there's any modification I can do to make it work? (Both in script or sources) I'll keep trying here, but if you could take a look at the codes and give me a light, I would be very grateful!
Edit
An screenshot of the error message I receive when add onkill function to creature.cpp on 0.4:
http://img256.imageshack.us/img256/7420/63661316.jpg
Last edited: