Get Player Id that isnt limited to loop


#1

How would I go about getting a player id, that way I dont have to use a for loop that is limited.


#2

In what context? When do you want to “get the player id”?

Anyways, the loop isn’t that bad. You’re only going from 1 to 32 so, it shouldn’t slow down the server to any notable degree (unless it’s an old server).


#3

The source id, and wouldnt 1-32 be limited to those source id’s? Anything larger wouldnt work, or would it?


#4

Well, the server only knows the player as their net id.

For example,

  • Havoc joins server (given id of 1)
  • MrDaGree joins (given id of 2)

The server only knows “Havoc” as 1 and “MrDaGree” as 2. If you want to get the player’s name you need to call the GetPlayerName( INT ) function on the server (see here).

If you’re worried about the loop being limited to 32, you can always use the GetPlayers (see here) function to get a table of players connected to the server and loop through that instead.


#5

Ahhh Thank you! That makes much more sense.