Raised This Month: $ Target: $400
 0% 

Crashed Map Recovery v1.5 Modification / Help Requests


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Darkwob
BANNED
Join Date: Oct 2018
Old 08-27-2020 , 23:40   Crashed Map Recovery v1.5 Modification / Help Requests
Reply With Quote #1

This plugin replays the same episode at Episode End. taking a loop on the same map. When I restarted the server, I downloaded this plugin to prevent it from going to the first map, but while playing another map it suddenly starts it back to the map where it was looped at the end of the episode.


map in loop.After finishing the first part of the dead center map, instead of moving to the other second part, the one below starts on the map. We play that map and it stays on the same map again.
c10m3_ranchhouse

PHP Code:
/*
* Crashed Map Recovery (c) 2009 Jonah Hirsch


* Loads the map the server was on before it crashed when server restarts

*  
* Changelog                                
* ------------        
* 1.5
*  - Messages are now logged to logs/CMR.log
*  - crashmap.txt is now generated automatically
* 1.4.3
*  - Fixed compile warnings
*  - Backs up and restores nextmap on crash + recover (test feature!)
* 1.4.2
*  - Autoconfig added. cfg/sourcemod/plugin.crashmap.cfg
* 1.4.1
*  - Added FCVAR_DONTRECORD to version cvar
* 1.4
*  - Added sm_crashmap_maxrestarts
*  - Added support for checking if the map being changed to crashes the server
* 1.3
*  - Changed method of enabling/disabling recover time to improve performance
*  - Added sm_crashmap_interval
* 1.2
*  - Added timelimit recovery
*  - Added sm_crashmap_recovertime
* 1.1
*  - Added log message when map is recoevered on restart
* 1.0                                    
*  - Initial Release            

*         
*/

#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.5"

static String:FileLoc[128];
new 
String:logPath[PLATFORM_MAX_PATH]
new 
Handle:logFileHandle INVALID_HANDLE
new Handle:dataFileHandle INVALID_HANDLE
new Handle:sm_crashmap_enabled INVALID_HANDLE
new Handle:sm_crashmap_recovertime INVALID_HANDLE
new Handle:sm_crashmap_interval INVALID_HANDLE
new Handle:sm_crashmap_maxrestarts INVALID_HANDLE
new Handle:TimeleftHandle INVALID_HANDLE
new bool:Recovered false
new bool:TimelimitChanged false
new bool:Overwrite false
new newTimelimit


public Plugin:myinfo 
{
    
name "Crashed Map Recovery",
    
author "Crazydog",
    
description "Reloads map that was being played before server crash",
    
version PLUGIN_VERSION,
    
url "http://theelders.net"
}

public 
OnPluginStart(){
    
CreateConVar("sm_crashmap_version"PLUGIN_VERSION"Crashed Map Recovery Version"FCVAR_PLUGIN FCVAR_SPONLY FCVAR_NOTIFY FCVAR_DONTRECORD);
    
sm_crashmap_enabled CreateConVar("sm_crashmap_enabled""1""Enable Crashed Map Recovery? (1=yes 0=no)"FCVAR_NOTIFYtrue0.0true1.0)
    
sm_crashmap_recovertime CreateConVar("sm_crashmap_recovertime""0""Recover timelimit? (1=yes 0=no)"FCVAR_NOTIFYtrue0.0true1.0)
    
sm_crashmap_interval CreateConVar("sm_crashmap_interval""20""Interval between timeleft updates (in seconds)"FCVAR_NOTIFYtrue1.0)
    
sm_crashmap_maxrestarts CreateConVar("sm_crashmap_maxrestarts""5""How many consecutive crashes until server loads the default map"FCVAR_NOTIFYtrue3.0)
    
AutoExecConfig(true"plugin.crashmap")
    
HookConVarChange(sm_crashmap_recovertimeTimerState)
    
HookConVarChange(sm_crashmap_intervalIntervalChange)
    
    if(
GetConVarInt(sm_crashmap_recovertime) == 1){
        
TimeleftHandle CreateTimer(GetConVarFloat(sm_crashmap_interval), SaveTimeleft_TIMER_REPEAT)
    }
    
BuildPath(Path_SMFileLoc128"data/crashmap.txt")
    if(!
FileExists(FileLoc)){
        
dataFileHandle OpenFile(FileLoc,"a");
        
WriteFileLine(dataFileHandle,"SavedMap");
        
WriteFileLine(dataFileHandle,"{");
        
WriteFileLine(dataFileHandle,"}");
        
CloseHandle(dataFileHandle);
    }
    
    
BuildPath(Path_SMlogPathPLATFORM_MAX_PATH"/logs/CMR.log")
    if(!
FileExists(logPath)){
        
logFileHandle OpenFile(logPath"a")
        
CloseHandle(logFileHandle)
    }
}



