AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Looping through all players and getting global variable (https://forums.alliedmods.net/showthread.php?t=95024)

xbatista 06-18-2009 15:50

Looping through all players and getting global variable
 
PHP Code:

new counted_spawns
public event_deathmsg5()
{
    new 
victim read_data(2)

    if(
get_user_team(victim) == && g_Tickets[victim] > 1)
    {
        
g_Tickets[victim]--
        
set_task(get_pcvar_float(cvar_respawndelay), "respawn_player"victim)
        
client_print(victimprint_chat"Tickets left: %d"g_Tickets[victim])
    }
    
    new 
Players[32], iNum 0i;
    
    
get_players(PlayersiNum"ae""TERRORIST")
    if(
iNum 0)
    {
        for(
0iNum; ++i
            
counted_spawns g_Tickets[Players[i]]
    }

    
set_hudmessage(0255500.020.2713.03.0)
    
ShowSyncHudMsg(0g_msgHudSyncX"Preds Remaining : %i"counted_spawns)



Why it gets only the victim g_Tickets? I've loop it through all players and get all tickets in terrorist team.
It prints always : Preds Remaining : 2 or 1 (it's only victim) . I need to get all terrorist team g_Tickets, so why it won't?

Bugsy 06-18-2009 21:47

Re: Looping through all players and getting global variable
 
Code:
new counted_spawns public event_deathmsg5() {     new victim = read_data(2)     if(get_user_team(victim) == 1 && g_Tickets[victim] > 1)     {         g_Tickets[victim]--         set_task(get_pcvar_float(cvar_respawndelay), "respawn_player", victim)         client_print(victim, print_chat, "Tickets left: %d", g_Tickets[victim])     }         new Players[32], iNum = 0, i;         get_players(Players, iNum, "ae", "TERRORIST")     if(iNum > 0)     {         for(i = 0; i < iNum; ++i)             counted_spawns = g_Tickets[Players[i]]     }     set_hudmessage(0, 255, 50, 0.02, 0.27, 1, 3.0, 3.0)     ShowSyncHudMsg(0, g_msgHudSyncX, "Preds Remaining : %i", counted_spawns) }

PHP Code:

counted_spawns += g_Tickets[Players[i]] 


xbatista 06-19-2009 02:00

Re: Looping through all players and getting global variable
 
Ahh yes thanks :]

xbatista 06-19-2009 02:48

Re: Looping through all players and getting global variable
 
Bug.
Imagine in the server are 11 players and get_pcvar_num(cvar_tickets) = 2
It will print always when kill : "Preds Remaining : 21,then in second kill 41, in third global kill 60 etc...
I don't need to "+" :/ So how to fix :mrgreen:
PHP Code:

public Ev_RoundRestart()
{
    for (new 
id 1id <= g_maxplayersid++)
    {
        
g_Tickets[id] = get_pcvar_num(cvar_tickets)
    }


PHP Code:

cvar_tickets register_cvar("amx_tickets""2"// Give X tickets on round start. 


Exolent[jNr] 06-19-2009 02:50

Re: Looping through all players and getting global variable
 
PHP Code:

new counted_spawns
public event_deathmsg5()
{
    new 
victim read_data(2)

    if(
get_user_team(victim) == && g_Tickets[victim] > 1)
    {
        
g_Tickets[victim]--
        
set_task(get_pcvar_float(cvar_respawndelay), "respawn_player"victim)
        
client_print(victimprint_chat"Tickets left: %d"g_Tickets[victim])
    }
    
    new 
Players[32], iNum 0i;
    
    
get_players(PlayersiNum"ae""TERRORIST")
    
counted_spawns 0;
    if(
iNum 0)
    {
        for(
0iNum; ++i
            
counted_spawns += g_Tickets[Players[i]]
    }

    
set_hudmessage(0255500.020.2713.03.0)
    
ShowSyncHudMsg(0g_msgHudSyncX"Preds Remaining : %i"counted_spawns)




xbatista 06-19-2009 02:53

Re: Looping through all players and getting global variable
 
Already tryied that trick Exo, when all players dead and have 0 tickets, it will print "Preds Remaining : 11"
So i've made this :
PHP Code:

    get_players(PlayersiNum"e""TERRORIST")
    
counted_spawns 0;
    if(
iNum 0)
    {
        for(
0iNum; ++i
        {
            if ( 
g_Tickets[Players[i]] > )
            {
                
counted_spawns += g_Tickets[Players[i]]
            }
        }
    } 

Still there are bug :/ When tickets goes from 21 to 11, it's stop :0 Writes "Preds Remaining : 11"
But I've check if g_Tickets[Players[i]] > 0 :/

Sylwester 06-19-2009 04:24

Re: Looping through all players and getting global variable
 
PHP Code:

    if(get_user_team(victim) == && g_Tickets[victim] > 1

-->
PHP Code:

    if(get_user_team(victim) == && g_Tickets[victim] > 0


xbatista 06-19-2009 07:40

Re: Looping through all players and getting global variable
 
Still buggy, when 7 terrors left and you will kill all ,it wil write " Preds Left: 1 "
God damn it

Maybe someone can give a good code that will count all tickets from whole terrorist team

Bugsy 06-19-2009 08:07

Re: Looping through all players and getting global variable
 
Quote:

Originally Posted by xbatista (Post 852252)
Still buggy, when 7 terrors left and you will kill all ,it wil write " Preds Left: 1 "
God damn it

Maybe someone can give a good code that will count all tickets from whole terrorist team

I still don't get what tickets are :B

I see no logic in 21, 41, 60 as you said above.

Loop through all alive terrorists and add up tickets?
PHP Code:

for( new <= g_iMaxPlayers i++ )
    if ( 
is_user_alive) && ( get_user_team) == ) )
        
counted_spawns += g_Tickets]; 


xbatista 06-19-2009 11:32

Re: Looping through all players and getting global variable
 
Tickets - I mean how much times you can respawn.

You gave the same code :/
PHP Code:

    new Players[32], iNum 0i;
    
    
get_players(PlayersiNum"ae""TERRORIST")
    if(
iNum 0)
    {
        for(
0iNum; ++i)             counted_spawns += g_Tickets[Players[i]]

    } 

Understand that wouldn't be enough ,it will be buggy, this will add EACH KILL !
Like exolents says you must then do
PHP Code:

counted_spawns 0

And yes I done it,but there are another bug, when all players tickets are 0, it will show always "11"( Preds Remainig : 11 )
It will show then 11 players in teror team and not all tickets of players.
God damn it, hard to explain


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

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