Raised This Month: $ Target: $400
 0% 

Randomly choosing a player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bruno
Member
Join Date: Jun 2005
Old 02-22-2006 , 16:15   Randomly choosing a player
Reply With Quote #1

How can I randomly choose a player in game and execute a function on that player?

Thanks
__________________
If you have but one shot at an opportunity, make it count.
Bruno is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-22-2006 , 16:20  
Reply With Quote #2

Try this:

Code:
// stock function stock random_player() {     new iPlayer, iPlayers = get_playersnum()     while(!is_user_alive(iPlayer))         iPlayer = random_num(1,iPlayers)         return iPlayer }
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Bruno
Member
Join Date: Jun 2005
Old 02-22-2006 , 16:25  
Reply With Quote #3

Thanks for replying so fast. I got one question though. How do I use a stock function?
__________________
If you have but one shot at an opportunity, make it count.
Bruno is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-22-2006 , 16:29  
Reply With Quote #4

Sorry, if that doesn't work, try this:

Code:
// stock function stock random_player() {     new iPlayer, iPlayers = get_playersnum()     while(!is_user_connected(iPlayer))         iPlayer = random_num(1,iPlayers)         return iPlayer }

I forgot you didn't specify whether or not the person has to be alive.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Bruno
Member
Join Date: Jun 2005
Old 02-22-2006 , 16:36  
Reply With Quote #5

How do I use that? Where do I put my code?
__________________
If you have but one shot at an opportunity, make it count.
Bruno is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-22-2006 , 16:40  
Reply With Quote #6

Put it at the end of your script, then anywhere use this:

Code:
new player = random_player()

And a random player will be stored into player.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Bruno
Member
Join Date: Jun 2005
Old 02-22-2006 , 16:50  
Reply With Quote #7

I'm sorry man I'm still not really getting you. For example let's say that I just wanted to put a client_print on a random person with a task that checks it. How would I include that code in?
__________________
If you have but one shot at an opportunity, make it count.
Bruno is offline
Jordan
Veteran Member
Join Date: Aug 2005
Old 02-22-2006 , 17:17  
Reply With Quote #8

Code:
 new player = random_player() client_print(player, print_chat, "z0mg GABEN")

I think that should work.
Jordan is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-22-2006 , 17:45  
Reply With Quote #9

Quote:
Originally Posted by ^_^Satan^_^
Code:
 new player = random_player() client_print(player, print_chat, "z0mg GABEN")

I think that should work.
No, it would work, but this would be faster:

Code:
client_print(random_player(),print_chat,"zomg gaben")
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Bruno
Member
Join Date: Jun 2005
Old 02-22-2006 , 18:22  
Reply With Quote #10

Hawk that doesn't work for me. Is there any other way?
__________________
If you have but one shot at an opportunity, make it count.
Bruno is offline
Reply


Thread Tools
Display Modes

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 20:16.


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