• 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!

Lua Function moveCreatureTo(cid,pos[,mindist[,maxdist]])

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
By mock the bear.
Tested on TFS 0.3.6pl1

Go to luascript.cpp
in last line add:
Code:
int32_t LuaScriptInterface::luamoveCreatureTo(lua_State* L)
{
        //moveCreatureTo(cid,pos[,mindist[,maxdist]])
	ScriptEnviroment* env = getEnv();
	uint32_t mindist = 1, maxdist = 1;
	if(lua_gettop(L) > 3)
		maxdist = popNumber(L);
	if(lua_gettop(L) > 2)
		mindist = popNumber(L);
		
	PositionEx pos;
	popPosition(L, pos);
	if(Creature* creature = env->getCreatureByUID(popNumber(L)))
	{
	    std::list<Direction> listDir;
	    if(!g_game.getPathToEx(creature, pos, listDir, 1, maxdist, true, true))
	    {
         lua_pushboolean(L, false);                        
         return 1;
         }       

	     creature->startAutoWalk(listDir);
	     lua_pushboolean(L, true);
	}
	else
	{
		errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
		lua_pushboolean(L, false);
	}
	return 1;
}
and before
Code:
lua_register(m_luaState, "doPlayerAddMapMark", LuaScriptInterface::luaDoPlayerAddMapMark);
add:
Code:
        //moveCreatureTo(cid,pos[,minist [,maxdist]])
	lua_register(m_luaState, "moveCreatureTo", LuaScriptInterface::luamoveCreatureTo);

On luascript.h
before:
Code:
static int32_t luaGetPlayerByGUID(lua_State* L);
add:
Code:
static int32_t luamoveCreatureTo(lua_State* L);

:thumbup:
 
Last edited:
@Diath
yes i know -.-
the forum format break some tab :S
 
@Diath
yes i know -.-
the forum format break some tab :S

So simply use
Code:
 instead, btw. this part also sux in tabbing (even if they're spaces):
[CODE]
	if(Creature* creature = env->getCreatureByUID(popNumber(L)))
	{
	    std::list<Direction> listDir;
	    if(!g_game.getPathToEx(creature, pos, listDir, 1, maxdist, true, true))
	    {
         lua_pushboolean(L, false);                        
         return 1;
         }
 
@unknown666
no, it move creature to a max dist i think 5 or 6 (screen size)
or else create a function with many addEvents to move more than 6 sqms using moveCreatureTo, 1 per 6 sqms :)
 
I test here and when i put to move only one square it works but if i put a number in maxdist this dont work the summon goes annother place and only one square...they dont walk to the place that i want...
what can be?
 
I had the same problem of "charmebdx" so that my if I click to go further than a home he walks back to the first and the same place it was before. So a walk home if you click the one hand sqm. Another problem is if I click to it <<<he walks to her>>> for it and if you click \ / he goes to la / \ (only 1 sqm) and also the monsters through walls. Can anyone help me solve this problem?
 
So simply use
Code:
 instead, btw. this part also sux in tabbing (even if they're spaces):
[/QUOTE]

Why using [code] if you have [cpp] tag.

[cpp]
	if(Creature* creature = env->getCreatureByUID(popNumber(L)))
	{
	    std::list<Direction> listDir;
	    if(!g_game.getPathToEx(creature, pos, listDir, 1, maxdist, true, true))
	    {
         lua_pushboolean(L, false);                        
         return 1;
         }      
[/cpp]
 
I already have got the problem of the creature going to the opposite of what is sent, so I still have a problem:

The Creature walks so I even put a SQM distMin distMax and she just walks a SQM.

Someone help me fix this problem?

Thanks in advance.
Cezinha
 
mock, give me a exemple for use, here it don't work, but, don't have any erros in console...
 
Nobody can I solve my problem here? As the leon00 speak there, I guess I'm not knowing how to make the script correctly, could someone give me an example of how I would script it works for corretamete?
 
PHP:
function onUse(cid, item, pos, itemEx, topos)
moveCreatureTo(cid, topos, 1,1)
return true
end
 
I got this error.. Creature move only 1 sqm.. and do not go to final position...

[12/12/2010 16:47:09] [Error - Action Interface]
[12/12/2010 16:47:09] In a timer event called from:
[12/12/2010 16:47:09] actions/scripts/tools.lua:eek:nUse
[12/12/2010 16:47:09] Description:
[12/12/2010 16:47:09] attempt to index a nil value
[12/12/2010 16:47:09] stack traceback:
[12/12/2010 16:47:09] [C]: ?

Used on this:
function onUse(cid, item, pos, itemEx, topos)
if(isInArray(2767, itemEx.itemid)) then
doCreatureSay(cid, getCreatureName(getPlayerPet(cid)) .. ', Cut!', TALKTYPE_SAY)
local pos = getClosestFreeTile(getPlayerPet(cid), pos)
moveCreatureTo(getPlayerPet(cid), pos, topos)
for i = 2, 3 do
addEvent(doSendMagicEffect, i * 100, toPosition, i)
end
doRemoveItem(itemEx.uid)
addEvent(doCreateItem, 5 * 1000, 2767, 1, toPosition)
else
returnMessage(cid, "This is impossible.")
end
return true
end
 
Last edited:
Back
Top