AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Data is persistent over map changes, when I don't want it to be (https://forums.alliedmods.net/showthread.php?t=173662)

yellowblood 12-08-2011 15:04

Data is persistent over map changes, when I don't want it to be
 
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

McFlurry 12-08-2011 15:14

Re: Data is persistent over map changes, when I don't want it to be
 
Something might be wrong with _enabled. Show more code.

yellowblood 12-08-2011 19:09

Re: Data is persistent over map changes, when I don't want it to be
 
1 Attachment(s)
The full plugin is attached.

Powerlord 12-08-2011 20:49

Re: Data is persistent over map changes, when I don't want it to be
 
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)


All times are GMT -4. The time now is 06:29.

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