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

Solved [TF2] Blocking round end when players die on 1 team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nanochip
Senior Member
Join Date: Jan 2014
Old 12-14-2017 , 00:46   [TF2] Blocking round end when players die on 1 team
Reply With Quote #1

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.
__________________

Last edited by Nanochip; 01-02-2018 at 11:28.
Nanochip is offline
Nanochip
Senior Member
Join Date: Jan 2014
Old 12-14-2017 , 01:07   Re: [TF2] Blocking round end when players die on 1 team
Reply With Quote #2

probably just gonna spawn an invisible bot if i can't find a less shittier solution...
__________________
Nanochip is offline
Byte
Senior Member
Join Date: Jun 2010
Location: 📦 CCSPlayer
Old 12-14-2017 , 01:27   Re: [TF2] Blocking round end when players die on 1 team
Reply With Quote #3

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;

__________________
STEAM: /id/invexbyte | Github: Mo Beigi | Discord: Byte#0017
Community: Invex Gaming | My Plugins: Click Me!


Last edited by Byte; 12-14-2017 at 01:54.
Byte is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-14-2017 , 01:37   Re: [TF2] Blocking round end when players die on 1 team
Reply With Quote #4

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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-14-2017 at 01:38.
Powerlord is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 12-14-2017 , 08:52   Re: [TF2] Blocking round end when players die on 1 team
Reply With Quote #5

Quote:
Originally Posted by Byte View Post
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
__________________
Benoist3012 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-14-2017 , 14:53   Re: [TF2] Blocking round end when players die on 1 team
Reply With Quote #6

Quote:
Originally Posted by Benoist3012 View Post
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.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
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
Nanochip
Senior Member
Join Date: Jan 2014
Old 01-02-2018 , 10:22   Re: [TF2] Blocking round end when players die on 1 team
Reply With Quote #8

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;

__________________
Nanochip 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 08:09.


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