AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help counting of players living (https://forums.alliedmods.net/showthread.php?t=242604)

Toallin 06-21-2014 22:21

Help counting of players living
 
Best to all.

What happens is that I have a problem with the controls of players

PHP Code:

GetAlive()
{
    new 
iAlive
    
    
for(new i<= g_maxplayers; ++i)
        if(
is_user_connected(i) && is_user_alive(i) && cs_get_user_team(i) == CS_TEAM_T)
            
iAlive++;
        
    return 
iAlive;


to put it into a hud if players live shows
PHP Code:

show_hudmessage(0"Alive %d"GetAlive()) 

But when I try to open a menu does not work

PHP Code:

public ShowMenu(id)
{
        if(
GetAlive() = 1)
        {
                new 
menu menu_create("New Menu""CmdNewMenu")

                
menu_additem("Option 1""1")

                
menu_display(idmenu)
        }
        return 
PLUGIN_HANDLED;       


Someone tell me the error
thanks

^SmileY 06-21-2014 22:59

Re: Help counting of players living
 
Try get_players:

PHP Code:

new iPlayers[32],iNum,iPlayer;
    
get_players(iPlayers,iNum,"ach"); // A = Colect Alive Only, C = Skip Bots and H Skipy HLTV
    
    
for(new i;iNum;i++)
    {
        
iPlayer iPlayers[i];
        
        
user_silentkill(iPlayer);
        
client_print(iPlayer,print_chat,"You Are Alive? Soo Die NOW!");
    } 

AND IF YOU NEED

PHP Code:

    new iPlayers[32],iNum;
    
get_players(iPlayers,iNum,"ach"); // A = Colect Alive Only, C = Skip Bots and H Skipy HLTV
    
    
if(iNum == 1)
    {
        
/* MENU HERE */
    



Nextra 06-22-2014 08:10

Re: Help counting of players living
 
Your GetAlive function looks fine. The only thing is that cs_get_user_team(i) == CS_TEAM_T will ensure that only alive terrorists will be counted.

Quote:

Originally Posted by Toallin (Post 2155361)
PHP Code:

        if(GetAlive() = 1


This can not work, and probably won't even compile. Either this is your problem or you are not showing us the code you are actually using and we therefore can't help you properly.

Toallin 06-22-2014 17:36

Re: Help counting of players living
 
Thanks Smiley but I use iNum variable globally?
I just want to restrict certain features and menus depending on the players who are alive.

georgik57 06-22-2014 17:38

Re: Help counting of players living
 
You just need to change

Code:
if (GetAlive() = 1)

to

Code:
if (GetAlive() == 1)

Also you don't need to check for connected if you're checking for alive if I'm not wrong.

Flick3rR 06-22-2014 17:38

Re: Help counting of players living
 
So you want something to be done for alive players, and other thing to be done for dead players?
If so, the best way you can use is get_players and flag "a" for alive players, and flag "b" for dead players. Loop trough the number of players got, and do the thing.

Toallin 06-22-2014 17:45

Re: Help counting of players living
 
Thanks I understand.


All times are GMT -4. The time now is 21:14.

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