Raised This Month: $ Target: $400
 0% 

check alive players from a team problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Owyn
Veteran Member
Join Date: Nov 2007
Old 04-06-2009 , 13:07   check alive players from a team problem
Reply With Quote #1

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
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-06-2009 , 13:13   Re: check alive players from a team problem
Reply With Quote #2

Code:
public on_Death( iVictim, iAttacker, iWeaponID, iHeadshot ) { g_died[iVictim] = true }

Code:
public on_Death() { g_died[read_data(2)] = true }
__________________
hleV is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 04-06-2009 , 13:15   Re: check alive players from a team problem
Reply With Quote #3

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?
SnoW is offline
Send a message via MSN to SnoW
Owyn
Veteran Member
Join Date: Nov 2007
Old 04-06-2009 , 13:18   Re: check alive players from a team problem
Reply With Quote #4

Quote:
Originally Posted by SnoW View Post
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
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.

Last edited by Owyn; 04-06-2009 at 13:40.
Owyn is offline
Send a message via ICQ to Owyn
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-06-2009 , 15:22   Re: check alive players from a team problem
Reply With Quote #5

Quote:
Originally Posted by .Owyn. View Post
hleV
same thing with your variant
It's not variant. Your "variant" was completely wrong.
__________________
hleV is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-06-2009 , 16:05   Re: check alive players from a team problem
Reply With Quote #6

Quote:
Originally Posted by .Owyn. View Post
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?
__________________
fysiks is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-07-2009 , 04:47   Re: check alive players from a team problem
Reply With Quote #7

PHP Code:
#include <amxmodx>
#include <hamsandwich>
 
#define MIN_PLAYERS 6
 
#define TASK_EVENT 2591
 
#define SPEC 0
#define T 1
#define CT 2
 
new iTeam[33] = {0, ...}, bool:bAlive[33] = {false, ...}, g_iMaxPlayers 0g_iCurPlayers 0
 
public plugin_init()
{
       
register_event("DeathMsg""onDeath""a")
       
register_event("SendAudio","soundCTWin","a","2=%!MRAD_ctwin")
       
register_event("SendAudio","soundTWin","a","2=%!MRAD_terwin")
       
RegisterHam(Ham_Spawn"player""playerSpawn"1)
}
 
public 
playerSpawn(id)
{
       if(!
is_user_alive(id))
              return 
PLUGIN_CONTINUE
 
       bAlive
[id] = true
 
       
switch(get_user_team(id))
       {
              case 
0,3iTeam[id] = SPEC
              
case 1iTeam[id] = T
              
case 2iTeam[id] = CT
       
}
}
 
public 
client_connect(id)
{
       
iTeam[id] = 0
       bAlive
[id] = false
       g_iCurPlayers
++
}
 
public 
client_disconnect(id)
{
       
iTeam[id] = 0
       bAlive
[id] = false
       g_iCurPlayers
--
}
 
public 
onDeath() bAlive[read_data(2)] = false
 
public soundCTWin() checkAlive(CT)
 
public 
soundTWin() checkAlive(T)
 
public 
checkAlive(team)
{
       if(
g_iCurPlayers MIN_PLAYERS)
              return
 
       new 
ibool:event true
 
       
for(1<= g_iMaxPlayersi++)
       {
              if(
iTeam[i] != team || bAlive[i])
                     continue
 
              
event false
              
break
       }
 
       if(
event)
              
set_task(0.5"doEvent"team+TASK_EVENT)
 
       return 
PLUGIN_CONTINUE
}
 
public 
doEvent(team)
{
       
team -= TASK_EVENT
       
// ...

It could be done without the for() but w/e also dunno if it works
__________________
Hunter-Digital is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 04-07-2009 , 05:40   Re: check alive players from a team problem
Reply With Quote #8

The SPEC define is useless, just don't touch Team[] and it will be 0.
And checking his team every spawn is a bad way, you should just check it once when the player joins a team, and not all the time.

And you don't need to reset Team[] for a player, hopefully as soon as he gets into the server he joins a team and thus updating Team[].
Also, you don't need to reset bAlive[] on both client_disconnect() and client_connect(). One of them should be enough.

One last thing - I suggest being consistent about return types and returning HAM_* in Ham forwards, FM_* in Fakemeta forwards, etc.
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ

Last edited by Dores; 04-07-2009 at 19:27.
Dores is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 04-06-2009 , 14:57   Re: check alive players from a team problem
Reply With Quote #9

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 )=
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
Old 04-06-2009, 15:15
vato loco [GE-S]
This message has been deleted by vato loco [GE-S]. Reason: ...
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 02:18.


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