-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53351ff
commit 5166a50
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|