AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   last terrorist help (https://forums.alliedmods.net/showthread.php?t=105567)

jagged20101 10-05-2009 22:42

last terrorist help
 
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

fysiks 10-05-2009 23:08

Re: last terrorist help
 
Didn't I already make this?

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

Bugsy 10-05-2009 23:08

Re: last terrorist help
 
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;



Mxnn 10-05-2009 23:11

Re: last terrorist help
 
You have to define "Team", you forget it :D

You can try in stead of "Team" "CS_TEAM_T"

fysiks 10-05-2009 23:14

Re: last terrorist help
 
Quote:

Originally Posted by Mxnn (Post 953690)
You have to define "Team", you forget it :D

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.

jagged20101 10-06-2009 08:24

Re: last terrorist help
 
Quote:

Originally Posted by Bugsy (Post 953682)
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.")
  } 


Bugsy 10-06-2009 09:01

Re: last terrorist help
 
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." );



vitorrd 10-06-2009 11:36

Re: last terrorist help
 
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.

fysiks 10-06-2009 18:51

Re: last terrorist help
 
Quote:

Originally Posted by jagged20101 (Post 953899)
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.

jagged20101 10-07-2009 08:19

Re: last terrorist help
 
Quote:

Originally Posted by fysiks (Post 954403)
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


All times are GMT -4. The time now is 22:41.

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