I am learning the plugin, but my plugin is not working properly at the time of production.
This plugins will be use in my "DangerZone Mode Server", Please help.
Code:
#include <sourcemod>
#include <cstrike>
#include <clientprefs>
#define LoopClients(%1) for(int %1 = 1;%1 <= MaxClients;%1++) if(IsValidClient(%1))
new Handle:PluginEnabled = INVALID_HANDLE;
new Handle:WarmupTime = INVALID_HANDLE;
new Handle:PlayerCountStart = INVALID_HANDLE;
new Handle:WarmupBack = INVALID_HANDLE;
new bool:IsWarmup;
new bool:ToWarmup;
int ToWarmupTime = 0;
public Plugin:myinfo =
{
name = "[CS:GO] Warmup Lobby",
author = "Rain_Effect",
description = "Keeps game in warmup untill specified number of players to start.",
version = "1.0",
url = "http://mc-rain.cn/"
};
public OnPluginStart()
{
PluginEnabled = CreateConVar("sm_warmup_lobby_enabled", "1", "Whether the plugin is enabled");
WarmupTime = CreateConVar("sm_warmup_lobby_time", "140", "Warmup time after players have connected");
PlayerCountStart = CreateConVar("sm_warmup_lobby_players_start", "2", "Number of players to end warmup");
WarmupBack = CreateConVar("sm_warmup_lobby_end_back", "10", "How long to back warmup when a round end");
AutoExecConfig(true, "warmup_lobby");
IsWarmup = false;
CreateTimer(1.0, Timer_GlobalTimer, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public Action Timer_GlobalTimer(Handle timer)
{
if(IsWarmup)
{
LoopClients(i)
{
PrintHintText(i, "[WarmUp Lobby]<br>Need ",GetConVarInt(PlayerCountStart), player(s) to"<br>start the game!");
}
}
if(ToWarmup)
{
if(ToWarmupTime<0)
{
LoopClients(i)
{
PrintHintText(i, "[WarmUp Lobby]<br>Game will be reset<br>in ",ToWarmupTime," seconds!");
}
ToWarmupTime=ToWarmupTime-1;
}
else
{
ServerCommand("mp_warmup_start;");
ToWarmup = false;
}
}
return Plugin_Continue;
}
public OnClientPutInServer(client)
{
CheckCount();
}
public OnClientDisconnect_Post()
{
CheckCount();
}
public CheckCount()
{
if(GetConVarBool(PluginEnabled))
{
SetConVarInt(FindConVar("mp_warmuptime"), GetConVarInt(WarmupTime));
SetConVarInt(FindConVar("mp_do_warmup_period"), 1);
if(GetClientCount(true) < GetConVarInt(PlayerCountStart))
{
if(!IsWarmup)
{
ServerCommand("mp_warmup_start;");
IsWarmup = true;
}
ServerCommand("mp_warmup_pausetimer 1");
}
else
{
ServerCommand("mp_warmup_pausetimer 0");
}
}
}
public round_start()
{
if(IsWarmup)
IsWarmup = false;
}
public round_end()
{
ToWarmupTime = GetConVarInt(WarmupBack);
ToWarmup = true;
}
stock bool IsValidClient(int client, bool alive = false)
{
if(0 < client && client <= MaxClients && IsClientInGame(client) && IsFakeClient(client) == false && (alive == false || IsPlayerAlive(client))) return true;
return false;
}