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

[TF2] CP_ maps ending on round time, instead of map time when map time is over


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
heavyisgps
Member
Join Date: Aug 2018
Old 11-07-2019 , 17:17   [TF2] CP_ maps ending on round time, instead of map time when map time is over
Reply With Quote #1

Hi. I don't think TF2's handling of rounds is that great when it comes to 5CP and attack defense.

I'm trying to make a plugin that works like this:

If it's a CP_ map the plugin runs, if not , it doesn't run.

When 60 seconds remains of maptime, it sets mp_timelimit to "" (infinite) and the mp_maxrounds to +1 of the total rounds played.

Right now I'm not sure what it's called what I'm looking for. I also haven't been able to figure out how to get the long value from the "tf_map_time_remaining" hook.

Below is the code so far.

Code:
#include <sourcemod>
#include <tf2>

int RoundCount = 0;
char mapname[80];

public void OnMapStart(){

	GetCurrentMap(mapname, 80);
	RoundCount = 0;
	


public void OnPluginStart(){


//Not sure how/where to make the plugin terminate if the map doesn't start with a cp_

		if (StrContains(mapname, "cp_", false) != -1) //if the string doesn't contain cp_
	{
		return Plugin_Handled;	
		
	}
	else{
	HookEvent("tf_map_time_remaining", Event_Map_Time_Remaining);

	HookEvent("teamplay_round_start", Event_RoundStart); 
	}
}

public Action FixTime() //Does the server commands, setting timelimit to blank (infinite) and the maxrounds to 1 more than currently played
{

	ServerCommand("mp_timelimit \"\""); //sets timelimit to blank
	ServerCommand("mp_maxrounds %s", RoundCount+1); //Sets the max rounds to one more than rounds played, so map ends when round is over

	return Plugin_Handled;
}

public Action Event_Map_Time_Remaining(Event event, const char[] name, bool dontBroadcast) //Triggers when a map isn't over and triggers the event that prevents the map from ending on map timer, rather than round timer
{

//not sure of the right method to get the time remaining when there's 60 seconds left. 	tf_map_time_remaining contains a long value called seconds

	new seconds = (event handle).GetInt("seconds");
	
	if (seconds == 60)
	{
		FixTime()
	}

}

public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast) //Counts each round played
{
	RoundCount++;
	
	return Plugin_Continue; 
}
heavyisgps is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 11-07-2019 , 19:50   Re: [TF2] CP_ maps ending on round time, instead of map time when map time is over
Reply With Quote #2

Not tested, but I fixed your code. I left comments to help you understand what I did.

PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

bool g_bIsValidMap;

ConVar g_cvMPTimeLimitg_cvMPMaxRounds;

int g_iOriginalTimeLimitg_iRoundCount;

public 
void OnPluginStart()
{
    
g_cvMPTimeLimit FindConVar("mp_timelimit"); // Cache the convar to a Handle...
    
g_cvMPMaxRounds FindConVar("mp_maxrounds"); // Cache the convar to a Handle...

    
HookEvent("tf_map_time_remaining"vEventMapTimeRemaining);
    
HookEvent("teamplay_round_start"vEventTeamplayRoundStart);

    
g_iOriginalTimeLimit g_cvMPTimeLimit.IntValue// Cache original value of "mp_timelimit"...
}

public 
void OnMapStart()
{
    
char sMap[128];
    
GetCurrentMap(sMapsizeof sMap);

    
// True if mapname starts with "cp_", false otherwise...
    
g_bIsValidMap = (StrContains(sMap"cp_"false) == 0) ? true false;
    
g_iRoundCount 0// Reset round count for each map...
    
g_cvMPTimeLimit.IntValue g_iOriginalTimeLimit// Reset "mp_timelimit" to original value...
}

public 
void OnMapEnd()
{
    
g_iRoundCount 0// Reset round count for each map...
    
g_cvMPTimeLimit.IntValue g_iOriginalTimeLimit// Reset "mp_timelimit" to original value...
}

public 
void vEventMapTimeRemaining(Event event, const char[] namebool dontBroadcast)
{
    if (!
g_bIsValidMap)
    {
        
// Don't do anything if it's not a "cp_" map...
        
return;
    }

    
int iSeconds event.GetInt("seconds");
    if (
iSeconds <= 60// If the time left is 60 seconds or less...
    
{
        if (
g_cvMPTimeLimit != null// Check if the convar was cached properly and is available...
        
{
            
g_cvMPTimeLimit.IntValue 0// 0 = infinite; set "mp_timelimit" to 0...
        
}

        if (
g_cvMPMaxRounds != null// Check if the convar was cached properly and is available...
        
{
            
g_cvMPMaxRounds.IntValue g_iRoundCount 1// Set "mp_maxrounds" to round count + 1...
        
}
    }
}

public 
void vEventTeamplayRoundStart(Event event, const char[] namebool dontBroadcast)
{
    if (!
g_bIsValidMap)
    {
        
// Don't do anything if it's not a "cp_" map...
        
return;
    }

    
g_iRoundCount++; // Increment each round...

Attached Files
File Type: sp Get Plugin or Get Source (tf2_bettercp.sp - 98 views - 2.1 KB)
__________________

Last edited by Psyk0tik; 11-07-2019 at 20:03.
Psyk0tik is offline
heavyisgps
Member
Join Date: Aug 2018
Old 11-08-2019 , 12:20   Re: [TF2] CP_ maps ending on round time, instead of map time when map time is over
Reply With Quote #3

Hi, thanks, but it doesn't work, it never registers that timeleft on the map is 1 min or 60 seconds, so it never triggers the commands to prevent the round from ending before the round timer is over

I also checked and the values it prints from mp_timelimit and mp_maxrounds are incorrect
__________________
Creator of the Hi GPS Balance mod for TF2.

www.higps.no

Last edited by heavyisgps; 11-08-2019 at 12:35.
heavyisgps is offline
Reply



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 11:17.


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