• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

[8.42+] NPC selfFollow to a creature!

Grim90

New Member
Joined
Jul 11, 2008
Messages
35
Reaction score
0
Hi
As known, NPC selfFollow works ONLY if we set a player to be a target. What I mean? I mean, if I use selfFollow, NPC will be following only a player, but not a creature which we wish to be following.

Due to this I fixed it yesterday:

npc.cpp
Find:

Code:
lua_register(m_luaState, "selfFollow", NpcScriptInterface::luaActionFollow);

Add below:

Code:
lua_register(m_luaState, "selfFollowCreature", NpcScriptInterface::luaActionFollowCreature);

Find:

Code:
int32_t NpcScriptInterface::luaActionFollow(lua_State* L)

Add below (as a new function of course):

Code:
int32_t NpcScriptInterface::luaActionFollowCreature(lua_State* L)
{
	//selfFollowCreature(cid)

	ScriptEnviroment* env = getScriptEnv();

	Creature* creature = env->getCreatureByUID(popNumber(L));
	Npc* npc = env->getNpc();
	if(!creature)
	{
		lua_pushboolean(L, false);
		return 1;
	}

	
	if(!npc)
	{
		lua_pushboolean(L, false);
		return 1;
	}

	lua_pushboolean(L, npc->setFollowCreature(creature, true));
	return 1;
}

npc.h
Find:

Code:
static int32_t luaActionFollow(lua_State* L);

Add below:

Code:
static int32_t luaActionFollowCreature(lua_State* L);

Compile it and done.

Then you shall use selfFollowCreature(cel) instead of selfFollow(cel)

Tested with TFS 0.3 for 8.42.
 
Last edited:
can be used with monsters too, i suppose :S
useless

Can, of course, but why the heck you would use NPC to fe. attack monsters (like Guard) if you can have a Summon?

Ok, ok, I lose here, gonna do selfFollow on 0.4 to work with creatures. That can be good for commanded Summons, like Pokemons or stuff.
 
Can, of course, but why the heck you would use NPC to fe. attack monsters (like Guard) if you can have a Summon?

Ok, ok, I lose here, gonna do selfFollow on 0.4 to work with creatures. That can be good for commanded Summons, like Pokemons or stuff.

Well for example I made a NPC who kills monsters and give a mission to kill 80 of them to get a reward. He is just asking for help. It's nice for RPG servers.
 
Back
Top