Raised This Month: $32 Target: $400
 8% 

last alive player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 03-22-2020 , 09:55   last alive player
Reply With Quote #1

how to find the last alive CT? does it seems good?

PHP Code:
public DeathMsgEvent(){
    
    for(new 
1<= g_maxplayersi++)
    {
        if(
is_user_connected(i) && is_user_alive(i) && cs_get_user_team(i) == CS_TEAM_CT)
        {
            
g_lastman i;
            new 
szName[32]
            
get_user_name(iszName31)
            
set_hudmessage(0150255, -1.00.1501.05.00.10.1, -1)
            
show_hudmessage(i"%s is the last ct alive."szName)
            
extra_weapon_menu(i
            return;
        } 
    }  
    
}

public 
extra_weapon_menu(i)
{
bla bla

__________________
a simple act of caring creates an endless ripple.

Last edited by Nutu_; 03-22-2020 at 09:56.
Nutu_ is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-22-2020 , 10:19   Re: last alive player
Reply With Quote #2

Not really.

Code:
new iPlayers[32], iPnum get_players(iPlayers, iPnum, "ae", "CT") if(iPnum == 1) {     new iLastCT = iPlayers[0] }
__________________

Last edited by OciXCrom; 03-22-2020 at 10:19.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-22-2020 , 12:45   Re: last alive player
Reply With Quote #3

Here's OciXCrom's code in a function. This will return the player id of the last alive CT. If there are more than 1 alive CT's, or no alive CT's, it will return 0.

PHP Code:
LastAliveCT()
{
    new 
iPlayers32 ] , iPnum;
    
get_playersiPlayers iPnum "ae" "CT" );
    
    return ( 
iPnum == ) ? iPlayers] : 0;

__________________
Bugsy is offline
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 03-23-2020 , 16:52   Re: last alive player
Reply With Quote #4

i also find it before
PHP Code:
public Event_DeathMsg() 

    
set_task(0.1,"check_alive"0
}

public 
check_alive() 

    if(
fnGetAliveCt() == 1
    { 
        for( new 
1<= g_Playersi++ )  
        {  
            if (
is_user_alive(i) && cs_get_user_team(i) == CS_TEAM_CT)  
            { 
                new 
szName[32]
                
get_user_name(iszName31)
                
extra_weapon_menu(i)
                
client_print(0print_center"%s is the last survivor"i)
            } 
        }  
    } 

fnGetAliveCt() 

    static 
iAliveid 
    iAlive 

    
    
for (id 1id <= g_Playersid++) 
    { 
        if (
is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_CT
            
iAlive++ 
    } 
    return 
iAlive

how am i supposed to make this to work only once, it gives the extra_weapon_menu to every player that have killed someone, I want this to gives only once, to the last CT alive, if there respawns a new CT and there would be 2 CT's, and someone got killed, not to show anymore.. thanks
__________________
a simple act of caring creates an endless ripple.
Nutu_ is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-23-2020 , 21:28   Re: last alive player
Reply With Quote #5

Try this
PHP Code:
public Event_DeathMsg() 

    
//set_task( 0.1 , "check_alive" ) 
    
check_alive();
}

public 
check_alive() 

    new 
iLastCT LastAliveCT();
    
    if ( 
iLastCT 
    { 
        new 
szName[32]
        
get_user_name(iLastCTszNamecharsmax(szName) );
        
extra_weapon_menu(iLastCT)
        
client_print(0print_center"%s is the last survivor"szName)
    } 


LastAliveCT()
{
    new 
iPlayers32 ] , iPnum;
    
get_playersiPlayers iPnum "ae" "CT" );
    
    return ( 
iPnum == ) ? iPlayers] : 0;

__________________
Bugsy is offline
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 03-24-2020 , 15:16   Re: last alive player
Reply With Quote #6

Bugsy, it works, it only shows the menu when you're last CT but the problem is, it shows every time you make a kill, you kill someone, not only once, i would like to appear that only once.
__________________
a simple act of caring creates an endless ripple.
Nutu_ is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 03-24-2020 , 15:28   Re: last alive player
Reply With Quote #7

declare a new bool, set it to true when menu has opened, set to false when new round begins.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 03-24-2020 , 18:15   Re: last alive player
Reply With Quote #8

alright, i was just look through some plugins about that bool
PHP Code:
new bool:hasOpened[33] = false

public newround()
{
    
hasOpened[id] = false
}

public 
check_alive() 

    new 
iLastCT LastAliveCT();
    
    if ( 
iLastCT 
    { 
        new 
szName[32]
        
get_user_name(iLastCTszNamecharsmax(szName) );
        
extra_weapon_menu(iLastCT)
        
client_print(0print_center"%s is the last survivor"szName)
        
hasOpened[id] = true
    


but how would i declare that the menu has been opened? or will work this way? (i cant test right now)
__________________
a simple act of caring creates an endless ripple.

Last edited by Nutu_; 03-24-2020 at 18:15.
Nutu_ is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-24-2020 , 18:20   Re: last alive player
Reply With Quote #9

You don't need to use this bool at a player level, since there will ever only be 1 last CT per round.
PHP Code:
new bool:hasOpened

public newround()
{
    
hasOpened false
}

public 
check_alive() 

    if ( !
hasOpened )
    {
        new 
iLastCT LastAliveCT();
        
        if ( 
iLastCT 
        { 
            new 
szName[32]
            
get_user_name(iLastCTszNamecharsmax(szName) );
            
extra_weapon_menu(iLastCT)
            
client_print(0print_center"%s is the last survivor"szName)
            
hasOpened true
        

    }

__________________
Bugsy is offline
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 03-25-2020 , 14:52   Re: last alive player
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
You don't need to use this bool at a player level, since there will ever only be 1 last CT per round.
PHP Code:
new bool:hasOpened

public newround()
{
    
hasOpened false
}

public 
check_alive() 

    if ( !
hasOpened )
    {
        new 
iLastCT LastAliveCT();
        
        if ( 
iLastCT 
        { 
            new 
szName[32]
            
get_user_name(iLastCTszNamecharsmax(szName) );
            
extra_weapon_menu(iLastCT)
            
client_print(0print_center"%s is the last survivor"szName)
            
hasOpened true
        

    }

thank you, works! +karma
__________________
a simple act of caring creates an endless ripple.
Nutu_ 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 17:07.


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