fivem
fivem copied to clipboard
Restarting current resource within itself results in server crash
const currentResourceName = GetCurrentResourceName();
RegisterCommand(`restart:${currentResourceName}`, () => {
// Works
// ExecuteCommand(`restart ${currentResourceName}`);
// Crashes
setImmediate(() => ExecuteCommand(`restart ${currentResourceName}`));
});
// Crashes
// setTimeout(() => ExecuteCommand(`restart ${currentResourceName}`), 1e3);
This isn't fixable for obvious reasons and there's already logic preventing this for the intended natives such as STOP_RESOURCE.
The best we can do is just prevent a stop/start of a currently-executing resource, but you haven't provided much.. details.
Alright, so I have to add the command to separate resource to fix that. The reason why I need separate command for restarting specific resource is because only players with specific ace permission should be able to restart this specific resource. I don't want to give players permission for restart command as they could restart any resource which should not be restarted.