Ok. Quite a request there =p.
Regarding the command itself, there should be a limit as to how often the player can use this. You could use PVars to record the last time the player used the command, the name they changed to and their original name (if this is needed).
To make it only available for hitmen, you would need to get the player's job, using whatever job system you have, and make sure they're a hitman.
Name Changing
So. The first way you could do this is by hiding the player's real name, then attaching a 3D label above their head to display a fake name.
ShowPlayerNameTagForPlayer- Hide a player's name for a specific player (use in a
for loop to hide for all players).
CreatePlayer3DTextLabel- Create the 3D label
This would save you a lot of effort working out whether the name they have chosen is available and making sure that the player's account is still saved correctly.
The 3D label may look a little fake, but that could be a way for perceptive players to work out if someone is a hitman.
The second way, the way you originally intended to use, would first need to make sure the name is valid:
- The player's name is not currently set to it: SetPlayerName returns 0 if that isn't true
- It's not currently in use by someone else, it's the correct length and doesn't contain invalid characters: SetPlayerName returns -1 if any of that isn't true
- It's not a registered name; Although you said you wanted this allowed, if the player who registered that name tried to connect, they wouldn't be able to because someone in-game already has their name.
It would then need to store the player's original name in a
PVar, so that the player's account can still be correctly saved (whenever the server tries to save the player's account, it would check if this
Pvar contains any value, and if it does, save to that account instead).
Creating a log entry would be helpful for tracking the player (e.g. "PLAYER disguised themself as PLAYER1"). So that if the player breaks any rules after changing their name, you know their true identity.
There would still be a problem with new players trying to connect with the name the player has disguised themself as, since the name is available for registering, but people can't connect with it until the disguised player has changed their name.
But anyway, the player's name would now be set to the new name. Any future name changes would not update the
PVar containing their original name.