AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Randomly select three terrorist (https://forums.alliedmods.net/showthread.php?t=172264)

quLeryuzz 11-18-2011 02:57

[HELP] Randomly select three terrorist
 
Hello, The following code selects random 3 live terrorist.I would like to choose the dead players.How can I do?

PHP Code:

            new Players[32], iCountrasgele1rasgele2rasgele3
            get_players
(Players,iCount,"ae","TERRORIST")
            if(
iCount 2)
            {
                
rasgele1 Playersrandom_num(0iCount) ]
                
rasgele2 Playersrandom_num(0iCount) ]
                
rasgele3 Playersrandom_num(0iCount) ]
                while( 
rasgele2 == rasgele3 || rasgele2 == rasgele1)
                {
                    
rasgele2 Playersrandom_num(0iCount) ]    
                }
                while( 
rasgele3 == rasgele1)
                {
                    
rasgele3 Playersrandom_num(0iCount) ]    
                }
                new 
terr1[64],terr2[64],terr3[64]
                
get_user_name(rasgele1terr163)
                
get_user_name(rasgele2terr263)
                
get_user_name(rasgele3terr363)
                
set_hudmessage(2552552550.030.6006.05.0,_,_,21)
                
show_hudmessage(0"Rasgele 3 Mahkum :^n%s^n%s^n%s",terr1,terr2,terr3


Sylwester 11-18-2011 04:31

Re: [HELP] Randomly select three terrorist
 
Your code is very inefficient, this is how you should do it:
PHP Code:

            new Players[32], iCount
            get_players
(Players,iCount,"be","TERRORIST")
            
            new 
terr_id[3], terr_cntrandcache[96], posname[32]
            while(
iCount && terr_cnt 3)
            {
                
terr_id[terr_cnt] = Players[rand random(iCount)]
                
Players[rand] = Players[--iCount]
                
                
get_user_name(terr_id[terr_cnt], namesizeof(name)-1)
                
pos += formatex(cache[pos], sizeof(cache)-pos-1"^n%s"name)
                
                
terr_cnt++
            }
            
set_hudmessage(2552552550.030.6006.05.0,_,_,21)
            
show_hudmessage(0"Rasgele %d Mahkum :%s"terr_cntcache


Devil259 11-18-2011 05:37

Re: [HELP] Randomly select three terrorist
 
Use charsmax instead of sizeof -1

drekes 11-18-2011 06:04

Re: [HELP] Randomly select three terrorist
 
Quote:

Originally Posted by Devil259 (Post 1598457)
Use charsmax instead of sizeof -1

Doesn't matter, it's the same thing.

string.inc:
Code:

#define charsmax(%1) (sizeof(%1)-1)

quLeryuzz 11-18-2011 11:01

Re: [HELP] Randomly select three terrorist
 
I guess I could not tell.I want to randomly select 3 players different from each other.I gave my players not dead code.I would like to take this to the players dead :|

Sylwester 11-18-2011 11:28

Re: [HELP] Randomly select three terrorist
 
Did you check my code? It should do what you requested (randomly selects up to 3 dead terrorists).

quLeryuzz 11-18-2011 11:33

Re: [HELP] Randomly select three terrorist
 
@Sylwester
I tried yours."Rasgele 0 Mahkum : ----" I do not get a result.

Sylwester 11-18-2011 12:07

Re: [HELP] Randomly select three terrorist
 
To get results you need to have dead terrorists on your server.

quLeryuzz 11-18-2011 12:12

Re: [HELP] Randomly select three terrorist
 
For both live and dead I wanted to make a selection.

quLeryuzz 11-18-2011 12:21

Re: [HELP] Randomly select three terrorist
 
I solved the problem.Thank those who help :)

PHP Code:

            get_players(Players,iCount,"be","TERRORIST"

>

PHP Code:

            get_players(Players,iCount,"e","TERRORIST"



All times are GMT -4. The time now is 08:34.

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