- Joined
- Jul 7, 2007
- Messages
- 4,049
- Reaction score
- 238
Well, my other topic got deleted, dunno why, but whatever
Tested on TFS 0.4 rev 4395, but should also work with pretty much every other server
What it does
This function allows you to rename a single monster in-game so that if you want a single monster with an unique name, you don't have to make a new monster file, simply call this function and the monster's name will be what you wanted
IMPORTANT (Info on how to bypass below)
Tibia Client Limitation:
Tibia client stores in its memories the id of each creature and its name(along with other stuff I believe), so if you for example see a troll in thais, then walk to venore, change the troll name to something else like "FakeTroll" and go back to the Thais troll, you'd still see the name troll because your client had already seen that creature, so it stored its id and name, other players that had never seen that troll before you changed the name will see the new name, but anyone that had already seen it, continues to see the old name, same applies to NPCs and Players.
monster.h
find
then add this under public:
find
replace with
monster.cpp
find
then add the following code right above isIdle = true;
luascript.h
add near the similar lines
luascript.cpp
add near similar lines
add near similar lines
Done
Bypassing Tibia Client Limitation
There is a way to 'fix' the limitation on the sources which involves going thru the spectators list to update the reference to the monster, but I didn't did that because I fixed the problem thru other means, the tibia client only registers the name of the creature if it sees it, so if you create the summon in a distance, change the name and then teleport the monster to where you want it, by doing this the monster will show the expected name and it would be much faster to execute, which would mean less lag because its faster to make a simple teleport then it is to go thru all the spectators list and update the monster.
An example for this would be:
Rep+ if you like it
Tested on TFS 0.4 rev 4395, but should also work with pretty much every other server
What it does
This function allows you to rename a single monster in-game so that if you want a single monster with an unique name, you don't have to make a new monster file, simply call this function and the monster's name will be what you wanted
IMPORTANT (Info on how to bypass below)
Tibia Client Limitation:
Tibia client stores in its memories the id of each creature and its name(along with other stuff I believe), so if you for example see a troll in thais, then walk to venore, change the troll name to something else like "FakeTroll" and go back to the Thais troll, you'd still see the name troll because your client had already seen that creature, so it stored its id and name, other players that had never seen that troll before you changed the name will see the new name, but anyone that had already seen it, continues to see the old name, same applies to NPCs and Players.
monster.h
find
Code:
class Monster : public Creature
Code:
std::string name, nameDescription;
Code:
virtual const std::string& getName() const {return mType->name;}
virtual const std::string& getNameDescription() const {return mType->nameDescription;}
virtual std::string getDescription(int32_t) const {return mType->nameDescription + ".";}
Code:
virtual const std::string& getName() const {return name;}
virtual const std::string& getNameDescription() const {return nameDescription;}
virtual std::string getDescription(int32_t) const {return nameDescription + ".";}
monster.cpp
find
Code:
Monster::Monster(MonsterType* _mType):
Code:
name = _mType->name;
nameDescription = _mType->nameDescription;
luascript.h
add near the similar lines
Code:
static int32_t luaSetCreatureName(lua_State* L);
luascript.cpp
add near similar lines
Code:
//setCreatureName(cid, name, description)
lua_register(m_luaState, "setCreatureName", LuaInterface::luaSetCreatureName);
Code:
int32_t LuaInterface::luaSetCreatureName(lua_State* L)
{
//setCreatureName(cid, newName, newDescription)
std::string newDesc = popString(L);
std::string newName = popString(L);
ScriptEnviroment* env = getEnv();
Creature* creature;
if(creature = env->getCreatureByUID(popNumber(L))){
Monster* monster = (Monster*)creature;
monster->name = newName;
monster->nameDescription = newDesc;
lua_pushboolean(L, true);
}
else{
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
Done
Bypassing Tibia Client Limitation
There is a way to 'fix' the limitation on the sources which involves going thru the spectators list to update the reference to the monster, but I didn't did that because I fixed the problem thru other means, the tibia client only registers the name of the creature if it sees it, so if you create the summon in a distance, change the name and then teleport the monster to where you want it, by doing this the monster will show the expected name and it would be much faster to execute, which would mean less lag because its faster to make a simple teleport then it is to go thru all the spectators list and update the monster.
An example for this would be:
Code:
function createFakeTroll(spawnPos)
local farAwayPos = {x = 100, y = 100, z = 7} --Change This!!
local monster = doCreateMonster("Troll", farAwayPos)
setCreatureName(monster, "FakeTroll", "a fake troll")
doTeleportThing(monster, spawnPos)
end
Rep+ if you like it
Last edited: