AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [TF2] Blocking round end when players die on 1 team (https://forums.alliedmods.net/showthread.php?t=303596)

Nanochip 12-14-2017 00:46

[TF2] Blocking round end when players die on 1 team
 
I'm creating an FFA plugin for dodgeball. Have it all working except the player shuffling so that it's genuine free-for-all. Problem is, for example, when 2 players are on red, and 1 is on blu, and the blu guy dies, i need to switch 1 player from red to blu without the round ending.

I've slapped this bit of code everywhere I can think:
PHP Code:

stock bool ChangeClientTeamAlive(int clientint team)
{
    
int currentteam GetClientTeam(client);
    if((
currentteam  == 1) || (currentteam == 0))return false;
    
SetEntProp(clientProp_Send"m_lifeState"2);
    
ChangeClientTeam(clientteam);
    
SetEntProp(clientProp_Send"m_lifeState"0);
    return 
true;


I've put it in player_death event with eventhookmode_pre, teamplay_round_win with eventhookmode_pre, and even in ongameframe(). All of them have the same result where the round ends.

Doing some googling and discording, I came across this outdated round end prevention thing. I am on linux, so this won't work for me. However, dr!fter included the gamedata which has linux in it that I can use with DHooks. Now the question is, how do I get this to properly work with DHooks and not having a crashed server? Is there any other way of getting the round to not end on me? What do.

Nanochip 12-14-2017 01:07

Re: [TF2] Blocking round end when players die on 1 team
 
probably just gonna spawn an invisible bot if i can't find a less shittier solution...

Byte 12-14-2017 01:27

Re: [TF2] Blocking round end when players die on 1 team
 
That game data is out of date which is causing issues I'm guessing.

Try:
Code:

"Games"
{
        "tf"
        {
                "Offsets"
               
                {
                        "SetWinningTeam"
                        {
                                "windows"        "160"
                                "linux"                "161"
                        }
                }
        }
}

Using with dhooks:
PHP Code:

Handle g_hSetWinningTeam null;

public 
void OnPluginStart()
{
  
Handle handle LoadGameConfigFile("yourgamedata.games");
  if (!
handle)
    
SetFailState("RIP");
  
  
int offset GameConfGetOffset(handle"SetWinningTeam");
  
g_hSetWinningTeam DHookCreate(offsetHookType_GameRulesReturnType_VoidThisPointer_IgnoreHook_SetWinningTeam);
  
DHookAddParam(g_hSetWinningTeamHookParamType_Int);
  
DHookAddParam(g_hSetWinningTeamHookParamType_Int);
  
DHookAddParam(g_hSetWinningTeamHookParamType_Bool);
  
DHookAddParam(g_hSetWinningTeamHookParamType_Bool);
  
DHookAddParam(g_hSetWinningTeamHookParamType_Bool);
  
DHookAddParam(g_hSetWinningTeamHookParamType_Bool);
  
  
delete handle;
}

//CTFGameRules::SetWinningTeam(int,int,bool,bool,bool,bool)
public MRESReturn Hook_SetWinningTeam(Handle hParams)
{
  
//Not too sure about last 4 :p
  
int team DHookGetParam(hParams1);
  
int iWinReason DHookGetParam(hParams2);
  
bool bForceMapReset DHookGetParam(hParams3);
  
bool bSwitchTeams DHookGetParam(hParams4);
  
bool bDontAddScore DHookGetParam(hParams5);
  
bool something6 DHookGetParam(hParams6);
  
  
//do stuff here

  //return MRES_Supercede to block team winning
  
  
return MRES_Ignored;



Powerlord 12-14-2017 01:37

Re: [TF2] Blocking round end when players die on 1 team
 
Remember: Events are just notifications of something that has already happened. So, doing something when an event pre-hook fires is already too late to prevent it from happening.

Benoist3012 12-14-2017 08:52

Re: [TF2] Blocking round end when players die on 1 team
 
Quote:

Originally Posted by Byte (Post 2566112)
public MRESReturn Hook_SetWinningTeam(Handle hParams)
{
//Not too sure about last 4 :p
int team = DHookGetParam(hParams, 1);
int iWinReason = DHookGetParam(hParams, 2);
bool bForceMapReset = DHookGetParam(hParams, 3);
bool bSwitchTeams = DHookGetParam(hParams, 4);
bool bDontAddScore = DHookGetParam(hParams, 5);
bool something6 = DHookGetParam(hParams, 6);
}

https://github.com/ValveSoftware/sou...amerules.h#L90

Powerlord 12-14-2017 14:53

Re: [TF2] Blocking round end when players die on 1 team
 
Quote:

Originally Posted by Benoist3012 (Post 2566176)

The last argument appears to be whether this is the final round in a multi-round map.

Or at least I'm assuming that's what it's supposed to do. All it seems to do is use mp_bonusroundtime_final instead of mp_bonusroundtime for the humiliation round.

Nanochip 01-02-2018 09:31

Re: [TF2] Blocking round end when players die on 1 team
 
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?

Nanochip 01-02-2018 10:22

Re: [TF2] Blocking round end when players die on 1 team
 
Derp.

Just fixed it, apparently you need to add the params to the hook even if you aren't going to use them:
PHP Code:

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

    
delete gameFile;




All times are GMT -4. The time now is 08:13.

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