Skip to content

Commit

Permalink
script files
Browse files Browse the repository at this point in the history
  • Loading branch information
HeresJohnny320 committed Dec 29, 2023
1 parent 53351ff commit 5166a50
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions auto_restart/fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fx_version 'cerulean'
game 'gta5'

author 'HeresJohnny320 (https://github.com/HeresJohnny320/fivem-resource-file-watcher)'
description 'restarts any resource'
version '1.0.0'


server_script 'server.js'
30 changes: 30 additions & 0 deletions auto_restart/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path');
var enabled_script = true;
var attempt_to_run = false;
fs.watch("./resources", { recursive: true}, function (event,filename) {
ExecuteCommand("refresh")
console.log("REFRESHING RESOURCES LIST")
const pathParts = filename.split(path.sep);
if (event === 'change' && filename) {
if(enabled_script){
if(pathParts[0] == GetCurrentResourceName()){
console.error("CANT RESTART ITSELF OTHERWISE I CRASH SERVER")
}else{
if(GetResourceState(pathParts[0]) == 'started' || GetResourceState(pathParts[0]) == 'starting' || GetResourceState(pathParts[0]) == 'running'){
console.debug("Resource Named:"+pathParts[0]+" Has Made A Change, fullpath:"+filename);
ExecuteCommand("restart "+pathParts[0])
}else if(GetResourceState(pathParts[0]) == 'stopped' || GetResourceState(pathParts[0]) == 'stopping'){
if(attempt_to_run){
console.warn("Attempting To Start Resource:"+pathParts[0])
ExecuteCommand("start "+pathParts[0])
}else{
console.warn("Resource Named:"+pathParts[0]+" Is Not Running Please Start It With 'start "+pathParts[0]+"' To Run The Resource")
}
}else{
console.error("Resource Named:"+pathParts[0]+" Is uninitialized or unknown")
}
}
}
}
});

0 comments on commit 5166a50

Please sign in to comment.