Skip to content

Commit

Permalink
ipb: Make use of onPlayerResourceStart (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
srslyyyy committed Nov 14, 2023
1 parent 3044d00 commit cca3a05
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
6 changes: 0 additions & 6 deletions [admin]/ipb/client/settings.lua
@@ -1,12 +1,6 @@

g_Settings = {}

addEventHandler("onClientResourceStart", resourceRoot,
function ()
triggerServerEvent("onClientResourceStart", localPlayer)
end,
false)

addEvent("ipb.syncSettings", true)
addEventHandler("ipb.syncSettings", localPlayer,
function (settings)
Expand Down
49 changes: 27 additions & 22 deletions [admin]/ipb/server/settings.lua
Expand Up @@ -4,37 +4,42 @@ local settingPrefix = ("*%s."):format(resourceName)
local prefixLength = settingPrefix:len()

g_Settings = {
["SaveHighCPUResources"] = get("SaveHighCPUResources") or "true",
["SaveHighCPUResourcesAmount"] = get("SaveHighCPUResourcesAmount") or "10",
["NotifyIPBUsersOfHighUsage"] = get("NotifyIPBUsersOfHighUsage") or "50",
["AccessRightName"] = get("AccessRightName") or "general.http"
["SaveHighCPUResources"] = get("SaveHighCPUResources") or "true",
["SaveHighCPUResourcesAmount"] = get("SaveHighCPUResourcesAmount") or "10",
["NotifyIPBUsersOfHighUsage"] = get("NotifyIPBUsersOfHighUsage") or "50",
["AccessRightName"] = get("AccessRightName") or "general.http"
}

local function onResourceSettingChange(name, old, new)
g_Settings[name] = new
g_Settings[name] = new

if Element.getByIndex("player", 0) then
triggerClientEvent("ipb.updateSetting", resourceRoot, name, new)
end
if Element.getByIndex("player", 0) then
triggerClientEvent("ipb.updateSetting", resourceRoot, name, new)
end
end

addEventHandler("onSettingChange", root,
function (settingName, old, new)
if not settingName:find(settingPrefix, 1, true) then
return
end
function (settingName, old, new)
if not settingName:find(settingPrefix, 1, true) then
return
end

local shortSettingName = settingName:sub(prefixLength + 1)
local shortSettingName = settingName:sub(prefixLength + 1)

if g_Settings[shortSettingName] ~= new then
onResourceSettingChange(shortSettingName, old and fromJSON(old) or old, new and fromJSON(new) or new)
end
end
if g_Settings[shortSettingName] ~= new then
onResourceSettingChange(shortSettingName, old and fromJSON(old) or old, new and fromJSON(new) or new)
end
end
)

addEvent("onClientResourceStart", true)
addEventHandler("onClientResourceStart", root,
function ()
client:triggerEvent("ipb.syncSettings", client, g_Settings)
end
addEventHandler("onPlayerResourceStart", root,
function (startedResource)
local matchingResource = (startedResource == resource)

if not matchingResource then
return false
end

triggerClientEvent(source, "ipb.syncSettings", source, g_Settings)
end
)

0 comments on commit cca3a05

Please sign in to comment.