Guest User

Untitled

a guest
Aug 7th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 51.57 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17. #include "otpch.h"
  18. #ifdef __DEBUG_LUASCRIPTS__
  19. #include <sstream>
  20. #endif
  21.  
  22. #include "creatureevent.h"
  23. #include "player.h"
  24. #include "tools.h"
  25.  
  26. CreatureEvents::CreatureEvents():
  27. m_interface("CreatureScript Interface")
  28. {
  29.     m_interface.initState();
  30. }
  31.  
  32. CreatureEvents::~CreatureEvents()
  33. {
  34.     for(CreatureEventList::iterator it = m_creatureEvents.begin(); it != m_creatureEvents.end(); ++it)
  35.         delete (*it);
  36.  
  37.     m_creatureEvents.clear();
  38. }
  39.  
  40. void CreatureEvents::clear()
  41. {
  42.     //clear creature events
  43.     for(CreatureEventList::iterator it = m_creatureEvents.begin(); it != m_creatureEvents.end(); ++it)
  44.         (*it)->clearEvent();
  45.  
  46.     //clear lua state
  47.     m_interface.reInitState();
  48. }
  49.  
  50. Event* CreatureEvents::getEvent(const std::string& nodeName)
  51. {
  52.     std::string tmpNodeName = asLowerCaseString(nodeName);
  53.     if(tmpNodeName == "event" || tmpNodeName == "creaturevent" || tmpNodeName == "creatureevent" || tmpNodeName == "creaturescript")
  54.         return new CreatureEvent(&m_interface);
  55.  
  56.     return NULL;
  57. }
  58.  
  59. bool CreatureEvents::registerEvent(Event* event, xmlNodePtr, bool override)
  60. {
  61.     CreatureEvent* creatureEvent = dynamic_cast<CreatureEvent*>(event);
  62.     if(!creatureEvent)
  63.         return false;
  64.  
  65.     if(creatureEvent->getEventType() == CREATURE_EVENT_NONE)
  66.     {
  67.         std::clog << "[Error - CreatureEvents::registerEvent] Trying to register event without type!" << std::endl;
  68.         return false;
  69.     }
  70.  
  71.     if(CreatureEvent* oldEvent = getEventByName(creatureEvent->getName()))
  72.     {
  73.         //if there was an event with the same type that is not loaded (happens when realoading), it is reused
  74.         if(oldEvent->getEventType() == creatureEvent->getEventType())
  75.         {
  76.             if(!oldEvent->isLoaded() || override)
  77.                 oldEvent->copyEvent(creatureEvent);
  78.  
  79.             return override;
  80.         }
  81.     }
  82.  
  83.     //if not, register it normally
  84.     m_creatureEvents.push_back(creatureEvent);
  85.     return true;
  86. }
  87.  
  88. CreatureEvent* CreatureEvents::getEventByName(const std::string& name)
  89. {
  90.     for(CreatureEventList::iterator it = m_creatureEvents.begin(); it != m_creatureEvents.end(); ++it)
  91.     {
  92.         if((*it)->getName() == name)
  93.             return (*it);
  94.     }
  95.  
  96.     return NULL;
  97. }
  98.  
  99. bool CreatureEvents::playerLogin(Player* player)
  100. {
  101.     //fire global event if is registered
  102.     bool result = true;
  103.     for(CreatureEventList::iterator it = m_creatureEvents.begin(); it != m_creatureEvents.end(); ++it)
  104.     {
  105.         if((*it)->getEventType() == CREATURE_EVENT_LOGIN && (*it)->isLoaded()
  106.             && !(*it)->executeLogin(player) && result)
  107.             result = false;
  108.     }
  109.  
  110.     return result;
  111. }
  112.  
  113. bool CreatureEvents::playerLogout(Player* player, bool forceLogout)
  114. {
  115.     //fire global event if is registered
  116.     bool result = true;
  117.     for(CreatureEventList::iterator it = m_creatureEvents.begin(); it != m_creatureEvents.end(); ++it)
  118.     {
  119.         if((*it)->getEventType() == CREATURE_EVENT_LOGOUT && (*it)->isLoaded()
  120.             && !(*it)->executeLogout(player, forceLogout) && result)
  121.             result = false;
  122.     }
  123.  
  124.     return result;
  125. }
  126.  
  127. /////////////////////////////////////
  128.  
  129. CreatureEvent::CreatureEvent(LuaInterface* _interface):
  130. Event(_interface)
  131. {
  132.     m_type = CREATURE_EVENT_NONE;
  133.     m_isLoaded = false;
  134. }
  135.  
  136. bool CreatureEvent::configureEvent(xmlNodePtr p)
  137. {
  138.     std::string str;
  139.     if(!readXMLString(p, "name", str))
  140.     {
  141.         std::clog << "[Error - CreatureEvent::configureEvent] No name for creature event." << std::endl;
  142.         return false;
  143.     }
  144.  
  145.     m_eventName = str;
  146.     if(!readXMLString(p, "type", str))
  147.     {
  148.         std::clog << "[Error - CreatureEvent::configureEvent] No type for creature event." << std::endl;
  149.         return false;
  150.     }
  151.  
  152.     std::string tmpStr = asLowerCaseString(str);
  153.     if(tmpStr == "login")
  154.         m_type = CREATURE_EVENT_LOGIN;
  155.     else if(tmpStr == "logout")
  156.         m_type = CREATURE_EVENT_LOGOUT;
  157.     else if(tmpStr == "joinchannel")
  158.         m_type = CREATURE_EVENT_CHANNEL_JOIN;
  159.     else if(tmpStr == "leavechannel")
  160.         m_type = CREATURE_EVENT_CHANNEL_LEAVE;
  161.     else if(tmpStr == "advance")
  162.         m_type = CREATURE_EVENT_ADVANCE;
  163.     else if(tmpStr == "sendmail")
  164.         m_type = CREATURE_EVENT_MAIL_SEND;
  165.     else if(tmpStr == "receivemail")
  166.         m_type = CREATURE_EVENT_MAIL_RECEIVE;
  167.     else if(tmpStr == "traderequest")
  168.         m_type = CREATURE_EVENT_TRADE_REQUEST;
  169.     else if(tmpStr == "tradeaccept")
  170.         m_type = CREATURE_EVENT_TRADE_ACCEPT;
  171.     else if(tmpStr == "textedit")
  172.         m_type = CREATURE_EVENT_TEXTEDIT;
  173.     else if(tmpStr == "reportbug")
  174.         m_type = CREATURE_EVENT_REPORTBUG;
  175.     else if(tmpStr == "look")
  176.         m_type = CREATURE_EVENT_LOOK;
  177.     else if(tmpStr == "think")
  178.         m_type = CREATURE_EVENT_THINK;
  179.     else if(tmpStr == "direction")
  180.         m_type = CREATURE_EVENT_DIRECTION;
  181.     else if(tmpStr == "outfit")
  182.         m_type = CREATURE_EVENT_OUTFIT;
  183.     else if(tmpStr == "statschange")
  184.         m_type = CREATURE_EVENT_STATSCHANGE;
  185.     else if(tmpStr == "areacombat")
  186.         m_type = CREATURE_EVENT_COMBAT_AREA;
  187.     else if(tmpStr == "push")
  188.         m_type = CREATURE_EVENT_PUSH;
  189.     else if(tmpStr == "target")
  190.         m_type = CREATURE_EVENT_TARGET;
  191.     else if(tmpStr == "follow")
  192.         m_type = CREATURE_EVENT_FOLLOW;
  193.     else if(tmpStr == "combat")
  194.         m_type = CREATURE_EVENT_COMBAT;
  195.     else if(tmpStr == "attack")
  196.         m_type = CREATURE_EVENT_ATTACK;
  197.     else if(tmpStr == "cast")
  198.         m_type = CREATURE_EVENT_CAST;
  199.     else if(tmpStr == "kill")
  200.         m_type = CREATURE_EVENT_KILL;
  201.     else if(tmpStr == "death")
  202.         m_type = CREATURE_EVENT_DEATH;
  203.     else if(tmpStr == "preparedeath")
  204.         m_type = CREATURE_EVENT_PREPAREDEATH;
  205.     else
  206.     {
  207.         std::clog << "[Error - CreatureEvent::configureEvent] No valid type for creature event." << str << std::endl;
  208.         return false;
  209.     }
  210.  
  211.     m_isLoaded = true;
  212.     return true;
  213. }
  214.  
  215. std::string CreatureEvent::getScriptEventName() const
  216. {
  217.     switch(m_type)
  218.     {
  219.         case CREATURE_EVENT_LOGIN:
  220.             return "onLogin";
  221.         case CREATURE_EVENT_LOGOUT:
  222.             return "onLogout";
  223.         case CREATURE_EVENT_CHANNEL_JOIN:
  224.             return "onJoinChannel";
  225.         case CREATURE_EVENT_CHANNEL_LEAVE:
  226.             return "onLeaveChannel";
  227.         case CREATURE_EVENT_THINK:
  228.             return "onThink";
  229.         case CREATURE_EVENT_ADVANCE:
  230.             return "onAdvance";
  231.         case CREATURE_EVENT_LOOK:
  232.             return "onLook";
  233.         case CREATURE_EVENT_DIRECTION:
  234.             return "onDirection";
  235.         case CREATURE_EVENT_OUTFIT:
  236.             return "onOutfit";
  237.         case CREATURE_EVENT_MAIL_SEND:
  238.             return "onSendMail";
  239.         case CREATURE_EVENT_MAIL_RECEIVE:
  240.             return "onReceiveMail";
  241.         case CREATURE_EVENT_TRADE_REQUEST:
  242.             return "onTradeRequest";
  243.         case CREATURE_EVENT_TRADE_ACCEPT:
  244.             return "onTradeAccept";
  245.         case CREATURE_EVENT_TEXTEDIT:
  246.             return "onTextEdit";
  247.         case CREATURE_EVENT_REPORTBUG:
  248.             return "onReportBug";
  249.         case CREATURE_EVENT_STATSCHANGE:
  250.             return "onStatsChange";
  251.         case CREATURE_EVENT_COMBAT_AREA:
  252.             return "onAreaCombat";
  253.         case CREATURE_EVENT_PUSH:
  254.             return "onPush";
  255.         case CREATURE_EVENT_TARGET:
  256.             return "onTarget";
  257.         case CREATURE_EVENT_FOLLOW:
  258.             return "onFollow";
  259.         case CREATURE_EVENT_COMBAT:
  260.             return "onCombat";
  261.         case CREATURE_EVENT_ATTACK:
  262.             return "onAttack";
  263.         case CREATURE_EVENT_CAST:
  264.             return "onCast";
  265.         case CREATURE_EVENT_KILL:
  266.             return "onKill";
  267.         case CREATURE_EVENT_DEATH:
  268.             return "onDeath";
  269.         case CREATURE_EVENT_PREPAREDEATH:
  270.             return "onPrepareDeath";
  271.         case CREATURE_EVENT_NONE:
  272.         default:
  273.             break;
  274.     }
  275.  
  276.     return "";
  277. }
  278.  
  279. std::string CreatureEvent::getScriptEventParams() const
  280. {
  281.     switch(m_type)
  282.     {
  283.         case CREATURE_EVENT_LOGIN:
  284.             return "cid";
  285.         case CREATURE_EVENT_LOGOUT:
  286.             return "cid, forceLogout";
  287.         case CREATURE_EVENT_CHANNEL_JOIN:
  288.         case CREATURE_EVENT_CHANNEL_LEAVE:
  289.             return "cid, channel, users";
  290.         case CREATURE_EVENT_ADVANCE:
  291.             return "cid, skill, oldLevel, newLevel";
  292.         case CREATURE_EVENT_LOOK:
  293.             return "cid, thing, position, lookDistance";
  294.         case CREATURE_EVENT_MAIL_SEND:
  295.             return "cid, receiver, item, openBox";
  296.         case CREATURE_EVENT_MAIL_RECEIVE:
  297.             return "cid, sender, item, openBox";
  298.         case CREATURE_EVENT_TRADE_REQUEST:
  299.         case CREATURE_EVENT_TRADE_ACCEPT:
  300.             return "cid, target, item";
  301.         case CREATURE_EVENT_TEXTEDIT:
  302.             return "cid, item, newText";
  303.         case CREATURE_EVENT_REPORTBUG:
  304.             return "cid, comment";
  305.         case CREATURE_EVENT_THINK:
  306.             return "cid, interval";
  307.         case CREATURE_EVENT_DIRECTION:
  308.         case CREATURE_EVENT_OUTFIT:
  309.             return "cid, old, current";
  310.         case CREATURE_EVENT_STATSCHANGE:
  311.             return "cid, attacker, type, combat, value";
  312.         case CREATURE_EVENT_COMBAT_AREA:
  313.             return "cid, ground, position, aggressive";
  314.         case CREATURE_EVENT_PUSH:
  315.         case CREATURE_EVENT_TARGET:
  316.         case CREATURE_EVENT_FOLLOW:
  317.         case CREATURE_EVENT_COMBAT:
  318.         case CREATURE_EVENT_ATTACK:
  319.         case CREATURE_EVENT_CAST:
  320.             return "cid, target";
  321.         case CREATURE_EVENT_KILL:
  322. #ifndef __WAR_SYSTEM__
  323.             return "cid, target, damage, flags";
  324. #else
  325.             return "cid, target, damage, flags, war";
  326. #endif
  327.         case CREATURE_EVENT_DEATH:
  328.             return "cid, corpse, deathList";
  329.         case CREATURE_EVENT_PREPAREDEATH:
  330.             return "cid, deathList";
  331.         case CREATURE_EVENT_NONE:
  332.         default:
  333.             break;
  334.     }
  335.  
  336.     return "";
  337. }
  338.  
  339. void CreatureEvent::copyEvent(CreatureEvent* creatureEvent)
  340. {
  341.     m_scriptId = creatureEvent->m_scriptId;
  342.     m_interface = creatureEvent->m_interface;
  343.     m_scripted = creatureEvent->m_scripted;
  344.     m_isLoaded = creatureEvent->m_isLoaded;
  345. }
  346.  
  347. void CreatureEvent::clearEvent()
  348. {
  349.     m_scriptId = 0;
  350.     m_interface = NULL;
  351.     m_scripted = EVENT_SCRIPT_FALSE;
  352.     m_isLoaded = false;
  353. }
  354.  
  355. uint32_t CreatureEvent::executeLogin(Player* player)
  356. {
  357.     //onLogin(cid)
  358.     if(m_interface->reserveEnv())
  359.     {
  360.         ScriptEnviroment* env = m_interface->getEnv();
  361.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  362.         {
  363.             env->setRealPos(player->getPosition());
  364.             std::stringstream scriptstream;
  365.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  366.  
  367.             scriptstream << m_scriptData;
  368.             bool result = true;
  369.             if(m_interface->loadBuffer(scriptstream.str()))
  370.             {
  371.                 lua_State* L = m_interface->getState();
  372.                 result = m_interface->getGlobalBool(L, "_result", true);
  373.             }
  374.  
  375.             m_interface->releaseEnv();
  376.             return result;
  377.         }
  378.         else
  379.         {
  380.             #ifdef __DEBUG_LUASCRIPTS__
  381.             char desc[35];
  382.             sprintf(desc, "%s", player->getName().c_str());
  383.             env->setEvent(desc);
  384.             #endif
  385.  
  386.             env->setScriptId(m_scriptId, m_interface);
  387.             env->setRealPos(player->getPosition());
  388.  
  389.             lua_State* L = m_interface->getState();
  390.             m_interface->pushFunction(m_scriptId);
  391.             lua_pushnumber(L, env->addThing(player));
  392.  
  393.             bool result = m_interface->callFunction(1);
  394.             m_interface->releaseEnv();
  395.             return result;
  396.         }
  397.     }
  398.     else
  399.     {
  400.         std::clog << "[Error - CreatureEvent::executeLogin] Call stack overflow." << std::endl;
  401.         return 0;
  402.     }
  403. }
  404.  
  405. uint32_t CreatureEvent::executeLogout(Player* player, bool forceLogout)
  406. {
  407.     //onLogout(cid, forceLogout)
  408.     if(m_interface->reserveEnv())
  409.     {
  410.         ScriptEnviroment* env = m_interface->getEnv();
  411.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  412.         {
  413.             env->setRealPos(player->getPosition());
  414.             std::stringstream scriptstream;
  415.  
  416.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  417.             scriptstream << "local forceLogout = " << (forceLogout ? "true" : "false") << std::endl;
  418.  
  419.             scriptstream << m_scriptData;
  420.             bool result = true;
  421.             if(m_interface->loadBuffer(scriptstream.str()))
  422.             {
  423.                 lua_State* L = m_interface->getState();
  424.                 result = m_interface->getGlobalBool(L, "_result", true);
  425.             }
  426.  
  427.             m_interface->releaseEnv();
  428.             return result;
  429.         }
  430.         else
  431.         {
  432.             #ifdef __DEBUG_LUASCRIPTS__
  433.             char desc[35];
  434.             sprintf(desc, "%s", player->getName().c_str());
  435.             env->setEvent(desc);
  436.             #endif
  437.  
  438.             env->setScriptId(m_scriptId, m_interface);
  439.             env->setRealPos(player->getPosition());
  440.  
  441.             lua_State* L = m_interface->getState();
  442.             m_interface->pushFunction(m_scriptId);
  443.  
  444.             lua_pushnumber(L, env->addThing(player));
  445.             lua_pushboolean(L, forceLogout);
  446.  
  447.             bool result = m_interface->callFunction(2);
  448.             m_interface->releaseEnv();
  449.             return result;
  450.         }
  451.     }
  452.     else
  453.     {
  454.         std::clog << "[Error - CreatureEvent::executeLogout] Call stack overflow." << std::endl;
  455.         return 0;
  456.     }
  457. }
  458.  
  459. uint32_t CreatureEvent::executeChannelJoin(Player* player, uint16_t channelId, UsersMap usersMap)
  460. {
  461.     //onJoinChannel(cid, channel, users)
  462.     if(m_interface->reserveEnv())
  463.     {
  464.         ScriptEnviroment* env = m_interface->getEnv();
  465.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  466.         {
  467.             env->setRealPos(player->getPosition());
  468.             std::stringstream scriptstream;
  469.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  470.  
  471.             scriptstream << "local channel = " << channelId << std::endl;
  472.             scriptstream << "local users = {}" << std::endl;
  473.             for(UsersMap::iterator it = usersMap.begin(); it != usersMap.end(); ++it)
  474.                 scriptstream << "users:insert(" << env->addThing(it->second) << ")" << std::endl;
  475.  
  476.             scriptstream << m_scriptData;
  477.             bool result = true;
  478.             if(m_interface->loadBuffer(scriptstream.str()))
  479.             {
  480.                 lua_State* L = m_interface->getState();
  481.                 result = m_interface->getGlobalBool(L, "_result", true);
  482.             }
  483.  
  484.             m_interface->releaseEnv();
  485.             return result;
  486.         }
  487.         else
  488.         {
  489.             #ifdef __DEBUG_LUASCRIPTS__
  490.             char desc[35];
  491.             sprintf(desc, "%s", player->getName().c_str());
  492.             env->setEvent(desc);
  493.             #endif
  494.  
  495.             env->setScriptId(m_scriptId, m_interface);
  496.             env->setRealPos(player->getPosition());
  497.  
  498.             lua_State* L = m_interface->getState();
  499.             m_interface->pushFunction(m_scriptId);
  500.  
  501.             lua_pushnumber(L, env->addThing(player));
  502.             lua_pushnumber(L, channelId);
  503.  
  504.             UsersMap::iterator it = usersMap.begin();
  505.             lua_newtable(L);
  506.             for(int32_t i = 1; it != usersMap.end(); ++it, ++i)
  507.             {
  508.                 lua_pushnumber(L, i);
  509.                 lua_pushnumber(L, env->addThing(it->second));
  510.                 lua_settable(L, -3);
  511.             }
  512.  
  513.             bool result = m_interface->callFunction(3);
  514.             m_interface->releaseEnv();
  515.             return result;
  516.         }
  517.     }
  518.     else
  519.     {
  520.         std::clog << "[Error - CreatureEvent::executeChannelJoin] Call stack overflow." << std::endl;
  521.         return 0;
  522.     }
  523. }
  524.  
  525. uint32_t CreatureEvent::executeChannelLeave(Player* player, uint16_t channelId, UsersMap usersMap)
  526. {
  527.     //onLeaveChannel(cid, channel, users)
  528.     if(m_interface->reserveEnv())
  529.     {
  530.         ScriptEnviroment* env = m_interface->getEnv();
  531.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  532.         {
  533.             env->setRealPos(player->getPosition());
  534.             std::stringstream scriptstream;
  535.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  536.  
  537.             scriptstream << "local channel = " << channelId << std::endl;
  538.             scriptstream << "local users = {}" << std::endl;
  539.             for(UsersMap::iterator it = usersMap.begin(); it != usersMap.end(); ++it)
  540.                 scriptstream << "users:insert(" << env->addThing(it->second) << ")" << std::endl;
  541.  
  542.             scriptstream << m_scriptData;
  543.             bool result = true;
  544.             if(m_interface->loadBuffer(scriptstream.str()))
  545.             {
  546.                 lua_State* L = m_interface->getState();
  547.                 result = m_interface->getGlobalBool(L, "_result", true);
  548.             }
  549.  
  550.             m_interface->releaseEnv();
  551.             return result;
  552.         }
  553.         else
  554.         {
  555.             #ifdef __DEBUG_LUASCRIPTS__
  556.             char desc[35];
  557.             sprintf(desc, "%s", player->getName().c_str());
  558.             env->setEvent(desc);
  559.             #endif
  560.  
  561.             env->setScriptId(m_scriptId, m_interface);
  562.             env->setRealPos(player->getPosition());
  563.  
  564.             lua_State* L = m_interface->getState();
  565.             m_interface->pushFunction(m_scriptId);
  566.  
  567.             lua_pushnumber(L, env->addThing(player));
  568.             lua_pushnumber(L, channelId);
  569.  
  570.             UsersMap::iterator it = usersMap.begin();
  571.             lua_newtable(L);
  572.             for(int32_t i = 1; it != usersMap.end(); ++it, ++i)
  573.             {
  574.                 lua_pushnumber(L, i);
  575.                 lua_pushnumber(L, env->addThing(it->second));
  576.                 lua_settable(L, -3);
  577.             }
  578.  
  579.             bool result = m_interface->callFunction(3);
  580.             m_interface->releaseEnv();
  581.             return result;
  582.         }
  583.     }
  584.     else
  585.     {
  586.         std::clog << "[Error - CreatureEvent::executeChannelLeave] Call stack overflow." << std::endl;
  587.         return 0;
  588.     }
  589. }
  590.  
  591. uint32_t CreatureEvent::executeAdvance(Player* player, skills_t skill, uint32_t oldLevel, uint32_t newLevel)
  592. {
  593.     //onAdvance(cid, skill, oldLevel, newLevel)
  594.     if(m_interface->reserveEnv())
  595.     {
  596.         ScriptEnviroment* env = m_interface->getEnv();
  597.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  598.         {
  599.             env->setRealPos(player->getPosition());
  600.             std::stringstream scriptstream;
  601.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  602.  
  603.             scriptstream << "local skill = " << skill << std::endl;
  604.             scriptstream << "local oldLevel = " << oldLevel << std::endl;
  605.             scriptstream << "local newLevel = " << newLevel << std::endl;
  606.  
  607.             scriptstream << m_scriptData;
  608.             bool result = true;
  609.             if(m_interface->loadBuffer(scriptstream.str()))
  610.             {
  611.                 lua_State* L = m_interface->getState();
  612.                 result = m_interface->getGlobalBool(L, "_result", true);
  613.             }
  614.  
  615.             m_interface->releaseEnv();
  616.             return result;
  617.         }
  618.         else
  619.         {
  620.             #ifdef __DEBUG_LUASCRIPTS__
  621.             char desc[35];
  622.             sprintf(desc, "%s", player->getName().c_str());
  623.             env->setEvent(desc);
  624.             #endif
  625.  
  626.             env->setScriptId(m_scriptId, m_interface);
  627.             env->setRealPos(player->getPosition());
  628.  
  629.             lua_State* L = m_interface->getState();
  630.             m_interface->pushFunction(m_scriptId);
  631.  
  632.             lua_pushnumber(L, env->addThing(player));
  633.             lua_pushnumber(L, (uint32_t)skill);
  634.  
  635.             lua_pushnumber(L, oldLevel);
  636.             lua_pushnumber(L, newLevel);
  637.  
  638.             bool result = m_interface->callFunction(4);
  639.             m_interface->releaseEnv();
  640.             return result;
  641.         }
  642.     }
  643.     else
  644.     {
  645.         std::clog << "[Error - CreatureEvent::executeAdvance] Call stack overflow." << std::endl;
  646.         return 0;
  647.     }
  648. }
  649.  
  650. uint32_t CreatureEvent::executeMailSend(Player* player, Player* receiver, Item* item, bool openBox)
  651. {
  652.     //onSendMail(cid, receiver, item, openBox)
  653.     if(m_interface->reserveEnv())
  654.     {
  655.         ScriptEnviroment* env = m_interface->getEnv();
  656.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  657.         {
  658.             env->setRealPos(player->getPosition());
  659.             std::stringstream scriptstream;
  660.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  661.  
  662.             scriptstream << "local receiver = " << env->addThing(receiver) << std::endl;
  663.             env->streamThing(scriptstream, "item", item, env->addThing(item));
  664.             scriptstream << "local openBox = " << (openBox ? "true" : "false") << std::endl;
  665.  
  666.             scriptstream << m_scriptData;
  667.             bool result = true;
  668.             if(m_interface->loadBuffer(scriptstream.str()))
  669.             {
  670.                 lua_State* L = m_interface->getState();
  671.                 result = m_interface->getGlobalBool(L, "_result", true);
  672.             }
  673.  
  674.             m_interface->releaseEnv();
  675.             return result;
  676.         }
  677.         else
  678.         {
  679.             #ifdef __DEBUG_LUASCRIPTS__
  680.             char desc[30];
  681.             sprintf(desc, "%s", player->getName().c_str());
  682.             env->setEvent(desc);
  683.             #endif
  684.  
  685.             env->setScriptId(m_scriptId, m_interface);
  686.             env->setRealPos(player->getPosition());
  687.  
  688.             lua_State* L = m_interface->getState();
  689.             m_interface->pushFunction(m_scriptId);
  690.  
  691.             lua_pushnumber(L, env->addThing(player));
  692.             lua_pushnumber(L, env->addThing(receiver));
  693.  
  694.             LuaInterface::pushThing(L, item, env->addThing(item));
  695.             lua_pushboolean(L, openBox);
  696.  
  697.             bool result = m_interface->callFunction(4);
  698.             m_interface->releaseEnv();
  699.             return result;
  700.         }
  701.     }
  702.     else
  703.     {
  704.         std::clog << "[Error - CreatureEvent::executeMailSend] Call stack overflow." << std::endl;
  705.         return 0;
  706.     }
  707. }
  708.  
  709. uint32_t CreatureEvent::executeMailReceive(Player* player, Player* sender, Item* item, bool openBox)
  710. {
  711.     //onReceiveMail(cid, sender, item, openBox)
  712.     if(m_interface->reserveEnv())
  713.     {
  714.         ScriptEnviroment* env = m_interface->getEnv();
  715.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  716.         {
  717.             env->setRealPos(player->getPosition());
  718.             std::stringstream scriptstream;
  719.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  720.  
  721.             scriptstream << "local sender = " << env->addThing(sender) << std::endl;
  722.             env->streamThing(scriptstream, "item", item, env->addThing(item));
  723.             scriptstream << "local openBox = " << (openBox ? "true" : "false") << std::endl;
  724.  
  725.             scriptstream << m_scriptData;
  726.             bool result = true;
  727.             if(m_interface->loadBuffer(scriptstream.str()))
  728.             {
  729.                 lua_State* L = m_interface->getState();
  730.                 result = m_interface->getGlobalBool(L, "_result", true);
  731.             }
  732.  
  733.             m_interface->releaseEnv();
  734.             return result;
  735.         }
  736.         else
  737.         {
  738.             #ifdef __DEBUG_LUASCRIPTS__
  739.             char desc[30];
  740.             sprintf(desc, "%s", player->getName().c_str());
  741.             env->setEvent(desc);
  742.             #endif
  743.  
  744.             env->setScriptId(m_scriptId, m_interface);
  745.             env->setRealPos(player->getPosition());
  746.  
  747.             lua_State* L = m_interface->getState();
  748.             m_interface->pushFunction(m_scriptId);
  749.  
  750.             lua_pushnumber(L, env->addThing(player));
  751.             lua_pushnumber(L, env->addThing(sender));
  752.  
  753.             LuaInterface::pushThing(L, item, env->addThing(item));
  754.             lua_pushboolean(L, openBox);
  755.  
  756.             bool result = m_interface->callFunction(4);
  757.             m_interface->releaseEnv();
  758.             return result;
  759.         }
  760.     }
  761.     else
  762.     {
  763.         std::clog << "[Error - CreatureEvent::executeMailReceive] Call stack overflow." << std::endl;
  764.         return 0;
  765.     }
  766. }
  767.  
  768. uint32_t CreatureEvent::executeTradeRequest(Player* player, Player* target, Item* item)
  769. {
  770.     //onTradeRequest(cid, target, item)
  771.     if(m_interface->reserveEnv())
  772.     {
  773.         ScriptEnviroment* env = m_interface->getEnv();
  774.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  775.         {
  776.             env->setRealPos(player->getPosition());
  777.             std::stringstream scriptstream;
  778.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  779.  
  780.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  781.             env->streamThing(scriptstream, "item", item, env->addThing(item));
  782.  
  783.             scriptstream << m_scriptData;
  784.             bool result = true;
  785.             if(m_interface->loadBuffer(scriptstream.str()))
  786.             {
  787.                 lua_State* L = m_interface->getState();
  788.                 result = m_interface->getGlobalBool(L, "_result", true);
  789.             }
  790.  
  791.             m_interface->releaseEnv();
  792.             return result;
  793.         }
  794.         else
  795.         {
  796.             #ifdef __DEBUG_LUASCRIPTS__
  797.             char desc[35];
  798.             sprintf(desc, "%s", player->getName().c_str());
  799.             env->setEvent(desc);
  800.             #endif
  801.  
  802.             env->setScriptId(m_scriptId, m_interface);
  803.             env->setRealPos(player->getPosition());
  804.  
  805.             lua_State* L = m_interface->getState();
  806.             m_interface->pushFunction(m_scriptId);
  807.  
  808.             lua_pushnumber(L, env->addThing(player));
  809.             lua_pushnumber(L, env->addThing(target));
  810.             LuaInterface::pushThing(L, item, env->addThing(item));
  811.  
  812.             bool result = m_interface->callFunction(3);
  813.             m_interface->releaseEnv();
  814.             return result;
  815.         }
  816.     }
  817.     else
  818.     {
  819.         std::clog << "[Error - CreatureEvent::executeTradeRequest] Call stack overflow." << std::endl;
  820.         return 0;
  821.     }
  822. }
  823.  
  824. uint32_t CreatureEvent::executeTradeAccept(Player* player, Player* target, Item* item, Item* targetItem)
  825. {
  826.     //onTradeAccept(cid, target, item, targetItem)
  827.     if(m_interface->reserveEnv())
  828.     {
  829.         ScriptEnviroment* env = m_interface->getEnv();
  830.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  831.         {
  832.             env->setRealPos(player->getPosition());
  833.             std::stringstream scriptstream;
  834.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  835.  
  836.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  837.             env->streamThing(scriptstream, "item", item, env->addThing(item));
  838.  
  839.             scriptstream << m_scriptData;
  840.             bool result = true;
  841.             if(m_interface->loadBuffer(scriptstream.str()))
  842.             {
  843.                 lua_State* L = m_interface->getState();
  844.                 result = m_interface->getGlobalBool(L, "_result", true);
  845.             }
  846.  
  847.             m_interface->releaseEnv();
  848.             return result;
  849.         }
  850.         else
  851.         {
  852.             #ifdef __DEBUG_LUASCRIPTS__
  853.             char desc[35];
  854.             sprintf(desc, "%s", player->getName().c_str());
  855.             env->setEvent(desc);
  856.             #endif
  857.  
  858.             env->setScriptId(m_scriptId, m_interface);
  859.             env->setRealPos(player->getPosition());
  860.  
  861.             lua_State* L = m_interface->getState();
  862.             m_interface->pushFunction(m_scriptId);
  863.  
  864.             lua_pushnumber(L, env->addThing(player));
  865.             lua_pushnumber(L, env->addThing(target));
  866.             LuaInterface::pushThing(L, item, env->addThing(item));
  867.             LuaInterface::pushThing(L, targetItem, env->addThing(targetItem));
  868.  
  869.             bool result = m_interface->callFunction(4);
  870.             m_interface->releaseEnv();
  871.             return result;
  872.         }
  873.     }
  874.     else
  875.     {
  876.         std::clog << "[Error - CreatureEvent::executeTradeAccept] Call stack overflow." << std::endl;
  877.         return 0;
  878.     }
  879. }
  880.  
  881. uint32_t CreatureEvent::executeLook(Player* player, Thing* thing, const Position& position, int16_t stackpos, int32_t lookDistance)
  882. {
  883.     //onLook(cid, thing, position, lookDistance)
  884.     if(m_interface->reserveEnv())
  885.     {
  886.         ScriptEnviroment* env = m_interface->getEnv();
  887.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  888.         {
  889.             env->setRealPos(player->getPosition());
  890.             std::stringstream scriptstream;
  891.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  892.  
  893.             scriptstream << "local thing = " << env->addThing(thing) << std::endl;
  894.             env->streamPosition(scriptstream, "position", position, stackpos);
  895.             scriptstream << "local lookDistance = " << lookDistance << std::endl;
  896.  
  897.             scriptstream << m_scriptData;
  898.             bool result = true;
  899.             if(m_interface->loadBuffer(scriptstream.str()))
  900.             {
  901.                 lua_State* L = m_interface->getState();
  902.                 result = m_interface->getGlobalBool(L, "_result", true);
  903.             }
  904.  
  905.             m_interface->releaseEnv();
  906.             return result;
  907.         }
  908.         else
  909.         {
  910.             #ifdef __DEBUG_LUASCRIPTS__
  911.             char desc[30];
  912.             sprintf(desc, "%s", player->getName().c_str());
  913.             env->setEvent(desc);
  914.             #endif
  915.  
  916.             env->setScriptId(m_scriptId, m_interface);
  917.             env->setRealPos(player->getPosition());
  918.  
  919.             lua_State* L = m_interface->getState();
  920.             m_interface->pushFunction(m_scriptId);
  921.  
  922.             lua_pushnumber(L, env->addThing(player));
  923.             LuaInterface::pushThing(L, thing, env->addThing(thing));
  924.  
  925.             LuaInterface::pushPosition(L, position, stackpos);
  926.             lua_pushnumber(L, lookDistance);
  927.  
  928.             bool result = m_interface->callFunction(4);
  929.             m_interface->releaseEnv();
  930.             return result;
  931.         }
  932.     }
  933.     else
  934.     {
  935.         std::clog << "[Error - CreatureEvent::executeLook] Call stack overflow." << std::endl;
  936.         return 0;
  937.     }
  938. }
  939.  
  940. uint32_t CreatureEvent::executeDirection(Creature* creature, Direction old, Direction current)
  941. {
  942.     //onDirection(cid, old, current)
  943.     if(m_interface->reserveEnv())
  944.     {
  945.         ScriptEnviroment* env = m_interface->getEnv();
  946.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  947.         {
  948.             env->setRealPos(creature->getPosition());
  949.             std::stringstream scriptstream;
  950.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  951.  
  952.             scriptstream << "local old = " << old << std::endl;
  953.             scriptstream << "local current = " << current << std::endl;
  954.  
  955.             scriptstream << m_scriptData;
  956.             bool result = true;
  957.             if(m_interface->loadBuffer(scriptstream.str()))
  958.             {
  959.                 lua_State* L = m_interface->getState();
  960.                 result = m_interface->getGlobalBool(L, "_result", true);
  961.             }
  962.  
  963.             m_interface->releaseEnv();
  964.             return result;
  965.         }
  966.         else
  967.         {
  968.             #ifdef __DEBUG_LUASCRIPTS__
  969.             char desc[30];
  970.             sprintf(desc, "%s", creature->getName().c_str());
  971.             env->setEvent(desc);
  972.             #endif
  973.  
  974.             env->setScriptId(m_scriptId, m_interface);
  975.             env->setRealPos(creature->getPosition());
  976.  
  977.             lua_State* L = m_interface->getState();
  978.             m_interface->pushFunction(m_scriptId);
  979.  
  980.             lua_pushnumber(L, env->addThing(creature));
  981.             lua_pushnumber(L, old);
  982.             lua_pushnumber(L, current);
  983.  
  984.             bool result = m_interface->callFunction(3);
  985.             m_interface->releaseEnv();
  986.             return result;
  987.         }
  988.     }
  989.     else
  990.     {
  991.         std::clog << "[Error - CreatureEvent::executeDirection] Call stack overflow." << std::endl;
  992.         return 0;
  993.     }
  994. }
  995.  
  996. uint32_t CreatureEvent::executeOutfit(Creature* creature, const Outfit_t& old, const Outfit_t& current)
  997. {
  998.     //onOutfit(cid, old, current)
  999.     if(m_interface->reserveEnv())
  1000.     {
  1001.         ScriptEnviroment* env = m_interface->getEnv();
  1002.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1003.         {
  1004.             env->setRealPos(creature->getPosition());
  1005.             std::stringstream scriptstream;
  1006.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1007.  
  1008.             env->streamOutfit(scriptstream, "old", old);
  1009.             env->streamOutfit(scriptstream, "current", current);
  1010.  
  1011.             scriptstream << m_scriptData;
  1012.             bool result = true;
  1013.             if(m_interface->loadBuffer(scriptstream.str()))
  1014.             {
  1015.                 lua_State* L = m_interface->getState();
  1016.                 result = m_interface->getGlobalBool(L, "_result", true);
  1017.             }
  1018.  
  1019.             m_interface->releaseEnv();
  1020.             return result;
  1021.         }
  1022.         else
  1023.         {
  1024.             #ifdef __DEBUG_LUASCRIPTS__
  1025.             char desc[30];
  1026.             sprintf(desc, "%s", creature->getName().c_str());
  1027.             env->setEvent(desc);
  1028.             #endif
  1029.  
  1030.             env->setScriptId(m_scriptId, m_interface);
  1031.             env->setRealPos(creature->getPosition());
  1032.  
  1033.             lua_State* L = m_interface->getState();
  1034.             m_interface->pushFunction(m_scriptId);
  1035.  
  1036.             lua_pushnumber(L, env->addThing(creature));
  1037.             LuaInterface::pushOutfit(L, old);
  1038.             LuaInterface::pushOutfit(L, current);
  1039.  
  1040.             bool result = m_interface->callFunction(3);
  1041.             m_interface->releaseEnv();
  1042.             return result;
  1043.         }
  1044.     }
  1045.     else
  1046.     {
  1047.         std::clog << "[Error - CreatureEvent::executeOutfit] Call stack overflow." << std::endl;
  1048.         return 0;
  1049.     }
  1050. }
  1051.  
  1052. uint32_t CreatureEvent::executeThink(Creature* creature, uint32_t interval)
  1053. {
  1054.     //onThink(cid, interval)
  1055.     if(m_interface->reserveEnv())
  1056.     {
  1057.         ScriptEnviroment* env = m_interface->getEnv();
  1058.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1059.         {
  1060.             env->setRealPos(creature->getPosition());
  1061.             std::stringstream scriptstream;
  1062.  
  1063.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1064.             scriptstream << "local interval = " << interval << std::endl;
  1065.  
  1066.             scriptstream << m_scriptData;
  1067.             bool result = true;
  1068.             if(m_interface->loadBuffer(scriptstream.str()))
  1069.             {
  1070.                 lua_State* L = m_interface->getState();
  1071.                 result = m_interface->getGlobalBool(L, "_result", true);
  1072.             }
  1073.  
  1074.             m_interface->releaseEnv();
  1075.             return result;
  1076.         }
  1077.         else
  1078.         {
  1079.             #ifdef __DEBUG_LUASCRIPTS__
  1080.             char desc[35];
  1081.             sprintf(desc, "%s", creature->getName().c_str());
  1082.             env->setEvent(desc);
  1083.             #endif
  1084.  
  1085.             env->setScriptId(m_scriptId, m_interface);
  1086.             env->setRealPos(creature->getPosition());
  1087.  
  1088.             lua_State* L = m_interface->getState();
  1089.             m_interface->pushFunction(m_scriptId);
  1090.  
  1091.             lua_pushnumber(L, env->addThing(creature));
  1092.             lua_pushnumber(L, interval);
  1093.  
  1094.             bool result = m_interface->callFunction(2);
  1095.             m_interface->releaseEnv();
  1096.             return result;
  1097.         }
  1098.     }
  1099.     else
  1100.     {
  1101.         std::clog << "[Error - CreatureEvent::executeThink] Call stack overflow." << std::endl;
  1102.         return 0;
  1103.     }
  1104. }
  1105.  
  1106. uint32_t CreatureEvent::executeStatsChange(Creature* creature, Creature* attacker, StatsChange_t type, CombatType_t combat, int32_t value)
  1107. {
  1108.     //onStatsChange(cid, attacker, type, combat, value)
  1109.     if(m_interface->reserveEnv())
  1110.     {
  1111.         ScriptEnviroment* env = m_interface->getEnv();
  1112.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1113.         {
  1114.             env->setRealPos(creature->getPosition());
  1115.             std::stringstream scriptstream;
  1116.  
  1117.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1118.             scriptstream << "local attacker = " << env->addThing(attacker) << std::endl;
  1119.  
  1120.             scriptstream << "local type = " << (uint32_t)type << std::endl;
  1121.             scriptstream << "local combat = " << (uint32_t)combat << std::endl;
  1122.             scriptstream << "local value = " << value << std::endl;
  1123.  
  1124.             scriptstream << m_scriptData;
  1125.             bool result = true;
  1126.             if(m_interface->loadBuffer(scriptstream.str()))
  1127.             {
  1128.                 lua_State* L = m_interface->getState();
  1129.                 result = m_interface->getGlobalBool(L, "_result", true);
  1130.             }
  1131.  
  1132.             m_interface->releaseEnv();
  1133.             return result;
  1134.         }
  1135.         else
  1136.         {
  1137.             #ifdef __DEBUG_LUASCRIPTS__
  1138.             char desc[35];
  1139.             sprintf(desc, "%s", creature->getName().c_str());
  1140.             env->setEvent(desc);
  1141.             #endif
  1142.  
  1143.             env->setScriptId(m_scriptId, m_interface);
  1144.             env->setRealPos(creature->getPosition());
  1145.  
  1146.             lua_State* L = m_interface->getState();
  1147.             m_interface->pushFunction(m_scriptId);
  1148.  
  1149.             lua_pushnumber(L, env->addThing(creature));
  1150.             lua_pushnumber(L, env->addThing(attacker));
  1151.  
  1152.             lua_pushnumber(L, (uint32_t)type);
  1153.             lua_pushnumber(L, (uint32_t)combat);
  1154.             lua_pushnumber(L, value);
  1155.  
  1156.             bool result = m_interface->callFunction(5);
  1157.             m_interface->releaseEnv();
  1158.             return result;
  1159.         }
  1160.     }
  1161.     else
  1162.     {
  1163.         std::clog << "[Error - CreatureEvent::executeStatsChange] Call stack overflow." << std::endl;
  1164.         return 0;
  1165.     }
  1166. }
  1167.  
  1168. uint32_t CreatureEvent::executeCombatArea(Creature* creature, Tile* tile, bool aggressive)
  1169. {
  1170.     //onAreaCombat(cid, ground, position, aggressive)
  1171.     if(m_interface->reserveEnv())
  1172.     {
  1173.         ScriptEnviroment* env = m_interface->getEnv();
  1174.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1175.         {
  1176.             env->setRealPos(creature->getPosition());
  1177.             std::stringstream scriptstream;
  1178.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1179.  
  1180.             env->streamThing(scriptstream, "ground", tile->ground, env->addThing(tile->ground));
  1181.             env->streamPosition(scriptstream, "position", tile->getPosition(), 0);
  1182.             scriptstream << "local aggressive = " << (aggressive ? "true" : "false") << std::endl;
  1183.  
  1184.             scriptstream << m_scriptData;
  1185.             bool result = true;
  1186.             if(m_interface->loadBuffer(scriptstream.str()))
  1187.             {
  1188.                 lua_State* L = m_interface->getState();
  1189.                 result = m_interface->getGlobalBool(L, "_result", true);
  1190.             }
  1191.  
  1192.             m_interface->releaseEnv();
  1193.             return result;
  1194.         }
  1195.         else
  1196.         {
  1197.             #ifdef __DEBUG_LUASCRIPTS__
  1198.             std::stringstream desc;
  1199.             desc << creature->getName();
  1200.             env->setEvent(desc.str());
  1201.             #endif
  1202.  
  1203.             env->setScriptId(m_scriptId, m_interface);
  1204.             env->setRealPos(creature->getPosition());
  1205.  
  1206.             lua_State* L = m_interface->getState();
  1207.             m_interface->pushFunction(m_scriptId);
  1208.  
  1209.             lua_pushnumber(L, env->addThing(creature));
  1210.             LuaInterface::pushThing(L, tile->ground, env->addThing(tile->ground));
  1211.  
  1212.             LuaInterface::pushPosition(L, tile->getPosition(), 0);
  1213.             lua_pushboolean(L, aggressive);
  1214.  
  1215.             bool result = m_interface->callFunction(4);
  1216.             m_interface->releaseEnv();
  1217.             return result;
  1218.         }
  1219.     }
  1220.     else
  1221.     {
  1222.         std::clog << "[Error - CreatureEvent::executeAreaCombat] Call stack overflow." << std::endl;
  1223.         return 0;
  1224.     }
  1225. }
  1226.  
  1227. uint32_t CreatureEvent::executeCombat(Creature* creature, Creature* target)
  1228. {
  1229.     //onCombat(cid, target)
  1230.     if(m_interface->reserveEnv())
  1231.     {
  1232.         ScriptEnviroment* env = m_interface->getEnv();
  1233.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1234.         {
  1235.             env->setRealPos(creature->getPosition());
  1236.             std::stringstream scriptstream;
  1237.  
  1238.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1239.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  1240.  
  1241.             scriptstream << m_scriptData;
  1242.             bool result = true;
  1243.             if(m_interface->loadBuffer(scriptstream.str()))
  1244.             {
  1245.                 lua_State* L = m_interface->getState();
  1246.                 result = m_interface->getGlobalBool(L, "_result", true);
  1247.             }
  1248.  
  1249.             m_interface->releaseEnv();
  1250.             return result;
  1251.         }
  1252.         else
  1253.         {
  1254.             #ifdef __DEBUG_LUASCRIPTS__
  1255.             std::stringstream desc;
  1256.             desc << creature->getName();
  1257.             env->setEvent(desc.str());
  1258.             #endif
  1259.  
  1260.             env->setScriptId(m_scriptId, m_interface);
  1261.             env->setRealPos(creature->getPosition());
  1262.  
  1263.             lua_State* L = m_interface->getState();
  1264.             m_interface->pushFunction(m_scriptId);
  1265.  
  1266.             lua_pushnumber(L, env->addThing(creature));
  1267.             lua_pushnumber(L, env->addThing(target));
  1268.  
  1269.             bool result = m_interface->callFunction(2);
  1270.             m_interface->releaseEnv();
  1271.             return result;
  1272.         }
  1273.     }
  1274.     else
  1275.     {
  1276.         std::clog << "[Error - CreatureEvent::executeCombat] Call stack overflow." << std::endl;
  1277.         return 0;
  1278.     }
  1279. }
  1280.  
  1281. uint32_t CreatureEvent::executeAttack(Creature* creature, Creature* target)
  1282. {
  1283.     //onAttack(cid, target)
  1284.     if(m_interface->reserveEnv())
  1285.     {
  1286.         ScriptEnviroment* env = m_interface->getEnv();
  1287.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1288.         {
  1289.             env->setRealPos(creature->getPosition());
  1290.             std::stringstream scriptstream;
  1291.  
  1292.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1293.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  1294.  
  1295.             scriptstream << m_scriptData;
  1296.             bool result = true;
  1297.             if(m_interface->loadBuffer(scriptstream.str()))
  1298.             {
  1299.                 lua_State* L = m_interface->getState();
  1300.                 result = m_interface->getGlobalBool(L, "_result", true);
  1301.             }
  1302.  
  1303.             m_interface->releaseEnv();
  1304.             return result;
  1305.         }
  1306.         else
  1307.         {
  1308.             #ifdef __DEBUG_LUASCRIPTS__
  1309.             std::stringstream desc;
  1310.             desc << creature->getName();
  1311.             env->setEvent(desc.str());
  1312.             #endif
  1313.  
  1314.             env->setScriptId(m_scriptId, m_interface);
  1315.             env->setRealPos(creature->getPosition());
  1316.  
  1317.             lua_State* L = m_interface->getState();
  1318.             m_interface->pushFunction(m_scriptId);
  1319.  
  1320.             lua_pushnumber(L, env->addThing(creature));
  1321.             lua_pushnumber(L, env->addThing(target));
  1322.  
  1323.             bool result = m_interface->callFunction(2);
  1324.             m_interface->releaseEnv();
  1325.             return result;
  1326.         }
  1327.     }
  1328.     else
  1329.     {
  1330.         std::clog << "[Error - CreatureEvent::executeAttack] Call stack overflow." << std::endl;
  1331.         return 0;
  1332.     }
  1333. }
  1334.  
  1335. uint32_t CreatureEvent::executeCast(Creature* creature, Creature* target/* = NULL*/)
  1336. {
  1337.     //onCast(cid[, target])
  1338.     if(m_interface->reserveEnv())
  1339.     {
  1340.         ScriptEnviroment* env = m_interface->getEnv();
  1341.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1342.         {
  1343.             env->setRealPos(creature->getPosition());
  1344.             std::stringstream scriptstream;
  1345.  
  1346.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1347.             scriptstream << "local target = ";
  1348.             if(target)
  1349.                 scriptstream << env->addThing(target);
  1350.             else
  1351.                 scriptstream << "nil";
  1352.  
  1353.             scriptstream << std::endl << m_scriptData;
  1354.             bool result = true;
  1355.             if(m_interface->loadBuffer(scriptstream.str()))
  1356.             {
  1357.                 lua_State* L = m_interface->getState();
  1358.                 result = m_interface->getGlobalBool(L, "_result", true);
  1359.             }
  1360.  
  1361.             m_interface->releaseEnv();
  1362.             return result;
  1363.         }
  1364.         else
  1365.         {
  1366.             #ifdef __DEBUG_LUASCRIPTS__
  1367.             std::stringstream desc;
  1368.             desc << creature->getName();
  1369.             env->setEvent(desc.str());
  1370.             #endif
  1371.  
  1372.             env->setScriptId(m_scriptId, m_interface);
  1373.             env->setRealPos(creature->getPosition());
  1374.  
  1375.             lua_State* L = m_interface->getState();
  1376.             m_interface->pushFunction(m_scriptId);
  1377.  
  1378.             lua_pushnumber(L, env->addThing(creature));
  1379.             lua_pushnumber(L, env->addThing(target));
  1380.  
  1381.             bool result = m_interface->callFunction(2);
  1382.             m_interface->releaseEnv();
  1383.             return result;
  1384.         }
  1385.     }
  1386.     else
  1387.     {
  1388.         std::clog << "[Error - CreatureEvent::executeCast] Call stack overflow." << std::endl;
  1389.         return 0;
  1390.     }
  1391. }
  1392.  
  1393. uint32_t CreatureEvent::executeKill(Creature* creature, Creature* target, const DeathEntry& entry)
  1394. {
  1395.     //onKill(cid, target, damage, flags)
  1396.     if(m_interface->reserveEnv())
  1397.     {
  1398.         uint32_t flags = 0;
  1399.         if(entry.isLast())
  1400.             flags |= 1;
  1401.  
  1402.         if(entry.isJustify())
  1403.             flags |= 2;
  1404.  
  1405.         if(entry.isUnjustified())
  1406.             flags |= 4;
  1407.  
  1408.         ScriptEnviroment* env = m_interface->getEnv();
  1409.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1410.         {
  1411.             env->setRealPos(creature->getPosition());
  1412.             std::stringstream scriptstream;
  1413.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1414.  
  1415.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  1416.             scriptstream << "local damage = " << entry.getDamage() << std::endl;
  1417.             scriptstream << "local flags = " << flags << std::endl;
  1418. #ifdef __WAR_SYSTEM__
  1419.             scriptstream << "local war = " << entry.getWar().war << std::endl;
  1420. #endif
  1421.  
  1422.             scriptstream << m_scriptData;
  1423.             bool result = true;
  1424.             if(m_interface->loadBuffer(scriptstream.str()))
  1425.             {
  1426.                 lua_State* L = m_interface->getState();
  1427.                 result = m_interface->getGlobalBool(L, "_result", true);
  1428.             }
  1429.  
  1430.             m_interface->releaseEnv();
  1431.             return result;
  1432.         }
  1433.         else
  1434.         {
  1435.             #ifdef __DEBUG_LUASCRIPTS__
  1436.             std::stringstream desc;
  1437.             desc << creature->getName();
  1438.             env->setEvent(desc.str());
  1439.             #endif
  1440.  
  1441.             env->setScriptId(m_scriptId, m_interface);
  1442.             env->setRealPos(creature->getPosition());
  1443.  
  1444.             lua_State* L = m_interface->getState();
  1445.             m_interface->pushFunction(m_scriptId);
  1446.  
  1447.             lua_pushnumber(L, env->addThing(creature));
  1448.             lua_pushnumber(L, env->addThing(target));
  1449.  
  1450.             lua_pushnumber(L, entry.getDamage());
  1451.             lua_pushnumber(L, flags);
  1452. #ifndef __WAR_SYSTEM__
  1453.  
  1454.             bool result = m_interface->callFunction(4);
  1455. #else
  1456.             lua_pushnumber(L, entry.getWar().war);
  1457.  
  1458.             bool result = m_interface->callFunction(5);
  1459. #endif
  1460.             m_interface->releaseEnv();
  1461.             return result;
  1462.         }
  1463.     }
  1464.     else
  1465.     {
  1466.         std::clog << "[Error - CreatureEvent::executeKill] Call stack overflow." << std::endl;
  1467.         return 0;
  1468.     }
  1469. }
  1470.  
  1471. uint32_t CreatureEvent::executeDeath(Creature* creature, Item* corpse, DeathList deathList)
  1472. {
  1473.     //onDeath(cid, corpse, deathList)
  1474.     if(m_interface->reserveEnv())
  1475.     {
  1476.         ScriptEnviroment* env = m_interface->getEnv();
  1477.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1478.         {
  1479.             env->setRealPos(creature->getPosition());
  1480.             std::stringstream scriptstream;
  1481.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1482.  
  1483.             env->streamThing(scriptstream, "corpse", corpse, env->addThing(corpse));
  1484.             scriptstream << "local deathList = {}" << std::endl;
  1485.             for(DeathList::iterator it = deathList.begin(); it != deathList.end(); ++it)
  1486.             {
  1487.                 scriptstream << "deathList:insert(";
  1488.                 if(it->isCreatureKill())
  1489.                     scriptstream << env->addThing(it->getKillerCreature());
  1490.                 else
  1491.                     scriptstream << it->getKillerName();
  1492.  
  1493.                 scriptstream << ")" << std::endl;
  1494.             }
  1495.  
  1496.             scriptstream << m_scriptData;
  1497.             bool result = true;
  1498.             if(m_interface->loadBuffer(scriptstream.str()))
  1499.             {
  1500.                 lua_State* L = m_interface->getState();
  1501.                 result = m_interface->getGlobalBool(L, "_result", true);
  1502.             }
  1503.  
  1504.             m_interface->releaseEnv();
  1505.             return result;
  1506.         }
  1507.         else
  1508.         {
  1509.             #ifdef __DEBUG_LUASCRIPTS__
  1510.             char desc[35];
  1511.             sprintf(desc, "%s", creature->getName().c_str());
  1512.             env->setEvent(desc);
  1513.             #endif
  1514.  
  1515.             env->setScriptId(m_scriptId, m_interface);
  1516.             env->setRealPos(creature->getPosition());
  1517.  
  1518.             lua_State* L = m_interface->getState();
  1519.             m_interface->pushFunction(m_scriptId);
  1520.  
  1521.             lua_pushnumber(L, env->addThing(creature));
  1522.             LuaInterface::pushThing(L, corpse, env->addThing(corpse));
  1523.  
  1524.             lua_newtable(L);
  1525.             DeathList::iterator it = deathList.begin();
  1526.             for(int32_t i = 1; it != deathList.end(); ++it, ++i)
  1527.             {
  1528.                 lua_pushnumber(L, i);
  1529.                 if(it->isCreatureKill())
  1530.                     lua_pushnumber(L, env->addThing(it->getKillerCreature()));
  1531.                 else
  1532.                     lua_pushstring(L, it->getKillerName().c_str());
  1533.  
  1534.                 lua_settable(L, -3);
  1535.             }
  1536.  
  1537.             bool result = m_interface->callFunction(3);
  1538.             m_interface->releaseEnv();
  1539.             return result;
  1540.         }
  1541.     }
  1542.     else
  1543.     {
  1544.         std::clog << "[Error - CreatureEvent::executeDeath] Call stack overflow." << std::endl;
  1545.         return 0;
  1546.     }
  1547. }
  1548.  
  1549. uint32_t CreatureEvent::executePrepareDeath(Creature* creature, DeathList deathList)
  1550. {
  1551.     //onPrepareDeath(cid, deathList)
  1552.     if(m_interface->reserveEnv())
  1553.     {
  1554.         ScriptEnviroment* env = m_interface->getEnv();
  1555.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1556.         {
  1557.             env->setRealPos(creature->getPosition());
  1558.             std::stringstream scriptstream;
  1559.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1560.  
  1561.             scriptstream << "local deathList = {}" << std::endl;
  1562.             for(DeathList::iterator it = deathList.begin(); it != deathList.end(); ++it)
  1563.             {
  1564.                 scriptstream << "deathList:insert(";
  1565.                 if(it->isCreatureKill())
  1566.                     scriptstream << env->addThing(it->getKillerCreature());
  1567.                 else
  1568.                     scriptstream << it->getKillerName();
  1569.  
  1570.                 scriptstream << ")" << std::endl;
  1571.             }
  1572.  
  1573.             scriptstream << m_scriptData;
  1574.             bool result = true;
  1575.             if(m_interface->loadBuffer(scriptstream.str()))
  1576.             {
  1577.                 lua_State* L = m_interface->getState();
  1578.                 result = m_interface->getGlobalBool(L, "_result", true);
  1579.             }
  1580.  
  1581.             m_interface->releaseEnv();
  1582.             return result;
  1583.         }
  1584.         else
  1585.         {
  1586.             #ifdef __DEBUG_LUASCRIPTS__
  1587.             char desc[35];
  1588.             sprintf(desc, "%s", creature->getName().c_str());
  1589.             env->setEvent(desc);
  1590.             #endif
  1591.  
  1592.             env->setScriptId(m_scriptId, m_interface);
  1593.             env->setRealPos(creature->getPosition());
  1594.  
  1595.             lua_State* L = m_interface->getState();
  1596.             m_interface->pushFunction(m_scriptId);
  1597.  
  1598.             lua_pushnumber(L, env->addThing(creature));
  1599.  
  1600.             lua_newtable(L);
  1601.             DeathList::iterator it = deathList.begin();
  1602.             for(int32_t i = 1; it != deathList.end(); ++it, ++i)
  1603.             {
  1604.                 lua_pushnumber(L, i);
  1605.                 if(it->isCreatureKill())
  1606.                     lua_pushnumber(L, env->addThing(it->getKillerCreature()));
  1607.                 else
  1608.                     lua_pushstring(L, it->getKillerName().c_str());
  1609.  
  1610.                 lua_settable(L, -3);
  1611.             }
  1612.  
  1613.             bool result = m_interface->callFunction(2);
  1614.             m_interface->releaseEnv();
  1615.  
  1616.             return result;
  1617.         }
  1618.     }
  1619.     else
  1620.     {
  1621.         std::clog << "[Error - CreatureEvent::executePrepareDeath] Call stack overflow." << std::endl;
  1622.         return 0;
  1623.     }
  1624. }
  1625.  
  1626. uint32_t CreatureEvent::executeTextEdit(Player* player, Item* item, std::string newText)
  1627. {
  1628.     //onTextEdit(cid, item, newText)
  1629.     if(m_interface->reserveEnv())
  1630.     {
  1631.         ScriptEnviroment* env = m_interface->getEnv();
  1632.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1633.         {
  1634.             env->setRealPos(player->getPosition());
  1635.             std::stringstream scriptstream;
  1636.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  1637.  
  1638.             env->streamThing(scriptstream, "item", item, env->addThing(item));
  1639.             scriptstream << "local newText = " << newText.c_str() << std::endl;
  1640.  
  1641.             scriptstream << m_scriptData;
  1642.             bool result = true;
  1643.             if(m_interface->loadBuffer(scriptstream.str()))
  1644.             {
  1645.                 lua_State* L = m_interface->getState();
  1646.                 result = m_interface->getGlobalBool(L, "_result", true);
  1647.             }
  1648.  
  1649.             m_interface->releaseEnv();
  1650.             return result;
  1651.         }
  1652.         else
  1653.         {
  1654.             #ifdef __DEBUG_LUASCRIPTS__
  1655.             char desc[35];
  1656.             sprintf(desc, "%s", player->getName().c_str());
  1657.             env->setEvent(desc);
  1658.             #endif
  1659.  
  1660.             env->setScriptId(m_scriptId, m_interface);
  1661.             env->setRealPos(player->getPosition());
  1662.  
  1663.             lua_State* L = m_interface->getState();
  1664.             m_interface->pushFunction(m_scriptId);
  1665.  
  1666.             lua_pushnumber(L, env->addThing(player));
  1667.             LuaInterface::pushThing(L, item, env->addThing(item));
  1668.             lua_pushstring(L, newText.c_str());
  1669.  
  1670.             bool result = m_interface->callFunction(3);
  1671.             m_interface->releaseEnv();
  1672.             return result;
  1673.         }
  1674.     }
  1675.     else
  1676.     {
  1677.         std::clog << "[Error - CreatureEvent::executeTextEdit] Call stack overflow." << std::endl;
  1678.         return 0;
  1679.     }
  1680. }
  1681.  
  1682. uint32_t CreatureEvent::executeReportBug(Player* player, std::string comment)
  1683. {
  1684.     //onReportBug(cid, comment)
  1685.     if(m_interface->reserveEnv())
  1686.     {
  1687.         ScriptEnviroment* env = m_interface->getEnv();
  1688.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1689.         {
  1690.             env->setRealPos(player->getPosition());
  1691.             std::stringstream scriptstream;
  1692.  
  1693.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  1694.             scriptstream << "local comment = " << comment.c_str() << std::endl;
  1695.  
  1696.             scriptstream << m_scriptData;
  1697.             bool result = true;
  1698.             if(m_interface->loadBuffer(scriptstream.str()))
  1699.             {
  1700.                 lua_State* L = m_interface->getState();
  1701.                 result = m_interface->getGlobalBool(L, "_result", true);
  1702.             }
  1703.  
  1704.             m_interface->releaseEnv();
  1705.             return result;
  1706.         }
  1707.         else
  1708.         {
  1709.             #ifdef __DEBUG_LUASCRIPTS__
  1710.             char desc[35];
  1711.             sprintf(desc, "%s", player->getName().c_str());
  1712.             env->setEvent(desc);
  1713.             #endif
  1714.  
  1715.             env->setScriptId(m_scriptId, m_interface);
  1716.             env->setRealPos(player->getPosition());
  1717.  
  1718.             lua_State* L = m_interface->getState();
  1719.             m_interface->pushFunction(m_scriptId);
  1720.  
  1721.             lua_pushnumber(L, env->addThing(player));
  1722.             lua_pushstring(L, comment.c_str());
  1723.  
  1724.             bool result = m_interface->callFunction(2);
  1725.             m_interface->releaseEnv();
  1726.             return result;
  1727.         }
  1728.     }
  1729.     else
  1730.     {
  1731.         std::clog << "[Error - CreatureEvent::executeReportBug] Call stack overflow." << std::endl;
  1732.         return 0;
  1733.     }
  1734. }
  1735.  
  1736. uint32_t CreatureEvent::executePush(Player* player, Creature* target)
  1737. {
  1738.     //onPush(cid, target)
  1739.     if(m_interface->reserveEnv())
  1740.     {
  1741.         ScriptEnviroment* env = m_interface->getEnv();
  1742.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1743.         {
  1744.             env->setRealPos(player->getPosition());
  1745.             std::stringstream scriptstream;
  1746.  
  1747.             scriptstream << "local cid = " << env->addThing(player) << std::endl;
  1748.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  1749.  
  1750.             scriptstream << m_scriptData;
  1751.             bool result = true;
  1752.             if(m_interface->loadBuffer(scriptstream.str()))
  1753.             {
  1754.                 lua_State* L = m_interface->getState();
  1755.                 result = m_interface->getGlobalBool(L, "_result", true);
  1756.             }
  1757.  
  1758.             m_interface->releaseEnv();
  1759.             return result;
  1760.         }
  1761.         else
  1762.         {
  1763.             #ifdef __DEBUG_LUASCRIPTS__
  1764.             std::stringstream desc;
  1765.             desc << player->getName();
  1766.             env->setEvent(desc.str());
  1767.             #endif
  1768.  
  1769.             env->setScriptId(m_scriptId, m_interface);
  1770.             env->setRealPos(player->getPosition());
  1771.  
  1772.             lua_State* L = m_interface->getState();
  1773.             m_interface->pushFunction(m_scriptId);
  1774.  
  1775.             lua_pushnumber(L, env->addThing(player));
  1776.             lua_pushnumber(L, env->addThing(target));
  1777.  
  1778.             bool result = m_interface->callFunction(2);
  1779.             m_interface->releaseEnv();
  1780.             return result;
  1781.         }
  1782.     }
  1783.     else
  1784.     {
  1785.         std::clog << "[Error - CreatureEvent::executePush] Call stack overflow." << std::endl;
  1786.         return 0;
  1787.     }
  1788. }
  1789.  
  1790. uint32_t CreatureEvent::executeTarget(Creature* creature, Creature* target)
  1791. {
  1792.     //onTarget(cid, target)
  1793.     if(m_interface->reserveEnv())
  1794.     {
  1795.         ScriptEnviroment* env = m_interface->getEnv();
  1796.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1797.         {
  1798.             env->setRealPos(creature->getPosition());
  1799.             std::stringstream scriptstream;
  1800.  
  1801.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1802.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  1803.  
  1804.             scriptstream << m_scriptData;
  1805.             bool result = true;
  1806.             if(m_interface->loadBuffer(scriptstream.str()))
  1807.             {
  1808.                 lua_State* L = m_interface->getState();
  1809.                 result = m_interface->getGlobalBool(L, "_result", true);
  1810.             }
  1811.  
  1812.             m_interface->releaseEnv();
  1813.             return result;
  1814.         }
  1815.         else
  1816.         {
  1817.             #ifdef __DEBUG_LUASCRIPTS__
  1818.             std::stringstream desc;
  1819.             desc << creature->getName();
  1820.             env->setEvent(desc.str());
  1821.             #endif
  1822.  
  1823.             env->setScriptId(m_scriptId, m_interface);
  1824.             env->setRealPos(creature->getPosition());
  1825.  
  1826.             lua_State* L = m_interface->getState();
  1827.             m_interface->pushFunction(m_scriptId);
  1828.  
  1829.             lua_pushnumber(L, env->addThing(creature));
  1830.             lua_pushnumber(L, env->addThing(target));
  1831.  
  1832.             bool result = m_interface->callFunction(2);
  1833.             m_interface->releaseEnv();
  1834.             return result;
  1835.         }
  1836.     }
  1837.     else
  1838.     {
  1839.         std::clog << "[Error - CreatureEvent::executeTarget] Call stack overflow." << std::endl;
  1840.         return 0;
  1841.     }
  1842. }
  1843.  
  1844. uint32_t CreatureEvent::executeFollow(Creature* creature, Creature* target)
  1845. {
  1846.     //onFollow(cid, target)
  1847.     if(m_interface->reserveEnv())
  1848.     {
  1849.         ScriptEnviroment* env = m_interface->getEnv();
  1850.         if(m_scripted == EVENT_SCRIPT_BUFFER)
  1851.         {
  1852.             env->setRealPos(creature->getPosition());
  1853.             std::stringstream scriptstream;
  1854.  
  1855.             scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  1856.             scriptstream << "local target = " << env->addThing(target) << std::endl;
  1857.  
  1858.             scriptstream << m_scriptData;
  1859.             bool result = true;
  1860.             if(m_interface->loadBuffer(scriptstream.str()))
  1861.             {
  1862.                 lua_State* L = m_interface->getState();
  1863.                 result = m_interface->getGlobalBool(L, "_result", true);
  1864.             }
  1865.  
  1866.             m_interface->releaseEnv();
  1867.             return result;
  1868.         }
  1869.         else
  1870.         {
  1871.             #ifdef __DEBUG_LUASCRIPTS__
  1872.             std::stringstream desc;
  1873.             desc << creature->getName();
  1874.             env->setEvent(desc.str());
  1875.             #endif
  1876.  
  1877.             env->setScriptId(m_scriptId, m_interface);
  1878.             env->setRealPos(creature->getPosition());
  1879.  
  1880.             lua_State* L = m_interface->getState();
  1881.             m_interface->pushFunction(m_scriptId);
  1882.  
  1883.             lua_pushnumber(L, env->addThing(creature));
  1884.             lua_pushnumber(L, env->addThing(target));
  1885.  
  1886.             bool result = m_interface->callFunction(2);
  1887.             m_interface->releaseEnv();
  1888.             return result;
  1889.         }
  1890.     }
  1891.     else
  1892.     {
  1893.         std::clog << "[Error - CreatureEvent::executeFollow] Call stack overflow." << std::endl;
  1894.         return 0;
  1895.     }
  1896. }
  1897.  
Add Comment
Please, Sign In to add comment