AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   getting number of t's (https://forums.alliedmods.net/showthread.php?t=190045)

GhostMan 07-14-2012 06:08

getting number of t's
 
I want to get number of alive terrorists, so is code like that would be correct? (you may watch just first 7 lines)

PHP Code:

public cmd_box(id) {
    if(
is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_CT) {    
    
        new 
players[32], numT
        get_players
playersnumT"ae""TERRORIST" )
        
        if(
numT <= && numT && !g_BoxStarted) {
            static 
i
            
for(1<= g_max_clientsi++)
                if(
is_user_alive(i) && cs_get_user_team(i) == CS_TEAM_T)
                    
set_user_health(i100)

            
boxon true
            set_cvar_num
("mp_tkpunish"0)
            
set_cvar_num("mp_friendlyfire"1)
            
            
g_BoxStarted true
            
            set_hudmessage
(025500.080.2422.06.00.050.22)
            new 
name[33]; get_user_name(idnamecharsmax(name))
            
ShowSyncHudMsg(0g_HudSync"Priziuretojas %s Ijunge BOKSO rezima!"name)
        }
        else {
            
set_hudmessage(255000.080.2422.06.00.050.22)
            
ShowSyncHudMsg(idg_HudSync"Ijungti BOKSO rezimo dabar negalima!")
        }
    }
    return 
PLUGIN_HANDLED



<VeCo> 07-14-2012 06:30

Re: getting number of t's
 
PHP Code:

 new players[32], numT
get_players
playersnumT"ae""TERRORIST" 

Yes, the number or alive terrorists will be saved in the numT variable.

PHP Code:

static i
for(1<= g_max_clientsi++)
if(
is_user_alive(i) && cs_get_user_team(i) == CS_TEAM_T)
       
set_user_health(i100

Since you use get_players, it's better to make this loop like this:

PHP Code:

static i
for(0numTi++)
       
set_user_health(players[i],100

In players array you have the indexes of all alive terrorists.

SpeeDeeR 07-14-2012 07:39

Re: getting number of t's
 
Quote:

Originally Posted by <VeCo> (Post 1750070)
PHP Code:

static i
for(0numTi++)
       
set_user_health(players[i],100


Dont re-index arrays.

hleV 07-14-2012 07:43

Re: getting number of t's
 
Quote:

Originally Posted by SpeeDeeR (Post 1750112)
Dont re-index arrays.

Re-indexing would be if he did it more than once.

Bugsy 07-14-2012 11:22

Re: getting number of t's
 
Quote:

Originally Posted by SpeeDeeR (Post 1750112)
Dont re-index arrays.

Show us how you would do this code example, assuming we are only setting health.
PHP Code:

static i
for(0numTi++)
       
set_user_health(players[i],100



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

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