AlliedModders

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

Napoleon_be 05-03-2012 13:16

Choose random player
 
title say all..

i've thought of this which wont work i guess...
PHP Code:

new players[32], count
get_players
(playerscount"a")

players[random(count)] 


<VeCo> 05-03-2012 13:18

Re: Choose random player
 
It will work, just assign it to a variable.

Napoleon_be 05-03-2012 13:19

Re: Choose random player
 
Quote:

Originally Posted by <VeCo> (Post 1701278)
It will work, just assign it to a variable.

new randomplayer = players[random(count)] ?

<VeCo> 05-03-2012 13:20

Re: Choose random player
 
Yes, then that will be the index of the random player.

Napoleon_be 05-03-2012 13:24

Re: Choose random player
 
PHP Code:

public Cmd_KillVip(id) {
    
    new 
players[32], tsct
    get_players
(playersts"a""TERRORIST")
    
get_players(playersct"a""CT")
    
    new 
randomtsplayer players[random(ts)]
    new 
randomctplayer players[random(ct)]
    
    
set_user_health(randomtsplayer300)
    
set_user_health(randomctplayer300)
    
    
ColorChat(idGREEN"[%s] Objective:^1 Kill the opposite VIP!"szPrefix)
    
ColorChat(idGREEN"[%s]^1 The current round is:^4 Kill the VIP!"szPrefix)


Will this work?

<VeCo> 05-03-2012 13:29

Re: Choose random player
 
You don't need 2 variables if you only use the indexes for this.

PHP Code:

new players[32], countrandomplayer
 
get_players
(players,count,"ae","TERRORIST")
randomplayer players[random(count)]
set_user_health(randomplayer,300)
// if you need the random T index after this code, then you should make 2 variables, because we are getting the CT index in the same variable.......
 
get_players(players,count,"ae","CT")
randomplayer players[random(count)]
set_user_health(randomplayer,300)
 
ColorChat(idGREEN"[%s] Objective:^1 Kill the opposite VIP!"szPrefix)
ColorChat(idGREEN"[%s]^1 The current round is:^4 Kill the VIP!"szPrefix

Also, you need the "e" flag for the specific team in get_players.

Napoleon_be 05-03-2012 13:36

Re: Choose random player
 
ohh, thanks :)


All times are GMT -4. The time now is 00:19.

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