Unique player naming is difficult and can be cumbersome to achieve within a map on its own. This prefab will make it easy for you (a map maker, I presume) to do in your map.
This logic improves on an outdated version (found here on TF2Maps).
What this logic improves on from the last version is:
FAQ : How do I set this up?
- All naming logic is condensed to where it only needs to be activated by a single relay. Then boom! It works.
- No longer needs an supermassive map-wide trigger to use.
- Works faster and with less stress on the server to operate.
FAQ : What do I need to know as a Map Maker when I use the Improved Unique Player Naming Logic system?
- Place a way to Trigger "relay_name_players". (A trigger_multiple over respawn would do! Can be one big trigger or individual ones)
- Place all other logic in the map, typically somewhere that is inaccessible by the player.
- You can easily place this anywhere by using a func_instance and hooking up this file to it. Look at this guide for more info: https://tf2maps.net/threads/guide-instances-and-you.24784/#post-331700
- That's it.
- This system only needs one way to boot up, and it can be done at any time and does not need a player (or !activator) to start it. The best way (I imagine) for this to fire up is when a player spawns into the map. In this way, all players will have a unique name.
- This uses OnUser4
- OnUser4 is used to "echo" back to the Naming system to see if the player is still in the server and that the name is or isn't being used. This one is preferably kept clear of use at all times, so the game can write the state of the name back to this system.
- If ever you wanted to write attributes to the player or write a unique OnUser to them, put the I/O's in the trigger_multiple named naming_logic that's in this prefab.
FAQ : How does the logic work?
At the beginning of a round, the Improved Unique Player Naming Logic system will activate.
First, it will write to all named players and check to see if any names are taken. If no, continues to #1. If yes, it'll account for any name(s) taken and write again to the player for OnUser4 to tell the Improved Unique Player Naming system that their name is, well, taken! (It sets the logic_branch for that player to False, which means the name is being used)
Please read the article for Egg War in the Special Thanks.
- When the round starts (or a player touches the one trigger_multiple), it will proc the relay_name_players.
- From there, it will pick all players and add an addoutput "OnUser4 naming_logic:StartTouch::0:1", then FireUser4. This means all players will touch the naming_logic trigger immediately and anywhere in the map.
- The naming_logic trigger filters by unnamed players, and can only deal with one player at a time due to OnStartTouchAll. It then fires DisableAndEndTouch to refresh itself. (using StartTouch will always proc a trigger, even while disabled!)
- The queue system is made up of logic_branch entities that assign and decline player names. If a logic_branch is set to True, it will assign the unique name and stop there. If it is False, it will skip itself and move to the next logic_branch and see if that one is True.
- If all logic_branches are taken, it will automatically reset all logic_branch entities to True, and force players to send out an "echo" to see if they are still in the server. If a player is there, then their assigned logic_branch is set to False.
- The last piece of the puzzle is a way to trigger all of this. It is done by a player respawning into a trigger_multiple that procs the relay "relay_name_players", which does all of this over again!