Guest User

Untitled

a guest
Dec 27th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. uint32_t CreatureEvent::executeWalk(Creature* creature, const Position& fromPosition, const Position& toPosition)
  2. {
  3. //onWalk(cid, fromPosition, toPosition)
  4. if(m_interface->reserveEnv())
  5. {
  6. ScriptEnviroment* env = m_interface->getEnv();
  7. if(m_scripted == EVENT_SCRIPT_BUFFER)
  8. {
  9. env->setRealPos(creature->getPosition());
  10. std::stringstream scriptstream;
  11. scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  12. env->streamPosition(scriptstream, "fromPosition", fromPosition);
  13. env->streamPosition(scriptstream, "toPosition", toPosition);
  14.  
  15. scriptstream << m_scriptData;
  16. bool result = true;
  17. if(m_interface->loadBuffer(scriptstream.str()))
  18. {
  19. lua_State* L = m_interface->getState();
  20. result = m_interface->getGlobalBool(L, "_result", true);
  21. }
  22.  
  23. m_interface->releaseEnv();
  24. return result;
  25. }
  26. else
  27. {
  28. #ifdef __DEBUG_LUASCRIPTS__
  29. char desc[30];
  30. sprintf(desc, "%s", creature->getName().c_str());
  31. env->setEvent(desc);
  32. #endif
  33.  
  34. env->setScriptId(m_scriptId, m_interface);
  35. env->setRealPos(creature->getPosition());
  36.  
  37. lua_State* L = m_interface->getState();
  38. m_interface->pushFunction(m_scriptId);
  39.  
  40. lua_pushnumber(L, env->addThing(creature));
  41. LuaInterface::pushPosition(L, fromPosition);
  42. LuaInterface::pushPosition(L, toPosition);
  43.  
  44. bool result = m_interface->callFunction(3);
  45. m_interface->releaseEnv();
  46. return result;
  47. }
  48. }
  49. else
  50. {
  51. std::cout << "[Error - CreatureEvent::executeWalk] Call stack overflow." << std::endl;
  52. return 0;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment