AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   check alive players from a team problem (https://forums.alliedmods.net/showthread.php?t=89447)

Owyn 04-06-2009 13:07

check alive players from a team problem
 
PHP Code:

new bool:g_died[33]

public 
plugin_init()
{
register_event"DeathMsg"  "on_DeathMsg"  "a"  );
register_event("SendAudio","soundCTWin","a","2=%!MRAD_ctwin");
register_event("SendAudio","soundTWin","a","2=%!MRAD_terwin");
}


public 
on_DeathiVictimiAttackeriWeaponIDiHeadshot )
{
g_died[iVictim] = true
}

public 
soundCTWin() 
{
checkAlive("CT")
}

public 
soundTWin() 
{
checkAlive("TERRORIST")
}

checkAlive(const team[])
{

    new 
players[32], playerNumbool:g_event true
    get_players
(playersplayerNum"e"team)
    
    for (new 
0playerNumi++)
    {
        if (!
is_user_alive(players[i]) && g_died[players[i]])
        {
            
g_event false

            
break
        }
    }

    for (new 
6<= get_maxplayers(); i++)
        if (
g_event && is_user_connected(i))
            
set_task(1.5"doevent"team[0])
    
    return 
1


sometimes it works like it should but sometimes it doesn't, and sets task "doevent" even if players from both team died but it should only if all players from team checked by checkAlive() are alive :shock:

hleV 04-06-2009 13:13

Re: check alive players from a team problem
 
Code:
public on_Death( iVictim, iAttacker, iWeaponID, iHeadshot ) { g_died[iVictim] = true }
:arrow:
Code:
public on_Death() { g_died[read_data(2)] = true }

SnoW 04-06-2009 13:15

Re: check alive players from a team problem
 
Code:

new players[ 32 ], num = 0;
get_players( players, num, "ae", team );
if( !num )
//No alive players in that team

Code:

for (new i = 6; i <= get_maxplayers(); i++)
I don't understand... Why from 6?

Owyn 04-06-2009 13:18

Re: check alive players from a team problem
 
Quote:

Originally Posted by SnoW (Post 798952)
Code:

new players[ 32 ], num = 0;
get_players( players, num, "ae", team );
if( !num )
//No alive players in that team

Code:

for (new i = 6; i <= get_maxplayers(); i++)
I don't understand... Why from 6?

Quote:

Note: "e" flag can return incorrect results (for cstrike/czero at least).
that's what written in the funcwiki =\

Quote:

Why from 6?
to not let doevent() if less than 6 players on server...



hleV
same thing with your variant

Owyn 04-06-2009 14:57

Re: check alive players from a team problem
 
look, i tried to rewrite it:
PHP Code:

checkAlive(const team[])
{

    new 
players[32], iTotalPlayersibool:g_event true
    get_players
playersiTotalPlayers );
    
    if ( 
equaliteam"CT") )
    {
        for ( 
0iTotalPlayersi++ )
            {            
                if ( !
is_user_alive(i) && cs_get_user_team(i) == )
                    {
                        
g_event false
                        
break
                    }
            }
    }
    
    if ( 
equaliteam"TE") )
    {
        for ( 
0iTotalPlayersi++ )
            {            
                if ( !
is_user_alive(i) && cs_get_user_team(i) == )
                    {
                        
g_event false
                        
break
                    }
            }
    }


    for (new 
6<= get_maxplayers(); i++)
        if (
g_event && is_user_connected(i))
            
set_task(1.5"doevent"team[0])
    
    return 
1


but it crashes server )=

hleV 04-06-2009 15:22

Re: check alive players from a team problem
 
Quote:

Originally Posted by .Owyn. (Post 798955)
hleV
same thing with your variant

It's not variant. Your "variant" was completely wrong.

Owyn 04-06-2009 15:40

Re: check alive players from a team problem
 
it didn't help anyway, btw, why do i get a tag mismatch at
PHP Code:

if ( cs_get_user_team(i) == 

?

IneedHelp 04-06-2009 15:44

Re: check alive players from a team problem
 
try with CS_TEAM_T

Also, you can optimize your checkalive function doing only 1 loop

Owyn 04-06-2009 15:48

Re: check alive players from a team problem
 
Quote:

Originally Posted by IneedHelp (Post 799093)
try with CS_TEAM_T

Also, you can optimize your checkalive function doing only 1 loop

hmm, worked, but i've seen "cs_get_user_team(i) != 1" construction in public rulez plugin and it didn't give tag mismatch O_o

about only 1 loop, doesn't it "break" the loop with my code when it finds dead player in the team?


fysiks 04-06-2009 16:05

Re: check alive players from a team problem
 
Quote:

Originally Posted by .Owyn. (Post 798955)
to not let doevent() if less than 6 players on server...

If there are 7 players, id = 1,2,3,4,5,6,7, and a couple leave, you may now have players: id = 1,2,5,6,7. So, skipping i=1,2,3,4,5 is NOT what you need to do.

Also, if g_event is true and you have "more than 5" players you will be setting the same task many times nearly simultaneously right?


All times are GMT -4. The time now is 02:18.

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