Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint32_t CreatureEvent::executeDeath(Creature* creature, Item* corpse, DeathList deathList)
- {
- //onDeath(cid, corpse, deathList)
- if(m_interface->reserveEnv())
- {
- 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;
- env->streamThing(scriptstream, "corpse", corpse, env->addThing(corpse));
- scriptstream << "local deathList = {}" << std::endl;
- for(DeathList::iterator it = deathList.begin(); it != deathList.end(); ++it)
- {
- scriptstream << "deathList:insert(";
- if(it->isCreatureKill())
- scriptstream << env->addThing(it->getKillerCreature());
- else
- scriptstream << it->getKillerName();
- scriptstream << ")" << std::endl;
- }
- 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__
- char desc[35];
- sprintf(desc, "%s", creature->getName().c_str());
- env->setEventDesc(desc);
- #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));
- LuaScriptInterface::pushThing(L, corpse, env->addThing(corpse));
- lua_newtable(L);
- DeathList::iterator it = deathList.begin();
- for(int32_t i = 1; it != deathList.end(); ++it, ++i)
- {
- lua_pushnumber(L, i);
- if(it->isCreatureKill())
- lua_pushnumber(L, env->addThing(it->getKillerCreature()));
- else
- lua_pushstring(L, it->getKillerName().c_str());
- lua_settable(L, -3);
- }
- bool result = m_interface->callFunction(3);
- m_interface->releaseEnv();
- return result;
- }
- }
- else
- {
- std::cout << "[Error - CreatureEvent::executeDeath] Call stack overflow." << std::endl;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement