Raised This Month: $ Target: $400
 0% 

last terrorist help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jagged20101
Member
Join Date: Sep 2009
Old 10-05-2009 , 22:42   last terrorist help
Reply With Quote #1

would this work so that only the last terrorist can use my menu:

if( is_user_alive(iPlayerID) && cs_get_user_team(iPlayerID) == CS_TEAM_T && CS_TEAM_T == 1 )

??

I know that says if the player is alive and the player is on the terrorist team, but would that work?

Thanks for all help
jagged20101 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-05-2009 , 23:08   Re: last terrorist help
Reply With Quote #2

Didn't I already make this?

EDIT:
I did once but it was never confirmed as working completely.
__________________

Last edited by fysiks; 10-05-2009 at 23:12.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-05-2009 , 23:08   Re: last terrorist help
Reply With Quote #3

Untested
PHP Code:
//Usage
new iLastT GetLastPlayerCS_TEAM_T );
    
//If iLastT > 0 then there is only one T left and his id is stored in iLastT
if ( iLastT 
{
        
}
//If iLastT = 0 there are either no T's or more than one
else
{
    
}

//the function
public GetLastPlayerCsTeams:Team )
{
    new 
iPlayers32 ] , iNum id iLastT;
    
    
get_playersiPlayers iNum );
    
    for ( new 
iNum i++ )
    {
        
id iPlayers];
        
        if ( 
is_user_aliveid ) && ( cs_get_user_teamid ) == Team ) )
        {
            if ( 
iLastT )
                return 
0;
                
            
iLastT id;
        }
    }
    
    return 
iLastT;

__________________
Bugsy is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 10-05-2009 , 23:11   Re: last terrorist help
Reply With Quote #4

You have to define "Team", you forget it

You can try in stead of "Team" "CS_TEAM_T"
Mxnn is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-05-2009 , 23:14   Re: last terrorist help
Reply With Quote #5

Quote:
Originally Posted by Mxnn View Post
You have to define "Team", you forget it

You can try in stead of "Team" "CS_TEAM_T"
Team is declared in the function declaration. That value is passed as a variable when using the function.
__________________
fysiks is offline
jagged20101
Member
Join Date: Sep 2009
Old 10-06-2009 , 08:24   Re: last terrorist help
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
Untested
PHP Code:
//Usage
new iLastT GetLastPlayerCS_TEAM_T );
 
//If iLastT > 0 then there is only one T left and his id is stored in iLastT
if ( iLastT 
{
 
}
//If iLastT = 0 there are either no T's or more than one
else
{
 
}
 
//the function
public GetLastPlayerCsTeams:Team )
{
    new 
iPlayers32 ] , iNum id iLastT;
 
    
get_playersiPlayers iNum );
 
    for ( new 
iNum i++ )
    {
        
id iPlayers];
 
        if ( 
is_user_aliveid ) && ( cs_get_user_teamid ) == Team ) )
        {
            if ( 
iLastT )
                return 
0;
 
            
iLastT id;
        }
    }
 
    return 
iLastT;


Or this code provided by fysiks would work even better:

PHP Code:
new iPlayer[32], iT;
  
get_players(iPlayersiT"ae""TERRORIST");
    
  if (
iT == && cs_get_user_team(id) == CS_TEAM_T && is_user_alive(id))
  {
   
menu_handler(idmenuitem)
  }
  else
  {
   
client_print(idprint_chat"You cannot use that command.")
  } 
jagged20101 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-06-2009 , 09:01   Re: last terrorist help
Reply With Quote #7

If the function worked properly then that would obviously be the fastest and easiest way. The problem is that passing flags with get_players() does not always return valid results; I tested the function with various flags and got mixed results. On one occassion, passing "ae" to the function would return players as normal (alive,team) then the next day, identical plugin\code, it would always return 0 players even though there were players that matched the passed criteria. The function should not be used with flags if it is not always going to work consistently. This is why I called it with no flags and did the alive\team checking manually.

http://www.amxmodx.org/funcwiki.php?go=func&id=174

Quote:
"We don't really support get_players() with flags anymore. It was a bad idea and if it was our choice, it would have never been added to the original AMX Mod." - BAILOPAN
And that code is incorrect, untested
PHP Code:
new iPlayers[32] , iT;
get_playersiPlayers iT "ae" "TERRORIST" );
    
if ( 
iT == )
{
    
menu_handleriPlayers[0] , menuitem);
}
else
{
    
client_printiPlayers[0] , print_chat "You cannot use that command." );

__________________

Last edited by Bugsy; 10-06-2009 at 09:15.
Bugsy is offline
Old 10-06-2009, 11:12
jagged20101
This message has been deleted by jagged20101. Reason: double posted in 2 different topics, sorry :)
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-06-2009 , 11:36   Re: last terrorist help
Reply With Quote #8

Not fastest, though.
The use of flags slow down the function, a lot. The fastest way would be looping through 1 and get_maxplayers() checking if the user is alive and if the user is in that team. Calling an extra function (get_players in this case) will copy the IDs of the players to your array, and will very likely do the very same checks than my method.
vitorrd is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-06-2009 , 18:51   Re: last terrorist help
Reply With Quote #9

Quote:
Originally Posted by jagged20101 View Post
Or this code provided by fysiks would work even better:

PHP Code:
new iPlayer[32], iT;
  
get_players(iPlayersiT"ae""TERRORIST");
    
  if (
iT == && cs_get_user_team(id) == CS_TEAM_T && is_user_alive(id))
  {
   
menu_handler(idmenuitem)
  }
  else
  {
   
client_print(idprint_chat"You cannot use that command.")
  } 
I didn't write this.
__________________
fysiks is offline
jagged20101
Member
Join Date: Sep 2009
Old 10-07-2009 , 08:19   Re: last terrorist help
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
I didn't write this.
i ment u provided it in this thread, sorry to who was the orginal poster of this, Credit goes out to ya
Thanks again
jagged20101 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 22:41.


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