Raised This Month: $12 Target: $400
 3% 

Can't teamswap dead players


Post New Thread Reply   
 
Thread Tools Display Modes
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-09-2022 , 13:25   Re: Can't teamswap dead players
Reply With Quote #21

Just for information, Round_End will be called even if the game didn't commence yet.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-09-2022 , 14:24   Re: Can't teamswap dead players
Reply With Quote #22

Quote:
Originally Posted by Natsheh View Post
Just for information, Round_End will be called even if the game didn't commence yet.
Yes, thanks.

So I'm about to give up, but I think it is pretty clear that the issue is with death from the bomb.
This test below works flawlessly, if I type "kill" in chat and then "test", I get transferred.
But if I use any of the hooks it only works if I survive the bomb.

PHP Code:
#include <amxmodx>
#include <cstrike>

public plugin_init()
{
    
//register_logevent("SwapTeams", 2, "1=Round_End") 
    //register_event("SendAudio", "SwapTeams", "a", "2&%!MRAD_terwin")
    //register_event("SendAudio", "SwapTeams", "a", "2&%!MRAD_ctwin")
    
register_clcmd("test""SwapTeams")
}

public 
SwapTeams()
{
    new 
players[32];
    new 
playercount;
    
get_players(playersplayercount"h");
    
    new 
iid
    
for (i=0i<playercounti++)
    {
        
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)
        }
    }


Last edited by GoldNux; 11-09-2022 at 14:24.
GoldNux is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-09-2022 , 15:01   Re: Can't teamswap dead players
Reply With Quote #23

There is definitely an issue with the event.
I have tried hooking win sounds, end round event and target bombed.
Non of them work even with a delay on the function that switches players.

But if I die from the bomb, and call the exact same function from console with a command, it works!

Teh fuck am I doing wrong here!?
It obviously works when you are alive so I don't know what's going on..
I even tested the events and they work, it just does not run the change team correctly.
But how can I do this with a command then!?

Beats me I think I give up.

Any odd idea on a workaround?
Thanks.

edit: I came up with my own horrible solution to the problem, but it actually works:
edit2: I'm an idiot, what if T kill all CTs...

PHP Code:
public newRound()
{
    
set_task(get_cvar_num("mp_c4timer") , "SwapTeams")

It is not great by any means but it beats spending hours testing like this and finding nothing.
At least I got my stuff updated to the latest version so I'm glad for that.
Also thanks for your feedback it has been great.

Last edited by GoldNux; 11-10-2022 at 15:18.
GoldNux is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-09-2022 , 18:54   Re: Can't teamswap dead players
Reply With Quote #24

My suggestion would be to kill the user before changing its team.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-10-2022 , 13:51   Re: Can't teamswap dead players
Reply With Quote #25

Quote:
Originally Posted by Natsheh View Post
My suggestion would be to kill the user before changing its team.
Thanks man, it works now!
This is what it looks like if anyone has the same issue:
PHP Code:
public SwapTeams()
{
    new 
players[32];
    new 
playercount;
    
get_players(playersplayercount"h");
    
    new 
iid
    
for (i=0i<playercounti++)
    {
        
id players[i]
        new 
Float:flFrags
        pev
(idpev_fragsflFrags)
        
set_pev(idpev_frags, ++flFrags)

        
dllfunc(DLLFunc_ClientKillid)
        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)
        }
    }


Last edited by GoldNux; 11-10-2022 at 14:13.
GoldNux is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-10-2022 , 15:16   Re: Can't teamswap dead players
Reply With Quote #26

Quote:
Originally Posted by Natsheh View Post
My suggestion would be to kill the user before changing its team.
I still have one issue:
I'm keeping count on team 1 and team 2 with variables that are gets +1 if ct/t win.
When I kill the players at round_end event the ct or t win is triggered twice so the score count gets fucked up.

I "solved" this by using:

PHP Code:
    register_event("23""Event_WinT""a""1=17""6=-105""7=17")
    
register_logevent("Event_WinCT"3"2=Defused_The_Bomb"); 
That is with bomb explode and defuse event.
But now players have to wait for c4 to go off if all CTs are killed and wont get any points.
Not sure how to solve this without checking when a player dies if he was the last one alive, not very nice way of doing it but these wierd conditions have put me in this spot.

Last edited by GoldNux; 11-10-2022 at 15:19.
GoldNux is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 11-10-2022 , 23:14   Re: Can't teamswap dead players
Reply With Quote #27

Use a boolean and set it true when the round ends and false when round starts. Check if the boolean is already true when doing ++1. It can help avoiding the twice increasement.
I've seen a lot of team swap codes, most of them are inside Furien Mod and all of them uses set_task to swap players teams. I've seen players had this issue before too, so this is what I have on mine, may help you with more efficiency instead of doing tricky ways:

PHP Code:
#include <amxmodx>
#include <cstrike>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new g_iWins[2]

new 
pCvarMinCTWins
new pCvarMinTWins

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
pCvarMinCTWins register_cvar("minct_wins""5")
    
pCvarMinTWins register_cvar("mint_wins""5")
    
    
register_logevent"round_restart_event",   2"0=World triggered""1&Restart_Round_" )
    
    
register_event("SendAudio""EVENT_TWin""a""2&%!MRAD_terwin")
    
register_event("SendAudio""EVENT_CTWin""a""1=0""2=%!MRAD_ctwin");
}

public 
round_restart_event()
{
    
g_iWins[0] = g_iWins[1] = 0
}

public 
EVENT_CTWin() 
{
    
g_iWins[1]++
    if(
g_iWins[1] >= get_pcvar_num(pCvarMinCTWins))
    {
        
g_iWins[1] = 0
        swapTeams
()
    }
}

public 
EVENT_TWin() 
{
    
g_iWins[0]++
    if(
g_iWins[0] >= get_pcvar_num(pCvarMinTWins))
    {
        
g_iWins[0] = 0
        swapTeams
()
    }
}

swapTeams()
{
    new 
Players[32], PlayersNumid;
    
get_players(PlayersPlayersNum"h")
    if(
PlayersNum
    {
        for(new 
iPlayersNumi++) 
        {
            
id Players[i]
            
BeginDelay(id)
        }
    }
}

public 
BeginDelay(id
{
    if(
is_user_connected(id)) 
    {
        switch(
id
        {
            case 
1..7set_task(0.1"BeginTeamSwap"id)
            case 
8..15set_task(0.2"BeginTeamSwap"id)
            case 
16..23set_task(0.3"BeginTeamSwap"id)
            case 
24..32set_task(0.4"BeginTeamSwap"id)
        }
    }
}

public 
BeginTeamSwap(id
{
    if(
is_user_connected(id)) 
    {
        switch(
get_user_team(id)) 
        {
            case 
1cs_set_user_team(idCS_TEAM_CT)
            case 
2cs_set_user_team(idCS_TEAM_T)
        }
    }

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 11-10-2022 at 23:17.
EFFx is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-11-2022 , 17:11   Re: Can't teamswap dead players
Reply With Quote #28

Quote:
Originally Posted by EFFx View Post
Use a boolean and set it true when the round ends and false when round starts. Check if the boolean is already true when doing ++1. It can help avoiding the twice increasement.
I've seen a lot of team swap codes, most of them are inside Furien Mod and all of them uses set_task to swap players teams. I've seen players had this issue before too, so this is what I have on mine, may help you with more efficiency instead of doing tricky ways:
Thanks a ton bro!
It works. <3
GoldNux is offline
Reply


Thread Tools
Display Modes

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 12:08.


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