public 
OnMapStart(){
    if(
GetConVarInt(sm_crashmap_enabled) == 0){
        return
    }
    if(
Recovered){
        new 
String:CurrentMap[256];
        
GetCurrentMap(CurrentMapsizeof(CurrentMap))
        
decl Handle:SavedMap
        SavedMap 
CreateKeyValues("SavedMap")
        
FileToKeyValues(SavedMapFileLoc)
        
KvJumpToKey(SavedMap"Map"true)
        
KvSetString(SavedMap"Map"CurrentMap)
        
KvRewind(SavedMap)
        
KeyValuesToFile(SavedMapFileLoc)
        
CloseHandle(SavedMap)
        return
    }
    if(!
Recovered){
        new 
String:MapToLoad[256], String:nextmap[256], timeleftrestarts
        decl Handle
:SavedMap
        SavedMap 
CreateKeyValues("SavedMap")
        
FileToKeyValues(SavedMapFileLoc)
        
KvJumpToKey(SavedMap"Map"true)
        
KvGetString(SavedMap"Map"MapToLoadsizeof(MapToLoad))
        
restarts KvGetNum(SavedMap"restarts"0)
        
//LogToFile(logPath, "[CMR] Server restarted, restarts is %i", restarts)
        
restarts++
        
//LogToFile(logPath, "[CMR] Restarts incremented, restarts is %i", restarts)
        
LogToFile(logPath"Restarts is %i"restarts)
        
KvSetNum(SavedMap"restarts"restarts)
        
timeleft KvGetNum(SavedMap"Timeleft"30)
        
KvGetString(SavedMap"Nextmap"nextmapsizeof(nextmap))
        
SetNextMap(nextmap)
        
newTimelimit timeleft/60
        Recovered 
true
        
if(restarts GetConVarInt(sm_crashmap_maxrestarts)){
            
LogToFile(logPath"[CMR] Error! %s is causing the server to crash. Please fix!"MapToLoad)
            
KvSetNum(SavedMap"restarts"0)
            
KvRewind(SavedMap)
            
KeyValuesToFile(SavedMapFileLoc)
            
CloseHandle(SavedMap)
            return
        }
        
KvRewind(SavedMap)
        
KeyValuesToFile(SavedMapFileLoc)
        
CloseHandle(SavedMap)
        if(
GetConVarInt(sm_crashmap_recovertime) == 1){
            
LogToFile(logPath"[CMR] %s loaded after server crash. Timelimit set to %i"MapToLoadtimeleft/60)
        }else{
            
LogToFile(logPath"[CMR] %s loaded after server crash."MapToLoad)
        }
        
ForceChangeLevel(MapToLoad"Crashed Map Recovery")
        return
    }
}



public 
OnMapEnd(){
}

public 
Action:SaveTimeleft(Handle:timer){
    if(
Overwrite){
        new 
timeleft
        
if(!GetMapTimeLeft(timeleft)){
            if(!
GetMapTimeLimit(timeleft)){
                
timeleft 30
            
}
        }
        new 
String:nextmap[256]
        
GetNextMap(nextmapsizeof(nextmap))
        
decl Handle:SavedMap
        SavedMap 
CreateKeyValues("SavedMap")
        
FileToKeyValues(SavedMapFileLoc)
        
KvJumpToKey(SavedMap"Map"true)
        
KvSetNum(SavedMap"Timeleft"timeleft)
        
KvSetString(SavedMap"Nextmap"nextmap
        
KvRewind(SavedMap)
        
KeyValuesToFile(SavedMapFileLoc)
        
CloseHandle(SavedMap)
    }
}

public 
OnClientAuthorized(client){
    
decl Handle:SavedMap
    SavedMap 
CreateKeyValues("SavedMap")
    
FileToKeyValues(SavedMapFileLoc)
    
KvJumpToKey(SavedMap"Map"true)
    
KvSetNum(SavedMap"restarts"0)
    
KvRewind(SavedMap)
    
KeyValuesToFile(SavedMapFileLoc)
    
CloseHandle(SavedMap)
    if(!
TimelimitChanged && GetConVarInt(sm_crashmap_recovertime) == 1){
        
ServerCommand("mp_timelimit %i"newTimelimit)
        
TimelimitChanged true
        Overwrite 
true
    
}
}

public 
TimerState(Handle:convar, const String:oldValue[], const String:newValue[]){
    if(
GetConVarInt(sm_crashmap_recovertime) < 1){
        if(
TimeleftHandle != INVALID_HANDLE){
            
KillTimer(TimeleftHandle)
            
TimeleftHandle INVALID_HANDLE
        
}
    }
    if(
GetConVarInt(sm_crashmap_recovertime) > 0){
        new 
Float:newTime GetConVarFloat(sm_crashmap_interval)
        
TimeleftHandle CreateTimer(newTimeSaveTimeleft_TIMER_REPEAT)
        
Overwrite true
    
}
}

public 
IntervalChange(Handle:convar, const String:oldValue[], const String:newValue[]){
    if(
TimeleftHandle != INVALID_HANDLE){
        new 
Float:newTime StringToFloat(newValue)
        
KillTimer(TimeleftHandle)
        
TimeleftHandle INVALID_HANDLE
        TimeleftHandle 
CreateTimer(newTimeSaveTimeleft_TIMER_REPEAT)
    }

Darkwob is offline
Reply



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 03:07.


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