From 23a59584175dcbef7768b727324d9b556d3a6c78 Mon Sep 17 00:00:00 2001 From: JHodgson1 Date: Sun, 17 Mar 2019 14:16:20 +0000 Subject: [PATCH] v.1.0.2: Add the ability to configure admins and disable the check for them --- no-god-mode/client.lua | 10 ++++++++-- no-god-mode/server.lua | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 no-god-mode/server.lua diff --git a/no-god-mode/client.lua b/no-god-mode/client.lua index 81adb41..a7021bf 100644 --- a/no-god-mode/client.lua +++ b/no-god-mode/client.lua @@ -1,4 +1,5 @@ local isInvincible = false +local isAdmin = false Citizen.CreateThread(function() while true do @@ -13,7 +14,7 @@ Citizen.CreateThread(function() local ped = PlayerPedId() local player = PlayerId() - if isInvincible then + if isInvincible and not isAdmin then DrawLabel("~r~You are currently in godmode which is ~h~prohibited~h~ on this server, disable it now.") FreezeEntityPosition(ped, true) DisablePlayerFiring(player, true) -- true/false - doesn't seem to do anything different, still disables every frame @@ -35,4 +36,9 @@ function DrawLabel(text) BeginTextCommandDisplayHelp("STRING") AddTextComponentSubstringPlayerName(text) EndTextCommandDisplayHelp(0, 0, 1, -1) -end \ No newline at end of file +end + +RegisterNetEvent("sendAcePermissionToClient") +AddEventHandler("sendAcePermissionToClient", function(state) + isAdmin = state +end) \ No newline at end of file diff --git a/no-god-mode/server.lua b/no-god-mode/server.lua new file mode 100644 index 0000000..9a29c73 --- /dev/null +++ b/no-god-mode/server.lua @@ -0,0 +1,29 @@ +local ace_perm = "admin" +local debug = false + +function ProcessAces() + if GetNumPlayerIndices() > 0 then -- don't do it when there aren't any players + for i=0, GetNumPlayerIndices()-1 do -- loop through all players + player = tonumber(GetPlayerFromIndex(i)) + Citizen.Wait(0) + if IsPlayerAceAllowed(player, ace_perm) then + TriggerClientEvent("sendAcePermissionToClient", player, true) + if debug then print("[DEBUG][" .. GetCurrentResourceName() .. "] ^5Syncronising player aces, sending to client...^0") end + end + end + end +end + +Citizen.CreateThread(function() + while true do + ProcessAces() + Citizen.Wait(60000) -- lets check every minute + end +end) + +AddEventHandler("onResourceStart", function(name) + if name == GetCurrentResourceName() then + ProcessAces() + if debug then print("[DEBUG][" .. GetCurrentResourceName() .. "] ^6Resource [ " .. GetCurrentResourceName() .. " ] was (re)started, syncing aces to all players.^0") end + end +end) \ No newline at end of file