AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Randomly choosing a player (https://forums.alliedmods.net/showthread.php?t=24432)

Bruno 02-22-2006 16:15

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

Thanks

Hawk552 02-22-2006 16:20

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 }

Bruno 02-22-2006 16:25

Thanks for replying so fast. I got one question though. How do I use a stock function?

Hawk552 02-22-2006 16:29

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.

Bruno 02-22-2006 16:36

How do I use that? Where do I put my code?

Hawk552 02-22-2006 16:40

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.

Bruno 02-22-2006 16:50

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?

Jordan 02-22-2006 17:17

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

I think that should work.

Hawk552 02-22-2006 17:45

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")

Bruno 02-22-2006 18:22

Hawk that doesn't work for me. Is there any other way?


All times are GMT -4. The time now is 20:16.

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