View Single Post
Nanochip
Senior Member
Join Date: Jan 2014
Old 01-02-2018 , 09:31   Re: [TF2] Blocking round end when players die on 1 team
Reply With Quote #7

Alright, back to this.

I have successfully been able to block the round-end aka "SetWinningTeam" event. However now there are 3 new issues.

Here's the code I have:

PHP Code:
Handle g_hSetWinningTeam;

public 
void OnPluginStart
{
    
Handle gameFile LoadGameConfigFile("tf2.setwinningteam");
    
int offset GameConfGetOffset(gameFile"SetWinningTeam");
    
g_hSetWinningTeam DHookCreate(offsetHookType_GameRulesReturnType_VoidThisPointer_IgnoreHook_SetWinningTeam);
    
delete gameFile;
}

public 
void OnMapStart()
{
    
DHookGamerules(g_hSetWinningTeamfalse);
}

public 
MRESReturn Hook_SetWinningTeam(Handle hParams)
{
    if (
FFAMode)
    {
        if (
GetPlayerCountTeam(2) == && GetPlayerCountTeam(3) > 1)
        {
            return 
MRES_Supercede// Prevent round from ending so we can swap the last player over. (Done in OnGameFrame
        
}
        
        if (
GetPlayerCountTeam(3) == && GetPlayerCountTeam(2) > 1)
        {
            return 
MRES_Supercede;  // Prevent round from ending so we can swap the last player over. (Done in OnGameFrame
        
}
    }
    
    return 
MRES_Ignored;
}

public 
OnGameFrame()
{
    
// This is where it shuffles players around.
    
if (FFAMode)
    {
        
int red GetPlayerCountTeam(2);
        
int blu GetPlayerCountTeam(3);
        
int redDiff red blu;
        
int bluDiff blu red;
        
        if (
redDiff >= 2)
        {
            
int iMoveClient GetRandomPlayerTeam(2);
            
OldTeam[iMoveClient] = GetClientTeam(iMoveClient);
            
ChangeClientTeamAlive(iMoveClient3);
        }
        if (
bluDiff >= 2)
        {
            
int iMoveClient GetRandomPlayerTeam(3);
            
OldTeam[iMoveClient] = GetClientTeam(iMoveClient);
            
ChangeClientTeamAlive(iMoveClient2);
        }

So the 3 issues that now happen is that I'm assuming when hooking gamerules, some wonky shit happens, I'm probably missing something else in the gamerules:
1.) For example, if all of red team dies, it'll say that red team won. And vice versa for blue. This also happens when FFA is disabled.
2.) At the beginning of the round (when counting down), it shuffles the teams around and prints "Teams have been switched."
3.) At the end of the round, once a team has won, it respawns the losing team, (where they hold their hands above their head and you're in third person).

This definitely has to do with the parameters for the SetWinningTeam, however, all I'm doing is preventing the event from happening, so what kind of parameters would I need to use? Teach me how to dhook pls.

Any ideas what I'm missing here to prevent these issues from happening?
__________________

Last edited by Nanochip; 01-02-2018 at 09:35.
Nanochip is offline