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

C++ Set Creature Name (need help with source)

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
So, I have used this script from:

Feature - setCreatureName & monster:setName for TFS 1.2
https://otland.net/threads/setcreaturename-monster-setname-for-tfs-1-2.245108/
it adds additional function which allows you to change the name of your summon, or any creature really.

but it does not work that well because the player has to log out in order for the name to appear correctly

the description works just fine, if anyone knows what is wrong and tell me how that could be fixed please let me know
 
Solution
You mean that player see old name of monster? Try to check what happen if you change the name of monster which wasnt been seen by anyone. If this way will work, best "fix" for this is to teleport monster somewhere - far from players, change his name and then teleport him back to his latest position.
You mean that player see old name of monster? Try to check what happen if you change the name of monster which wasnt been seen by anyone. If this way will work, best "fix" for this is to teleport monster somewhere - far from players, change his name and then teleport him back to his latest position.
 
Solution
You mean that player see old name of monster? Try to check what happen if you change the name of monster which wasnt been seen by anyone. If this way will work, best "fix" for this is to teleport monster somewhere - far from players, change his name and then teleport him back to his latest position.
I recently wrote a post in the linked thread with "a bit" harder possibility of solving this. Your suggestions, while hacky, seems to be pretty easy to implement and would solve the problem I guess.
 
You mean that player see old name of monster? Try to check what happen if you change the name of monster which wasnt been seen by anyone. If this way will work, best "fix" for this is to teleport monster somewhere - far from players, change his name and then teleport him back to his latest position.

This workaround works thanks!

I recently wrote a post in the linked thread with "a bit" harder possibility of solving this. Your suggestions, while hacky, seems to be pretty easy to implement and would solve the problem I guess.

I've looked at your reply, and also looked at monster.cpp

this code is already included there;

C++:
        //Notify surrounding about the change
        SpectatorVec list;
        g_game.getSpectators(list, getPosition(), true);
        g_game.getSpectators(list, creature->getPosition(), true);
        for (Creature* spectator : list) {
            spectator->onCreatureConvinced(creature, this);
        }

and I think it should work when updating the creature name, or maybe it needs to be executed again, like after the name has changed? but how

I'll try and add this part in monster.h (or not, has to be monster.cpp)
 
Last edited:
This workaround works thanks!



I've looked at your reply, and also looked at monster.cpp

this code is already included there;

C++:
        //Notify surrounding about the change
        SpectatorVec list;
        g_game.getSpectators(list, getPosition(), true);
        g_game.getSpectators(list, creature->getPosition(), true);
        for (Creature* spectator : list) {
            spectator->onCreatureConvinced(creature, this);
        }

and I think it should work when updating the creature name, or maybe it needs to be executed again, like after the name has changed? but how

I'll try and add this part in monster.h (or not, has to be monster.cpp)

Yes, this code is there, but it is not executed when you set new name to a monster. This is just an example I pointed out to show what happens when monster is added (summoned or spawned) - spectators are made aware of this event, this is missing from the code you linked to - it only changes the name on server side, but does not inform users (those who can actually see this monster at the time the name is changed) about that change. This is why you don't see the name changed.
 
Yes, this code is there, but it is not executed when you set new name to a monster. This is just an example I pointed out to show what happens when monster is added (summoned or spawned) - spectators are made aware of this event, this is missing from the code you linked to - it only changes the name on server side, but does not inform users (those who can actually see this monster at the time the name is changed) about that change. This is why you don't see the name changed.

which means that I should either use the workaround specified above or write my own C++ function to execute on nameChange

I really want to do the latter just because I won't have to deal with teleports but at the same time I feel like I am going to break something inside the source

:eek:
 
which means that I should either use the workaround specified above or write my own C++ function to execute on nameChange

I really want to do the latter just because I won't have to deal with teleports but at the same time I feel like I am going to break something inside the source

:eek:

The "workaround" is really not a workaround, because it will send information about convincing creature to the client, not to change the name. This is just something I wanted to show you that happens on convincing the creature. Basically you need to inform all spectators of that change. But I am not that familiar with Tibia / OTClient to tell you if any of them actually accepts such information and deal with it. I would say it's actually highly unlikely. With OTClient its easier, because you can always extend it. But I'm afraid you will need support from someone more familiar with Tibia/OTS networking stack to tell you how this could be possibly implemented in TFS + OTClient, because I have no knowledge on that.

So this is as far as my help can you - pointing out what's missing that leaves the old name on player's screen and giving you theory behind making the fix. But unfortunately my knowledge is limited to this, so I can't provide you with a working solution. But perhaps you can pick it up from there (or find someone who can) to find a way to implement it. My guess, unless Tibia/OTClient has this built-in, you will need an extended OpCode. This will limit your server to OTClient though. But to verify this information, you will need to ask someone of greater knowledge on this, I'm just guessing here.
 
Back
Top