Raised This Month: $150 Target: $400
 37% 

Solved [L4D2] Restart chapter on server waking up


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jes
Junior Member
Join Date: Aug 2024
Old 11-26-2024 , 02:30   [L4D2] Restart chapter on server waking up
Reply With Quote #1

Yes as the title said, is there a plugin to restart the server on server waking up (dedicated), when the first player joins and the server starts running, after 30 seconds restart command will be executed, but only for the first entry at all.

Last edited by Jes; 12-02-2024 at 13:48.
Jes is offline
101
Senior Member
Join Date: Nov 2023
Old 11-26-2024 , 23:24   Re: [L4D2] Restart chapter on server waking up
Reply With Quote #2

it is better to describe why you want to restart your server ?
there must be a more efficient solution .

PHP Code:
int Humans;

public 
OnPluginStart() 
{
    
HookEvent("player_connect"Event_ConnectEventHookMode_Post);
    
HookEvent("player_disconnect"Event_DisconnectEventHookMode_Post);
}

public 
Action:Event_Connect(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!
GetEventBool(event"bot"))
        
Humans++;
    return 
Plugin_Continue;
}

public 
Action:Event_Disconnect(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!
GetEventBool(event"bot") && Humans-- == 1)
        
ServerCommand("_restart");    // Last Human left ... Shutdown and restart the engine
    
return Plugin_Continue;

you may have to look at this : https://forums.alliedmods.net/showthread.php?t=315367
101 is offline
Jes
Junior Member
Join Date: Aug 2024
Old 11-27-2024 , 03:20   Re: [L4D2] Restart chapter on server waking up
Reply With Quote #3

The plugins I'm using require restart on the first time entry to operate. I have to do it manually now so I need an auto restarter, but only for 1 time. From the 2nd chap onwards they work normally. So maybe after the server is wakened by the first player joining, after 30 seconds command restart will be executed

Last edited by Jes; 11-27-2024 at 03:23.
Jes is offline
101
Senior Member
Join Date: Nov 2023
Old 11-27-2024 , 23:47   Re: [L4D2] Restart chapter on server waking up
Reply With Quote #4

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_ConnectEventHookMode_Post);
    
HookEvent("player_disconnect"Event_DisconnectEventHookMode_Post);
}

public 
Action:Event_Connect(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!
GetEventBool(event"bot") && ++Humans == 1)
        
CreateTimerGetConVarFloat(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("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 .
101 is offline
Jes
Junior Member
Join Date: Aug 2024
Old 11-29-2024 , 19:56   Re: [L4D2] Restart chapter on server waking up
Reply With Quote #5

Is there a way to simulate !restart from admin system, or just simply run the round_end, mission_lost, etc... REstarting the campaign or changing map won't work
Jes is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 11-30-2024 , 07:23   Re: [L4D2] Restart chapter on server waking up
Reply With Quote #6

Quote:
Originally Posted by Jes View Post
I have to do it manually now so I need an auto restarter, but only for 1 time.

server_loader
__________________

Last edited by HarryPotter; 11-30-2024 at 07:28.
HarryPotter is offline
Jes
Junior Member
Join Date: Aug 2024
Old 12-02-2024 , 13:48   Re: [L4D2] Restart chapter on server waking up
Reply With Quote #7

Alrighty Ty guys I got it
Jes is offline
101
Senior Member
Join Date: Nov 2023
Old 12-10-2024 , 09:18   Re: [L4D2] Restart chapter on server waking up
Reply With Quote #8

more direct function [Untested]
(requires sourcemod_v1.12) :
PHP Code:
/*public OnServerEnterHibernation()
{
    LogMessage("OnServerEnterHibernation");
}*/

public OnServerExitHibernation()
{
   
//ServerCommand("sm_cvar mp_restartgame 1");
   //ServerCommand("changelevel %s" , GetEngineVersion() == Engine_Left4Dead ? "l4d_hospital01_apartment" : "c8m1_apartment");
   //ServerCommand("exec 123.cfg");
   
...


Last edited by 101; 12-10-2024 at 09:20.
101 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:59.


Powered by vBulletin®
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Theme made by Freecode