• 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 doPlayerFollowCreature(cid,target)

Syntax

Developer
Joined
Oct 10, 2007
Messages
2,890
Reaction score
458
Location
Texas
Example: (will follow a creature named Syntax)
Code:
doPlayerFollowCreature(cid,getCreatureName("Syntax")
NOTEs:
Code:
Green square will not appear as if followed through client.
Only supports players following creatures, not vice-versa.

luascript.cpp
After the line: lua_register(m_luaState, "doPlayerSetPartner", LuaInterface::luaDoPlayerSetPartner); ADD:
Code:
	//doPlayerFollowCreature(cid)
	lua_register(m_luaState, "doPlayerFollowCreature", LuaInterface::luaDoPlayerFollowCreature);
After the function: int32_t LuaInterface::luaDoPlayerSetPartner(lua_State* L) ADD:
Code:
int32_t LuaInterface::luaDoPlayerFollowCreature(lua_State* L)
{
	//doPlayerFollowCreature(cid, target)
	ScriptEnviroment* env = getEnv();

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

	Player* player = env->getPlayerByUID(popNumber(L));
	if(!player)
	{
		errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushboolean(L, false);
	}

	g_game.playerFollowCreature(player->getID(), creature->getID());
	lua_pushboolean(L, true);
	return 1;
}
luascript.h
After the line: static int32_t luaDoPlayerSetPartner(lua_State* L); ADD:
Code:
        static int32_t luaDoPlayerFollowCreature(lua_State* L);

Enjoy.
 
Already tested on 0.4dev, if you have otherwise and tested, let me know how it goes.
 
Nice!

Can you make a doPlayerAttackCreature(cid, target)? :d
 
If i change
int32_t LuaInterface::luaDoPlayerFollowCreature(lua_State* L)
{
//doPlayerFollowCreature(cid, target)
ScriptEnviroment* env = getEnv();

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

Player* player = env->getPlayerByUID(popNumber(L));
if(!player)
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}

g_game.playerFollowCreature(player->getID(), creature->getID());
lua_pushboolean(L, true);
return 1;
}

to

int32_t LuaInterface::luaDoPlayerFollowCreature(lua_State* L)
{
//doPlayerFollowCreature(cid, target)
ScriptEnviroment* env = getEnv();

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

Player* player = env->getPlayerByUID(popNumber(L));
if(!player)
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}

g_game.playerFollowCreature(creature->getID(), player->getID());
lua_pushboolean(L, true);
return 1;
}

Work vice versa or not?playerFollowCreature workig only for player-->monster?
 
Great as always, adding it to TFS.

BTW:
There is a little typo at beggining:
doPlayerFollowCreature(cid,getCreatureName("Syntax")

should be:
doPlayerFollowCreature(cid, getCreatureByName("Syntax"))
 
If i change


to



Work vice versa or not?playerFollowCreature workig only for player-->monster?

players can follow monsters, players can follow players, use set target for monsters, use the built in npc function for npcs following
 
Back
Top