PHP Code:
/*
* Extend Round Time Plugin.
* by: shanapu
* https://github.com/shanapu/
*
* Copyright (C) 2016-2018 Thomas Schmidt (shanapu)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
STARTUP
******************************************************************************/
// Includes
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
// Compiler Options
#pragma semicolon 1
#pragma newdecls required
// Console Variables
ConVar gc_bExtend;
ConVar gc_iExtendLimit;
ConVar gc_sCustomCommandExtend;
// Extern Convars
//ConVar g_iMPRoundTime;
// Integers
int g_iExtendNumber[MAXPLAYERS+1];
public Plugin myinfo = {
name = "Extend round time",
author = "shanapu",
description = "Admins can extend round time",
version = "1.3",
url = "https://github.com/shanapu"
};
// Start
public void OnPluginStart()
{
// Client commands
RegConsoleCmd("sm_extend", Command_ExtendRoundTime, "Allows the admins to extend the roundtime");
// AutoExecConfig
gc_bExtend = CreateConVar("sm_extend_plugin", "1", "0 - disabled, 1 - Allows the admin to extend the roundtime", _, true, 0.0, true, 1.0);
gc_iExtendLimit = CreateConVar("sm_extend_limit", "2", "How many time a admin can extend the round?", _, true, 1.0);
gc_sCustomCommandExtend = CreateConVar("sm_cmds_extend", "extendtime, moretime", "Set your custom chat commands for extend time.(!extend (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands))");
// Hooks
HookEvent("round_start", ExtendTime_Event_RoundStart);
}
/******************************************************************************
COMMANDS
******************************************************************************/
public Action Command_ExtendRoundTime(int client, int args)
{
if (gc_bExtend.BoolValue)
{
if (CheckCommandAccess(client, "extend_access", ADMFLAG_BAN, false))
{
if (g_iExtendNumber[client] > 0)
{
Menu menu = new Menu(Handler_ExtendRoundTime);
menu.SetTitle("Extend Time");
menu.AddItem("120", "2 Minutes");
menu.AddItem("180", "3 Minutes");
menu.AddItem("300", "5 Minutes");
menu.ExitBackButton = true;
menu.ExitButton = true;
menu.Display(client, 20);
}
else ReplyToCommand(client, "You already extended the round %i times", gc_iExtendLimit.IntValue);
}
else ReplyToCommand(client, "No access to this command");
}
return Plugin_Handled;
}
/******************************************************************************
EVENTS
******************************************************************************/
public void ExtendTime_Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i))
continue;
g_iExtendNumber[i] = gc_iExtendLimit.IntValue;
}
}
/******************************************************************************
FUNCTIONS
******************************************************************************/
public Action ExtendTime(int client, int args)
{
GameRules_SetProp("m_iRoundTime", GameRules_GetProp("m_iRoundTime", 4, 0) + args, 4, 0, true);
int extendminute = (args/60);
PrintToChatAll("%N extended the round for %i minutes", client, extendminute);
return Plugin_Handled;
}
/******************************************************************************
MENUS
******************************************************************************/
public int Handler_ExtendRoundTime(Menu menu, MenuAction action, int client, int selection)
{
if (action == MenuAction_Select)
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
if (strcmp(info, "120") == 0)
{
ExtendTime(client, 120);
}
else if (strcmp(info, "180") == 0)
{
ExtendTime(client, 180);
}
else if (strcmp(info, "300") == 0)
{
ExtendTime(client, 300);
}
g_iExtendNumber[client]--;
}
else if (action == MenuAction_Cancel)
{
delete menu;
}
else if (action == MenuAction_End)
{
delete menu;
}
}
/******************************************************************************
FORWARDS LISTENING
******************************************************************************/
public void OnConfigsExecuted()
{
// Set custom Commands
int iCount = 0;
char sCommands[128], sCommandsL[12][32], sCommand[32];
// extend time
gc_sCustomCommandExtend.GetString(sCommands, sizeof(sCommands));
ReplaceString(sCommands, sizeof(sCommands), " ", "");
iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
for (int i = 0; i < iCount; i++)
{
Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
if (GetCommandFlags(sCommand) == INVALID_FCVAR_FLAGS) // if command not already exist
RegConsoleCmd(sCommand, Command_ExtendRoundTime, "Allows admin to extend the roundtime");
}
}