• 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++ Adding random numbers to player name's problem

clouf

Member
Joined
Jul 5, 2012
Messages
158
Reaction score
23
Hello i made some change's for my war server.
People are logging on same character like this:
First guy logged with name Druid 87258
e31965584c7f52862f1bb0137758dc32.png

Second guy logged with name Druid 29778
06572d77c196bdad48457240551a62dc.png

Third guy logged with name Druid 77176
1a0dd3ae7e3fb3edc2d6934212b28b9d.png


And only first guy see other guys number properly, the rest see other's with number of last login guy.
Here's my code:
C++:
if(creature->getName() == "Druid")
        {
            srand(time(NULL));
            char kekeke[20];
            int GeneratedID;
            GeneratedID = rand() % 89999 + 10000;
            sprintf(kekeke, "Druid %d", GeneratedID);
            msg->putString(kekeke);
        }
 
Last edited:
Post more of your code,

Feature - setCreatureName & monster:setName for TFS 1.2

I would change their actual names rather than just what is printed on appear?
Assign a new name on login and force the char to reappear somewhere.

My guess is from your code your randomizing char names as they appear on your screen 1x,
which will be random for all players that are named Druid on your screen and it will be random each time someone appears with the name' Druid'.

You need to change the players actual name and cause the char to reappear on screen?

At least thats how it worked when I tried to mess with names/creature variables.

Theres some hacks around this you could try with storage values and names..

Easiest fix
You could ..
set a player a storage value on login with the random number and display the storage value instead of the random generated number.(You will need to make the char reappear in some way prob)

You could also..
Create a temporary new char instance copied from Druid in DB which is deleted on logout.
(log into new inserted char based on the option they chose, this would take a second to code correctly, BUT you could end up saving chars if you wanted and I believe it would be something that hasn't been done before)

if you pick the druid option then
--randomize player
--INSERT INTO players ` ~ etc)
--player-loadPlayer()

then DELETE FROM when they log out or allow the char to save.

There is a function called loadPlayer() gonna need to look at that will help you with that.

Meaning if Druid 12451 got 100 frags he could head through a door, rename his char and that char would be saved and not deleted, or if he doesnt the instance is deleted. Cool idea I think.


In reality you might as well just make 50-100 chars replica on an account like Umbys, but I get how this would look cool.

Best of luck.
 
Last edited:
set a player a storage value on login with the random number and display the storage value instead of the random generated number.
That's what i did, but there is problem with private messages (always when right click appear Message to Druid instead of name+ storage)
Anyway thanks for reply :)
 
That's what i did, but there is problem with private messages (always when right click appear Message to Druid instead of name+ storage)
Anyway thanks for reply :)
Hmmm.. 95% sure thats handled in client so thats harder to fix.
Only way would be to change the stored value of the name of the character ingame, rather than whats just printed for that to be fixed I believe.

You will have to change your onLook() as well to show the storage. :)
 
This is because the client cache the creatures when they are seen. So you have to force the client to "refresh". Take look on how setGhostMode works in the sources.
 
Back
Top