Raised This Month: $ Target: $400
 0% 

Get random player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
poiuy_qwert
Junior Member
Join Date: Mar 2004
Old 09-26-2004 , 21:24   Get random player
Reply With Quote #1

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!
__________________
[p_q]poiuy_qwert[z_p]
poiuy_qwert is offline
Votorx
Senior Member
Join Date: Jun 2004
Old 09-27-2004 , 00:05  
Reply With Quote #2

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.
__________________
Currently Looking for a mod team.
Votorx is offline
Send a message via AIM to Votorx Send a message via MSN to Votorx Send a message via Yahoo to Votorx
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 09-27-2004 , 00:34  
Reply With Quote #3

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]
DS is offline
BAILOPAN
Join Date: Jan 2004
Old 09-27-2004 , 01:04  
Reply With Quote #4

maybe you should go from 1 to maxplayers instead of 1 to 32
__________________
egg
BAILOPAN is offline
poiuy_qwert
Junior Member
Join Date: Mar 2004
Old 09-27-2004 , 08:27  
Reply With Quote #5

Thank you so much guys!
__________________
[p_q]poiuy_qwert[z_p]
poiuy_qwert is offline
poiuy_qwert
Junior Member
Join Date: Mar 2004
Old 09-27-2004 , 13:26  
Reply With Quote #6

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?
__________________
[p_q]poiuy_qwert[z_p]
poiuy_qwert is offline
Votorx
Senior Member
Join Date: Jun 2004
Old 09-27-2004 , 18:12  
Reply With Quote #7

Unload the plugin from the hlds and run the hlds again. If no error comes up then yes it is your plugin.
__________________
Currently Looking for a mod team.
Votorx is offline
Send a message via AIM to Votorx Send a message via MSN to Votorx Send a message via Yahoo to Votorx
poiuy_qwert
Junior Member
Join Date: Mar 2004
Old 09-27-2004 , 20:11  
Reply With Quote #8

no its not the server that crashes, its the compiler when i try and compile the .sma to .amxx
__________________
[p_q]poiuy_qwert[z_p]
poiuy_qwert is offline
Votorx
Senior Member
Join Date: Jun 2004
Old 09-27-2004 , 20:25  
Reply With Quote #9

Oh well then yes it is your plugin
__________________
Currently Looking for a mod team.
Votorx is offline
Send a message via AIM to Votorx Send a message via MSN to Votorx Send a message via Yahoo to Votorx
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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