as you like :
PHP Code:
int Humans;
Handle Cvar;
public Plugin myinfo = {
name = "[L4D]auto restart campaigns",
author = "Jes",
description = "fix for some suspicious 3rd-party programs",
version = "1.0.0",
url = "https://forums.alliedmods.net/"
};
public OnPluginStart()
{
Cvar = CreateConVar("sv_auto_restart_time", "30.0" ,_,FCVAR_NONE ,true ,1.0 ,true ,60.0);
HookEvent("player_connect", Event_Connect, EventHookMode_Post);
HookEvent("player_disconnect", Event_Disconnect, EventHookMode_Post);
}
public Action:Event_Connect(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!GetEventBool(event, "bot") && ++Humans == 1)
CreateTimer( GetConVarFloat(Cvar) ,Restart_Timer);
return Plugin_Continue;
}
public Action:Event_Disconnect(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!GetEventBool(event, "bot"))
Humans--;
return Plugin_Continue;
}
public Action Restart_Timer(Handle timer)
{
//----- Choose ONLY ONE of the below lines by removing // from the beginning :
//ServerCommand("sm_cvar mp_restartgame 1");
//ServerCommand("changelevel %s" , GetEngineVersion() == Engine_Left4Dead ? "l4d_hospital01_apartment" : "c8m1_apartment");
FakeClientCommandEx(1 , "callvote restartgame");
//FakeClientCommandEx(1 , "callvote ChangeMission %s", GetEngineVersion() == Engine_Left4Dead ? "Hospital" : "L4D2C8");
return Plugin_Handled;
}
Note : There is a huge difference between restart
engine and restart
map/campaign ,
I've given you two different functions , the first one supposed to restart engine , while the second one is for maps and campaigns ,
if your problem was not solved , you can use both together .