Raised This Month: $ Target: $400
 0% 

Looping through all players and getting global variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 06-18-2009 , 15:50   Looping through all players and getting global variable
Reply With Quote #1

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?
xbatista is offline
Send a message via Skype™ to xbatista
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-18-2009 , 21:47   Re: Looping through all players and getting global variable
Reply With Quote #2

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]] 
__________________

Last edited by Bugsy; 06-18-2009 at 21:49.
Bugsy is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 06-19-2009 , 02:00   Re: Looping through all players and getting global variable
Reply With Quote #3

Ahh yes thanks :]
xbatista is offline
Send a message via Skype™ to xbatista
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 06-19-2009 , 02:48   Re: Looping through all players and getting global variable
Reply With Quote #4

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
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. 

Last edited by xbatista; 06-19-2009 at 02:51.
xbatista is offline
Send a message via Skype™ to xbatista
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-19-2009 , 02:50   Re: Looping through all players and getting global variable
Reply With Quote #5

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)


__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 06-19-2009 , 02:53   Re: Looping through all players and getting global variable
Reply With Quote #6

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 :/

Last edited by xbatista; 06-19-2009 at 02:58.
xbatista is offline
Send a message via Skype™ to xbatista
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-19-2009 , 04:24   Re: Looping through all players and getting global variable
Reply With Quote #7

PHP Code:
    if(get_user_team(victim) == && g_Tickets[victim] > 1
-->
PHP Code:
    if(get_user_team(victim) == && g_Tickets[victim] > 0
__________________
Impossible is Nothing
Sylwester is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 06-19-2009 , 07:40   Re: Looping through all players and getting global variable
Reply With Quote #8

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
xbatista is offline
Send a message via Skype™ to xbatista
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-19-2009 , 08:07   Re: Looping through all players and getting global variable
Reply With Quote #9

Quote:
Originally Posted by xbatista View Post
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]; 
__________________

Last edited by Bugsy; 06-19-2009 at 08:16.
Bugsy is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 06-19-2009 , 11:32   Re: Looping through all players and getting global variable
Reply With Quote #10

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

Last edited by xbatista; 06-19-2009 at 11:36.
xbatista is offline
Send a message via Skype™ to xbatista
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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