uint32_t CreatureEvent::executeCombat(Creature* creature, Creature* target)
{
//onCombat(cid, target)
if(m_scriptInterface->reserveScriptEnv())
{
ScriptEnviroment* env = m_scriptInterface->getScriptEnv();
if(m_scripted == 1)
{
env->setRealPos(creature->getPosition());
std::stringstream scriptstream;
scriptstream << "local cid = " << env->addThing(creature) << std::endl;
scriptstream << "local target = " << env->addThing(target) << std::endl;
scriptstream << m_scripted;
bool result = true;
if(m_scriptInterface->loadBuffer(scriptstream.str()[U])[/U]) --- [COLOR="#FF0000"]Error: too few arguments in function call[/COLOR][COLOR="#FF0000"][/COLOR]
{
lua_State* L = m_scriptInterface->getLuaState();
result = m_scriptInterface->callFunction(3);
}
m_scriptInterface->releaseScriptEnv();
return result;
}
else
{
#ifdef __DEBUG_LUASCRIPTS__
std::stringstream desc;
desc << creature->getName();
env->setEventDesc(desc.str());
#endif
env->setScriptId(m_scriptId, m_scriptInterface);
env->setRealPos(creature->getPosition());
lua_State* L = m_scriptInterface->getLuaState();
m_scriptInterface->pushFunction(m_scriptId);
lua_pushnumber(L, env->addThing(creature));
lua_pushnumber(L, env->addThing(target));
bool result = m_scriptInterface->callFunction(2);
m_scriptInterface->releaseScriptEnv();
return result;
}
}
else
{
std::cout << "[Error - CreatureEvent::executeCombat] Call stack overflow." << std::endl;
return 0;
}
}