AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_players (https://forums.alliedmods.net/showthread.php?t=340020)

MrPickles 10-17-2022 23:06

get_players
 
hello!, I wanted to know how to use this function to obtain the alive players and that they are from the opposing team

PHP Code:

native get_players(players[MAX_PLAYERS], &num, const flags[] = "", const team[] = ""); 


fysiks 10-17-2022 23:35

Re: get_players
 
Found a few threads in the Scripting Help forum (this one) with a quick search for "get_players team". Here is one that should help. This one talks about the difference between the new and old versions of the function.

Interestingly, I found that the official documentation actually shows an example for getting all players on a team that are also alive (for both versions here and here).

MrPickles 10-18-2022 00:15

Re: get_players
 
Quote:

Originally Posted by fysiks (Post 2791167)
Found a few threads in the Scripting Help forum (this one) with a quick search for "get_players team". Here is one that should help. This one talks about the difference between the new and old versions of the function.

Interestingly, I found that the official documentation actually shows an example for getting all players on a team that are also alive (for both versions here and here).


mm i know this already, but I was hoping to know, how to find the players of the team opposite yours, which team to put in the native, thinking about what will change


Like:

PHP Code:

static Team[16];
get_opposite_teamidTeam15 );

new 
players[g_maxplayers];
static 
num;

get_players(players,num,"be"Team); 

but the question is to make the "get_opposite_team" function

edit: here is the function...

PHP Code:

stock get_opposite_teamClientOpposite[] )
{
       static 
Name[1]; 

       
get_user_teamClientTeam);

       switch(
Team[0])
       {
           case 
'C'// CT
           

                  
Opposite Terrorist
           
}
           case 
'T'// Terrorist
           
{
                  
Opposite CT
           
}
           case 
'A'// i dont know in this one, if the game is in all vs all?
           
{
                  
Opposite All
           
}
       }      



fysiks 10-18-2022 01:04

Re: get_players
 
Use get_user_team() to determine which team the player is on and then you'll know the other team (there are mod-specific versions of get_user_team for Counter-Strike and Day of Defeat IIRC that might be better for clarity if you're playing one of those). Then, you'll know the opposite team.

Psuedocode:
Code:

if team == TeamA then
    TeamB
else
    TeamA

or, just replace "Team" in the get_players() function with the ternary operation:

Code:

get_user_team(id) == TeamA ? "TeamB" : "TeamA"
no need for an extra function unless you're trying to do something fancy with it.

MrPickles 10-18-2022 01:14

Re: get_players
 
Quote:

Originally Posted by fysiks (Post 2791170)
Use get_user_team() to determine which team the player is on and then you'll know the other team (there are mod-specific versions of get_user_team for Counter-Strike and Day of Defeat IIRC that might be better for clarity if you're playing one of those). Then, you'll know the opposite team.

Psuedocode:
Code:

if team == TeamA then
    TeamB
else
    TeamA

or, just replace "Team" in the get_players() function with the ternary operation:

Code:

get_user_team(id) == TeamA ? "TeamB" : "TeamA"
no need for an extra function unless you're trying to do something fancy with it.

Code:

get_user_team(id) == TeamA ? "TeamB" : "TeamA"
in the code ( in get_players ) how goes? is for counter strike

fysiks 10-18-2022 01:24

Re: get_players
 
Based on one of the threads that I found, the strings you use are "TERRORIST" or "CT". I don't normally play Counter-Strike but I believe that the values returned from get_user_team() are either 1 or 2 for the aforementioned team names, respectively.

However, if it's specifically for Counter-Strike, you should probably use cs_get_user_team() and then you can use the CsTeams enum value to check with. It would end up like this:

Code:

cs_get_user_team(id) == CS_TEAM_T ? "CT" : "TERRORIST"
As I said before, this would just replace the "Team" variable in get_players().

Napoleon_be 10-22-2022 00:34

Re: get_players
 
Don't look to much at this one, i don't think it's recommended doing it this way, but if it works, it works in my opinion (if it doesn't have significant negative effects on the server).

Two things that might be helpful for you.

Get enemy players.

Spoiler



Get Alive Team Players.


Spoiler


All these things are untested, but should do their job, except for the first one, that might just be a no-go by the amxmodx communicty.

If you need more info on what i did, feel free to ask, but i feel like it's pretty common sense.

fysiks 10-22-2022 01:49

Re: get_players
 
Quote:

Originally Posted by Napoleon_be (Post 2791347)
Don't look to much at this one, i don't think it's recommended doing it this way, but if it works, it works in my opinion (if it doesn't have significant negative effects on the server).

Two things that might be helpful for you.

Get enemy players.

Spoiler



Get Alive Team Players.


Spoiler


All these things are untested, but should do their job, except for the first one, that might just be a no-go by the amxmodx communicty.

If you need more info on what i did, feel free to ask, but i feel like it's pretty common sense.

Neither of these make any sense. Simply use get_players() with team argument determined by the check that I posted. It's actually quite simple, no loops necessary.

Napoleon_be 10-23-2022 06:56

Re: get_players
 
Really depends on what the player wants,. Could be done in different ways .Your vision might be wrong about it might. Although i know what you're referring to.

MrPickles 10-23-2022 16:48

Re: get_players
 
Quote:

Originally Posted by Napoleon_be (Post 2791347)
Don't look to much at this one, i don't think it's recommended doing it this way, but if it works, it works in my opinion (if it doesn't have significant negative effects on the server).

Two things that might be helpful for you.

Get enemy players.

Spoiler



Get Alive Team Players.


Spoiler


All these things are untested, but should do their job, except for the first one, that might just be a no-go by the amxmodx communicty.

If you need more info on what i did, feel free to ask, but i feel like it's pretty common sense.


Spoiler



Get Alive Team Players.


getting my team in a loop 0_0, its really unnecesary..


===>

PHP Code:

get_enemy_players(id)
{
    new 
iPlayers[33], iNumiEnemiesMyTeam;
    
get_players(iPlayersiNum"a" );

       
MyTeam get_user_team(id);

    for(new 
iiNumiNum)
    {
        if(
MyTeam != get_user_team(iPlayers[i])
            
iEnemies++
    }
    return 
iEnemies;




All times are GMT -4. The time now is 15:40.

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