Raised This Month: $ Target: $400
 0% 

check alive players from a team problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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 #2

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 #3

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