• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

doSummonMonster

aberos

New Member
Joined
Feb 26, 2014
Messages
17
Reaction score
0
good people, I want a "pos" in doSummonMonster to Summon be in creating a desired "pos", I did it here, plus the summon is still not creating the desired "pos", then I want to know what you want I'm doing wrong .
////////////
//doSummonMonster(cid, name, pos)
lua_register(m_luaState,"doSummonMonster",LuaScriptInterface::luaDoSummonMonster);
////////////

int32_tLuaScriptInterface::luaDoSummonMonster(lua_State* L){
//doSummonMonster(cid, name, pos)
PositionEx pos;
popPosition(L, pos);
std::string name = popString(L);

ScriptEnviroment* env = getEnv();
Creature* creature = env->getCreatureByUID(popNumber(L));
if(!creature)
{
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushboolean(L,false);
return1;
}

lua_pushnumber(L, g_game.placeSummon(creature, name));
return1;}
 
Code:
lua_pushnumber(L, g_game.placeSummon(creature, name));

Because you're not still using position variable in your code (even function g_game.placeSummon can not use it as parameter).

Use this function (not tested)
Take care about result's verification of this function, before my changes it was returning just booleans, now returns numbers as RETURNVALUE_ info.
Oh, and with this function you don't need use pos parameter, if you want old behavior (summon monster near cid)
Code:
int32_t LuaScriptInterface::luaDoSummonMonster(lua_State* L){
   //doSummonMonster(cid, name[, pos])
   PositionEx pos;
   int32_t args = lua_gettop(L);
   if(args > 2)
     popPosition(L, pos);

   std::string name = popString(L);

   ScriptEnviroment* env = getEnv();
   Creature* creature = env->getCreatureByUID(popNumber(L));
   if(!creature) {
     errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
     lua_pushboolean(L, false);
     return 1;
   }
   if(args > 2) // if not specified summon position, use current summoner's one
     pos = creature->getPosition();

   // this is copied from Game::placeSummon from TFS ~r5700
   Monster* monster = Monster::createMonster(name);
   if(!monster) {
     lua_pushnumber(L, RET_NOTPOSSIBLE);
     return 1;
   }

   // Place the monster
   creature->addSummon(monster);
   if(g_game.placeCreature(monster, pos, true))
   {
     g_game.addMagicEffect(monster->getPosition(), MAGIC_EFFECT_TELEPORT);
     lua_pushnumber(L, RET_NOERROR);
     return 1;
   }

   creature->removeSummon(monster);
   lua_pushnumber(L, RET_NOTENOUGHROOM);
   return 1;
}
 
Last edited:

Similar threads

Replies
2
Views
561
Back
Top