AlliedModders

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

Kellan123 03-20-2014 18:16

asdasd
 
Hey all, if join server then working Terrorits or Counter-Terrorits Team and then i transfered himself to Terrorist or Counter-Terrorits Team then not worked... :cry:

PHP Code:

Code Removed


Baws 03-20-2014 22:10

Re: GetPlayers Bugging
 
i don't really know if this will work but i tried at least.
PHP Code:

public GetPlayers()
{
    
//static terrorists, counter_terrorists
 
    
for(new id 1id <= get_maxplayers(); id++)
    {
        if(
is_user_connected(id) && is_user_alive(id))
        {
            if(
cs_get_user_team(id) == CS_TEAM_T)
            {
                
cs_set_user_team(id, (CS_TEAM_T terrorists++))
                
//terrorists++
            
}
 
            if(
cs_get_user_team(id) == CS_TEAM_CT)
            {
                
cs_set_user_team(id, (CS_TEAM_CT counter_terrorists++))
                
//counter_terrorists++
            
}
        }
    }

    if(
terrorists && counter_terrorists)
    {
        return 
PLUGIN_CONTINUE
    
}
 
    return 
PLUGIN_HANDLED



Blizzard_87 03-20-2014 22:20

Re: GetPlayers Bugging
 
Quote:

Originally Posted by baws (Post 2114046)
i don't really know if this will work but i tried at least.
PHP Code:

public GetPlayers()
{
    
//static terrorists, counter_terrorists
 
    
for(new id 1id <= get_maxplayers(); id++)
    {
        if(
is_user_connected(id) && is_user_alive(id))
        {
            if(
cs_get_user_team(id) == CS_TEAM_T)
            {
                
cs_set_user_team(id, (CS_TEAM_T terrorists++))
                
//terrorists++
            
}
 
            if(
cs_get_user_team(id) == CS_TEAM_CT)
            {
                
cs_set_user_team(id, (CS_TEAM_CT counter_terrorists++))
                
//counter_terrorists++
            
}
        }
    }

    if(
terrorists && counter_terrorists)
    {
        return 
PLUGIN_CONTINUE
    
}
 
    return 
PLUGIN_HANDLED



If you don't know if it will work then you shouldn't try and help all your doing is going to confuse the OP.

fysiks 03-21-2014 02:42

Re: GetPlayers Bugging
 
Never use get_maxplayers() or get_playersnum() in or as part of a for loop. Also, if a user is alive, they are connected (the is_user_alive() check already checks if they are connnected).

Anyways, you should use the get_players() native. This will already give you only players that are connected.

Also, your function doesn't do anything and your description of what you want makes no sense. You need to explain in detail what you are wanting (something that can be understood).

@Baws, wow, that is just horrible. Stop trying to help people when you have no idea of what you are doing.

Kellan123 03-21-2014 16:09

Re: GetPlayers Bugging
 
Quote:

Originally Posted by fysiks (Post 2114086)
Never use get_maxplayers() or get_playersnum() in or as part of a for loop. Also, if a user is alive, they are connected (the is_user_alive() check already checks if they are connnected).

Anyways, you should use the get_players() native. This will already give you only players that are connected.

Also, your function doesn't do anything and your description of what you want makes no sense. You need to explain in detail what you are wanting (something that can be understood).

@Baws, wow, that is just horrible. Stop trying to help people when you have no idea of what you are doing.

shh, its only working bool: no public...

Baws 03-21-2014 17:18

Re: GetPlayers Bugging
 
I at least try to help... Sometimes you guys just ignore topics that's why.
Anyways, i'll stop sorry for confusing you kellan!

fysiks 03-21-2014 18:16

Re: GetPlayers Bugging
 
Quote:

Originally Posted by Kellan123 (Post 2114280)
shh, its only working bool: no public...

What? If you want help, you need to explain in detail what you are wanting.

Quote:

Originally Posted by baws (Post 2114295)
I at least try to help... Sometimes you guys just ignore topics that's why.
Anyways, i'll stop sorry for confusing you kellan!

When you make fundamental mistakes, it is counter-productive. Trying to help is great but you can't just keep posting random code. So, if you are going to try to help when you don't know what you are doing, you should test the code to make sure that it works first.

Baws 03-21-2014 18:43

Re: GetPlayers Bugging
 
Okay thanks man for letting me know.

OnePL 03-22-2014 00:08

Re: GetPlayers Bugging
 
PHP Code:

#include <amxmodx>

#define USE_GETPLAYERS // uncommented - get_players, commented - loop for

public plugin_init() register_clcmd("say /status""clcmd_status");

public 
clcmd_status(id) {
    
client_print(id3"Alive TT: %i, Alive CT: %i, All TT: %i, All CT: %i"GetPlayers(11), GetPlayers(12), GetPlayers(01), GetPlayers(02));
}

#if defined USE_GETPLAYERS

stock GetPlayers(aliveteam) {
    new 
players[32], num;
    
get_players(playersnumalive "aceh" "ceh"team == "TERRORIST" "CT");
    return 
num;
}

#else

stock GetPlayers(aliveteam) {
    static 
maxplmaxpl get_maxplayers();
    for(new 
1<= maxpli++) {
        if(!
is_user_connected(i) || get_user_team(i) != team) continue;
        if(
alive && !is_user_alive(i)) continue;

        
i++;
    }
    return 
i;
}

#endif 


claudiuhks 03-22-2014 12:20

Re: GetPlayers Bugging
 
Regarding your first message, you need to zero your variables before using them. They are declared as static, and they never reset themselves until plugin reloads.

PHP Code:

GetPlayersCount(Team)
{
  static 
Players 0Player 0;

  
Players 0;

  for (
Player 1Player <= get_maxplayers(); Player++)
  {
    if (
is_user_connected(Player) && get_user_team(Player) == Team)
      
Players++;
  }

  return 
Players;




All times are GMT -4. The time now is 05:54.

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