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

Data is persistent over map changes, when I don't want it to be


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yellowblood
Member
Join Date: May 2010
Old 12-08-2011 , 15:04   Data is persistent over map changes, when I don't want it to be
Reply With Quote #1

Hey,

I have a simple TF2 plugins that deals with balancing teams.

Sadly, it keeps some data between maps and it causes some bugs. In other words, the method that clears this data isn't called -
Code:
public OnMapStart()
{
	if (_enabled) Enable();
}

public Enable()
{
	ServerCommand("mp_autoteambalance 0");
	ServerCommand("mp_teams_unbalance_limit 0");
	
	_isShouldBalance = false;
	_winningTeam = 0;
	_teamWins[TEAM_RED] = 0;
	_teamWins[TEAM_BLUE] = 0;

	for (new i = 0; i < sizeof(_playerKills) ; i++)
	{
		_playerKills[i] = 0;
		_playerTeams[i] = 0;
	}
}
What am I missing? I want the "Enable" method to be called every time a map changes, so the plugin will start fresh.

Thanks
yellowblood is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-08-2011 , 15:14   Re: Data is persistent over map changes, when I don't want it to be
Reply With Quote #2

Something might be wrong with _enabled. Show more code.
__________________

Last edited by McFlurry; 12-08-2011 at 15:14.
McFlurry is offline
Send a message via Skype™ to McFlurry
yellowblood
Member
Join Date: May 2010
Old 12-08-2011 , 19:09   Re: Data is persistent over map changes, when I don't want it to be
Reply With Quote #3

The full plugin is attached.
Attached Files
File Type: sp Get Plugin or Get Source (FewGoodMen.sp - 277 views - 8.1 KB)
yellowblood is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-08-2011 , 20:49   Re: Data is persistent over map changes, when I don't want it to be
Reply With Quote #4

Well, these don't really address the problem you posted, but they're things that will likely get mentioned by a SourceMod approver if you submit it as a new plugin:

1.
PHP Code:
    ServerCommand("mp_autoteambalance 0");
    
ServerCommand("mp_teams_unbalance_limit 0"); 
I'm not sure its a good idea to set cvars using ServerCommand. Use a handle variable, FindConVar (in OnPluginStart), and SetConVarBool instead.

2.
Hook either OnClientDisconnect or OnClientDisconnect_Post, not both. I recommend OnClientDisconnect_Post based on what you're doing.

3.
PHP Code:
#define TEAM_UNASSIGNED 0
#define TEAM_SPEC 1
#define TEAM_RED 2
#define TEAM_BLUE 3 
Use these from #include <tf2> instead:
PHP Code:
TFTeam_Unassigned
TFTeam_Spectator
TFTeam_Red
TFTeam_Blue 
// (yes, Blue... not Blu) 
You can compare them directly without casting, but you may need to cast them to a cell before using them with GetTeamClientCount (i.e. _:TFTeam_Red)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-08-2011 at 21:01.
Powerlord 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 13:42.


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