AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get random player (https://forums.alliedmods.net/showthread.php?t=6298)

poiuy_qwert 09-26-2004 21:24

Get random player
 
I need a way to get a random players ID in the game, set it to a variable, then set another variable to that players name. Thanks!

Votorx 09-27-2004 00:05

new player = random_num(1,32)
then make an if statement to check if its a valid ent/player. If it isn't then just run the same line again.

DS 09-27-2004 00:34

Votorx is certainly correct.

But if you'd like a more complete example of doing all you said:

Getting the random player ID in variable named player
Code:
new maxpl = get_maxplayers() // Get max number of possible players for the server new player = random_num(1, maxpl)     while (!is_user_connected(player))     player = random_num(1, maxpl) // Get new random player id if player not connected

And then to get the player's name based on that random player id
Code:
new name[32] get_user_name(player, name, 31)

And now the variable called "name" will have the randomly selected player's name in it.

Hope this has helped.

[edit]Ah, yes you are right Bailopan. Using maxplayers would be more efficient. Changed the code.[/edit]

BAILOPAN 09-27-2004 01:04

maybe you should go from 1 to maxplayers instead of 1 to 32

poiuy_qwert 09-27-2004 08:27

Thank you so much guys!

poiuy_qwert 09-27-2004 13:26

Im put your code into my plugin and ran the compiler, and it said Internal Error and gave the windows Not Responding window. Do you think it could have anything to do with the plugin?

Votorx 09-27-2004 18:12

Unload the plugin from the hlds and run the hlds again. If no error comes up then yes it is your plugin.

poiuy_qwert 09-27-2004 20:11

no its not the server that crashes, its the compiler when i try and compile the .sma to .amxx

Votorx 09-27-2004 20:25

Oh well then yes it is your plugin


All times are GMT -4. The time now is 17:25.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.