Dominik ms
Member
- Joined
- Jan 20, 2010
- Messages
- 424
- Reaction score
- 6
First try to build this.
When you got error, just post here.
When you got error, just post here.
if(m_scriptData)
scriptstream << *m_scriptData;
bool result = true;
LuaInterface::pushPosition(L, fromPosition);
LuaInterface::pushPosition(L, toPosition);
uint32_t CreatureEvent::executeOnMove(Player* player, Item* item, const Position& fromPosition, const Position& toPosition,
Item* fromItem, Item* toItem, Item* fromGround, Item* toGround, std::map<std::string,int> status)
{
//onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, equip, hold, depot, slot)
if(m_interface->reserveEnv())
{
ScriptScriptEnviroment* env = m_interface->getEnv();
if(m_scripted == EVENT_SCRIPT_BUFFER)
{
env->setRealPos(player->getPosition());
std::stringstream scriptstream;
scriptstream << "local cid = " << env->addThing(player) << std::endl;
env->streamThing(scriptstream, "item" ,item, env->addThing(item));
env->streamPosition(scriptstream, "fromPosition", fromPosition);
env->streamPosition(scriptstream, "toPosition", toPosition);
env->streamThing(scriptstream, "fromItem",fromItem, env->addThing(fromItem));
env->streamThing(scriptstream, "toItem",toItem, env->addThing(toItem));
env->streamThing(scriptstream, "fromGround",fromGround, env->addThing(fromGround));
env->streamThing(scriptstream, "toGround",toGround, env->addThing(toGround));
scriptstream << "equip = " << (int32_t)status["equip"] << std::endl;
scriptstream << "hold = " << (int32_t)status["hold"] << std::endl;
scriptstream << "depot = " << (int32_t)status["depot"] << std::endl;
scriptstream << "slot = " << (int32_t)status["slot"] << 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[30];
sprintf(desc, "%s", player->getName().c_str());
env->setEvent(desc);
#endif
env->setScriptId(m_scriptId, m_interface);
env->setRealPos(player->getPosition());
lua_State* L = m_interface->getState();
m_interface->pushFunction(m_scriptId);
lua_pushnumber(L, env->addThing(player));
LuaInterface::pushThing(L, item, env->addThing(item));
LuaInterface::pushPosition(L, fromPosition);
LuaInterface::pushPosition(L, toPosition);
LuaInterface::pushThing(L, fromItem, env->addThing(fromItem));
LuaInterface::pushThing(L, toItem, env->addThing(toItem));
LuaInterface::pushThing(L, fromGround, env->addThing(fromGround));
LuaInterface::pushThing(L, toGround, env->addThing(toGround));
lua_pushnumber(L, status["equip"]);
lua_pushnumber(L, status["hold"]);
lua_pushnumber(L, status["depot"]);
lua_pushnumber(L, status["slot"]);
bool result = m_interface->callFunction(12);
m_interface->releaseEnv();
return result;
}
}
else
{
std::clog << "[Error - CreatureEvent::executeMove] Call stack overflow." << std::endl;
return 0;
}
}
uint32_t CreatureEvent::executeOnMove(Player* player, Item* item, const Position& fromPosition, const Position& toPosition,
Item* fromItem, Item* toItem, Item* fromGround, Item* toGround, std::map<std::string,int> status)
{
//onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, equip, hold, depot, slot)
if(m_interface->reserveEnv())
{
ScriptEnviroment* env = m_interface->getEnv();
if(m_scripted == EVENT_SCRIPT_BUFFER)
{
env->setRealPos(player->getPosition());
std::stringstream scriptstream;
scriptstream << "local cid = " << env->addThing(player) << std::endl;
env->streamThing(scriptstream, "item" ,item, env->addThing(item));
env->streamPosition(scriptstream, "fromPosition", fromPosition);
env->streamPosition(scriptstream, "toPosition", toPosition);
env->streamThing(scriptstream, "fromItem",fromItem, env->addThing(fromItem));
env->streamThing(scriptstream, "toItem",toItem, env->addThing(toItem));
env->streamThing(scriptstream, "fromGround",fromGround, env->addThing(fromGround));
env->streamThing(scriptstream, "toGround",toGround, env->addThing(toGround));
scriptstream << "equip = " << (int32_t)status["equip"] << std::endl;
scriptstream << "hold = " << (int32_t)status["hold"] << std::endl;
scriptstream << "depot = " << (int32_t)status["depot"] << std::endl;
scriptstream << "slot = " << (int32_t)status["slot"] << 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[30];
sprintf(desc, "%s", player->getName().c_str());
env->setEvent(desc);
#endif
env->setScriptId(m_scriptId, m_interface);
env->setRealPos(player->getPosition());
lua_State* L = m_interface->getState();
m_interface->pushFunction(m_scriptId);
lua_pushnumber(L, env->addThing(player));
LuaScriptInterface::pushThing(L, item, env->addThing(item));
LuaScriptInterface::pushPosition(L, fromPosition);
LuaScriptInterface::pushPosition(L, toPosition);
LuaScriptInterface::pushThing(L, fromItem, env->addThing(fromItem));
LuaScriptInterface::pushThing(L, toItem, env->addThing(toItem));
LuaScriptInterface::pushThing(L, fromGround, env->addThing(fromGround));
LuaScriptInterface::pushThing(L, toGround, env->addThing(toGround));
lua_pushnumber(L, status["equip"]);
lua_pushnumber(L, status["hold"]);
lua_pushnumber(L, status["depot"]);
lua_pushnumber(L, status["slot"]);
bool result = m_interface->callFunction(12);
m_interface->releaseEnv();
return result;
}
}
else
{
std::clog << "[Error - CreatureEvent::executeMove] Call stack overflow." << std::endl;
return 0;
}
}
function onMove(params, go hear)
maxuid = 5000 -- change with max uid of items (can't be infinite, uids are in use for players, creatures, items, npcs, etc)
if(item.uid > 0 and item.uid < maxuid) then
return true
end
return false
end
function onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, status)
if item.actionid == 20000 then
doPlayerSendCancel(cid, "You cannot move this object.")
return false
end
end