AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can't teamswap dead players (https://forums.alliedmods.net/showthread.php?t=340256)

GoldNux 11-05-2022 09:39

Can't teamswap dead players
 
It swaps players that are alive but non dead.
Not sure why, I have tried many different ways.

PHP Code:

public SwapTeams()
{
    new 
players[32];
    new 
playercount;
    
get_players(playersplayercount);
    
    new 
i
    
for (i=0i<playercounti++)
    {
        new 
id players[i]
        if (!
is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR)
        {
            
cs_set_user_team(id, (cs_get_user_team(id) == CS_TEAM_T) ? CS_TEAM_CT CS_TEAM_T)
        }
    }



iceeedr 11-05-2022 10:16

Re: Can't teamswap dead players
 
Never faced such problem, what version of amx are you using? Anyway, here are some corrections to your code.

Code:

public SwapTeams()
{
    new players[32];
    new playercount;
    get_players(players, playercount, "h"); // 'h' to not include hltv
   
    new i, id // do not create vars inside a loop
    for (i=0; i<playercount; i++)
    {
        id = players[i]

        if (cs_get_user_team(id) != CS_TEAM_SPECTATOR && cs_get_user_team(id) != CS_TEAM_UNASSIGNED) // You also check if he hasn't chosen any team yet, ie "unassigned".
        {
            cs_set_user_team(id, (cs_get_user_team(id) == CS_TEAM_T) ? CS_TEAM_CT : CS_TEAM_T)
        }
    }
}


GoldNux 11-05-2022 10:23

Re: Can't teamswap dead players
 
Quote:

Originally Posted by iceeedr (Post 2792192)
Never faced such problem, what version of amx are you using? Anyway, here are some corrections to your code...

I use the latest version.
This worked for some reason:
Obviously not pretty..

Thanks for your reply.
I will test the code and try some more.
PHP Code:

public SwapTeams()
{
    new 
players[32];
    new 
playercount;
    
get_players(playersplayercount);
    
    new 
i
    
for (i=0i<playercounti++)
    {
        if (
cs_get_user_team(players[i]) == CS_TEAM_T)
        {
            
cs_set_user_team(players[i], CS_TEAM_CT)
        }
        else if (
cs_get_user_team(players[i]) == CS_TEAM_T)
        {
            
cs_set_user_team(players[i], CS_TEAM_T)
        }
    }



GoldNux 11-05-2022 11:03

Re: Can't teamswap dead players
 
Adding user_silentkill(id) solved this problem for me!
edit: nvm it did not.. wtf

There seems to be something wrong with cs_get_user_team when player is dead.

This works:
cs_set_user_team(id, CS_TEAM_CT)

This does not:
cs_set_user_team(id, (cs_get_user_team(id) == CS_TEAM_T) ? CS_TEAM_CT : CS_TEAM_T)

I printed the value of cs_get_user_team and got: thrun_crash_future
Then I ran it again and it printed: ngelevel_mapname

get_players(players, playercount, "he", "T") Does also not seem to be working properly.
Damn, I'm lost.

For some reason I could use this:
cs_set_user_team(id, (cs_get_user_team(id) == CS_TEAM_T) ? CS_TEAM_CT : CS_TEAM_T)

in a function triggered by the Ham_Killed...

Natsheh 11-06-2022 08:17

Re: Can't teamswap dead players
 
What amxx compiler version are you using?

GoldNux 11-06-2022 09:41

Re: Can't teamswap dead players
 
Quote:

Originally Posted by Natsheh (Post 2792250)
What amxx compiler version are you using?

I installed AMX Mod X Full Installer v1.8.2

Natsheh 11-06-2022 11:24

Re: Can't teamswap dead players
 
That's why you've problems in your plugins because you're using an old compiler probably using compiler version 1.8.1

GoldNux 11-07-2022 11:41

Re: Can't teamswap dead players
 
Quote:

Originally Posted by Natsheh (Post 2792267)
That's why you've problems in your plugins because you're using an old compiler probably using compiler version 1.8.1

I am now using 1.8.3 and it still does not transfer dead players.
I am using the map spawns editor, do you think it might affect my plugin?

GoldNux 11-07-2022 12:02

Re: Can't teamswap dead players
 
I tried this stupid solution but it crashed my server: :down:
I also tried calling the function from:

register_logevent( "SwapAlivePlayers", 2, "1=Round_End" );

Instead of:

register_event("SendAudio", "SwapAlivePlayers", "a", "2&%!MRAD_terwin")
register_event("SendAudio", "SwapAlivePlayers", "a", "2&%!MRAD_ctwin")

Still does not work so seems to be an issue with seting dead players.
Can someone test on their system? :S

PHP Code:

public SwapAlivePlayers()
{
    new 
players[32];
    new 
playercount;
    
get_players(playersplayercount"h");
    
    new 
iid
    
for (i=0i<playercounti++)
    {
        
id players[i];
        new 
playerTeam cs_get_user_team(id);
        if (
playerTeam != CS_TEAM_SPECTATOR && playerTeam != CS_TEAM_UNASSIGNED)
        {
            if (
playerTeam == CS_TEAM_T)
            {
                
engclient_cmd(id"jointeam""2");
                
engclient_cmd(id"joinclass""5");
            }
            else
            {
                
engclient_cmd(id"jointeam""1");
                
engclient_cmd(id"joinclass""5");
            }
        }
    }



Natsheh 11-07-2022 13:51

Re: Can't teamswap dead players
 
use the same amxx compiler version as your amxx mod in your server.
also use the latest amxx version which is 1.10 or 1.9


All times are GMT -4. The time now is 12:23.

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