PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0.4"
public Plugin:myinfo =
{
name = "HANSE WT-Restrict",
author = "red!",
description = "Provides winning team restrictions",
version = PLUGIN_VERSION,
url = "http://www.hanse-clan.de"
};
/* Handles to convars used by plugin */
new Handle:sm_wt_restrict_enable;
new Handle:sm_restrict_cmd_t;
new Handle:sm_restrict_cmd_ct;
new Handle:sm_unrestrict_cmd_t;
new Handle:sm_unrestrict_cmd_ct;
new Handle:sm_restrict_cmd_unrestrict_all;
new Handle:sm_wt_offset;
new Handle:sm_wt_offset_only;
public OnPluginStart()
{
// connect to the setting convars
sm_wt_restrict_enable = FindConVar("sm_wt_restrict_enable");
if (sm_wt_restrict_enable==INVALID_HANDLE) {
CreateConVar("sm_wt_restrict_enable", "1");
sm_wt_restrict_enable = FindConVar("sm_wt_restrict_enable");
}
sm_wt_offset = FindConVar("sm_wt_offset");
if (sm_wt_offset==INVALID_HANDLE) {
CreateConVar("sm_wt_offset", "0");
sm_wt_offset = FindConVar("sm_wt_offset");
}
sm_wt_offset_only = FindConVar("sm_wt_offset_only");
if (sm_wt_offset==INVALID_HANDLE) {
CreateConVar("sm_wt_offset_only", "0");
sm_wt_offset = FindConVar("sm_wt_offset_only");
}
sm_restrict_cmd_t = FindConVar("sm_restrict_cmd_t");
if (sm_restrict_cmd_t==INVALID_HANDLE) {
CreateConVar("sm_restrict_cmd_t", "");
sm_restrict_cmd_t = FindConVar("sm_restrict_cmd_t");
}
sm_restrict_cmd_ct = FindConVar("sm_restrict_cmd_ct");
if (sm_restrict_cmd_ct==INVALID_HANDLE) {
CreateConVar("sm_restrict_cmd_ct", "");
sm_restrict_cmd_ct = FindConVar("sm_restrict_cmd_ct");
}
sm_unrestrict_cmd_t = FindConVar("sm_unrestrict_cmd_t");
if (sm_unrestrict_cmd_t==INVALID_HANDLE) {
CreateConVar("sm_unrestrict_cmd_t", "");
sm_unrestrict_cmd_t = FindConVar("sm_unrestrict_cmd_t");
}
sm_unrestrict_cmd_ct = FindConVar("sm_unrestrict_cmd_ct");
if (sm_unrestrict_cmd_ct==INVALID_HANDLE) {
CreateConVar("sm_unrestrict_cmd_ct", "");
sm_unrestrict_cmd_ct = FindConVar("sm_unrestrict_cmd_ct");
}
sm_restrict_cmd_unrestrict_all = FindConVar("sm_restrict_cmd_unrestrict_all");
if (sm_restrict_cmd_unrestrict_all==INVALID_HANDLE) {
CreateConVar("sm_restrict_cmd_unrestrict_all", "");
sm_restrict_cmd_unrestrict_all = FindConVar("sm_restrict_cmd_unrestrict_all");
}
CreateConVar("wt_restrict_version", PLUGIN_VERSION, "Version of [HANSE] WT-Restrict", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_SPONLY);
// hook round start & round end events
//HookEvent("round_end",OnRoundEnd,EventHookMode_Post);
HookEvent("round_start",OnRoundStart);
RegConsoleCmd("sm_wtrestrict_status", debugPrint);
CreateTimer(5.0, OnRoundEnd, _, TIMER_REPEAT);
}
new bool:restricted_T=false;
new bool:restricted_CT=false;
new bool:bdebug=false;
public Action:debugPrint(client, args)
{
//PrintToConsole(client,"[wt_restrict] ct score %d, restriction %d, t score %d, restriction %d", GetTeamScore(TEAM_CT), restricted_CT, GetTeamScore(TEAM_T), restricted_T);
return Plugin_Handled;
}
set_T_restriction(bool:restrict)
{
new String:cmd[256];
if (restricted_T!=restrict)
{
restricted_T=restrict;
if (restrict)
{
// call sm_restrict_cmd_t
GetConVarString(sm_restrict_cmd_t, cmd, 128);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
else
{
// call sm_unrestrict_cmd_t
GetConVarString(sm_unrestrict_cmd_t, cmd, 128);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
}
}
set_CT_restriction(bool:restrict)
{
new String:cmd[256];
if (restricted_CT!=restrict)
{
restricted_CT=restrict;
if (restrict)
{
// call sm_restrict_cmd_ct
GetConVarString(sm_restrict_cmd_ct, cmd, 256);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
else
{
// call sm_unrestrict_cmd_ct
GetConVarString(sm_unrestrict_cmd_ct, cmd, 256);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
}
}
#define TEAM_T 2
#define TEAM_CT 3
public Action:OnRoundEnd(Handle: timer)
{
// break if plugin is disabled
if (GetConVarInt(sm_wt_restrict_enable)==0)
{
set_CT_restriction(false);
set_T_restriction(false);
return;
}
// evaluate teams to actiavte restrictions for
if(GetTeamScore(TEAM_T) > GetTeamScore(TEAM_CT))
{//Terrorists are in the lead
if((GetTeamScore(TEAM_T) - GetTeamScore(TEAM_CT)) >= GetConVarInt(sm_wt_offset))
{//Terrorirsts need to be restricted
set_CT_restriction(false);
set_T_restriction(true);
}
else if(GetConVarInt(sm_wt_offset_only) != 0)
{//Terrorists no longer need restriction
set_T_restriction(false);
}
}
else if(GetTeamScore(TEAM_CT) > GetTeamScore(TEAM_T))
{//CT team is in the lead
if((GetTeamScore(TEAM_CT) - GetTeamScore(TEAM_T)) >= GetConVarInt(sm_wt_offset))
{//CT team needs to be restricted
set_CT_restriction(true);
set_T_restriction(false);
}
else if(GetConVarInt(sm_wt_offset_only) != 0)
{//CT team no longer needs restriction
set_CT_restriction(false);
}
}
else//Even game
{
set_CT_restriction(false);
set_T_restriction(false);
}
if(bdebug)
PrintToChatAll("exit");
}
public OnRoundStart(Handle: event , const String: name[] , bool: dontBroadcast)
{
// announcements
if(restricted_T)
{
PrintToChatAll("\x04Terrorists: Awp/Auto Restriction = 0");
PrintToChatAll("\x04Counter-Terrorists: Awp/Auto Restriction = 2");
}
else if(restricted_CT)
{
PrintToChatAll("\x04Terrorists: Awp/Auto Restriction = 2");
PrintToChatAll("\x04Counter-Terrorists: Awp/Auto Restriction = 0");
}
else
{
PrintToChatAll("\x04Terrorists: Awp/Auto Restriction = 2");
PrintToChatAll("\x04Counter-Terrorists: Awp/Auto Restriction = 2");
}
}
public OnMapStart()
{
set_CT_restriction(false);
set_T_restriction(false);
//new String:cmd[256];
//GetConVarString(sm_restrict_cmd_unrestrict_all, cmd, 256);
//ServerCommand("%s", cmd);
}
I don't fully understand why this mod was broken, but I've fixed it with a timer. I spent 5 hours and didn't fix anything, I ended up replacing the OnRoundEnd event hook with a timer of the same name.
For some strange reason it was rarely completing the call "onroundend" which resulted in one debug print actually being printed, but no others.
I was able to figure out it happened usually on a function call or during a "new" identifier
Anyways here is the code, and here is the .smx
It is hardcoded for every 5 seconds. If you don't want it to run its checks every 5 seconds just open up the source and find 5.0 change it and put it into the compiler on the sourcemod homepage.
Edit: Removed inconsistencies in colour formatting and removed some debugging information.
I forgot to mention earlier that I have also hardcoded the announcements to say awp and auto restricted to 2 or 0 depending on the winning team or if the teams are even. I just didn't care for the regular ones, they are still there but commented. "//ServerCommand("%s", cmd);" remove the //
My announcements are in OnRoundStart