From 66e1cc854796b05377e4a7c77d3f717b9c37e925 Mon Sep 17 00:00:00 2001 From: Musiker15 Date: Sun, 20 Oct 2024 18:04:39 +0200 Subject: [PATCH] Update v2.6.6 --- client/functions/points.lua | 105 +++++++++++++++++++++++++++++++++ config.lua | 8 +-- fxmanifest.lua | 2 +- server/functions/ace.lua | 50 +++++++++++++--- server/functions/bansystem.lua | 4 ++ 5 files changed, 155 insertions(+), 14 deletions(-) create mode 100644 client/functions/points.lua diff --git a/client/functions/points.lua b/client/functions/points.lua new file mode 100644 index 0000000..b6ff707 --- /dev/null +++ b/client/functions/points.lua @@ -0,0 +1,105 @@ +local Points = {} +local RegisteredPoints = {} +local closestPoint + +local RemovePoint = function(self) + if closestPoint.id and closestPoint.id == self.id then + closestPoint = nil + end + + RegisteredPoints[self.id] = nil +end + +local ConvertCoords = function(coords) + local coordsType = type(coords) + + if coordsType ~= 'vector3' and coordsType ~= 'vec3' then + if coordsType == 'table' then + return vector3(coords[1] or coords.x, coords[2] or coords.y, coords[3] or coords.z) + elseif coordsType == 'vector4' or coordsType == 'vec4' then + return vector3(coords.x, coords.y, coords.z) + end + + error(("expected type 'vector3', received type '%s' (value: %s)"):format(coordsType, coords)) + end + + return coords +end + +CreateThread(function() + while true do + local sleep = 250 + local coords = MSK.Player.coords + + if closestPoint and #(coords - closestPoint.coords) > closestPoint.distance then + closestPoint = nil + end + + for k, point in pairs(RegisteredPoints) do + local distance = #(coords - point.coords) + + if distance <= point.distance then + point.currentDistance = distance + + if closestPoint then + if distance < closestPoint.currentDistance then + closestPoint.isClosest = nil + point.isClosest = true + closestPoint = point + end + elseif distance < point.distance then + point.isClosest = true + closestPoint = point + end + + if not point.inside then + point.inside = true + + if point.onEnter then + point.onEnter(point) + end + end + elseif point.inside then + point.inside = false + point.currentDistance = nil + + if point.onExit then + point.onExit(point) + end + end + end + + Wait(sleep) + end +end) + +Points.Add = function(properties) + if type(properties) ~= "table" then + return + end + + if not properties.coords or not properties.distance then + error(("expected type 'table' for parameter 'properties', received type '%s'"):format(type(properties))) + end + + local id = #RegisteredPoints + 1 + local self = properties + + self.id = id + self.coords = ConvertCoords(self.coords) + self.Remove = RemovePoint + + RegisteredPoints[id] = self + + return self +end + +Points.GetAllPoints = function() + return RegisteredPoints +end + +Points.GetClosestPoint = function() + return closestPoint +end + +MSK.Points = Points \ No newline at end of file diff --git a/config.lua b/config.lua index f944892..d34d55f 100644 --- a/config.lua +++ b/config.lua @@ -9,7 +9,7 @@ Config.Framework = 'AUTO' -- Supported Inventories: default, custom, ox_inventory, qs-inventory -- For ESX Default Inventory or Chezza Inventory, set to 'default' --- Set to 'custom' if you use another inventory +-- Set to 'custom' if you use another inventory and add your own functions -- You can add your own inventory in: server/inventories/custom.lua Config.Inventory = 'default' ---------------------------------------------------------------- @@ -57,7 +57,7 @@ Config.DisconnectLogger = { console = { enable = false, -- German: "Der Spieler ^3%s^0 mit der ^3ID %s^0 hat den Server verlassen.\n^4Uhrzeit:^0 %s\n^4Grund:^0 %s\n^4Identifier:^0\n %s\n %s\n %s\n^4Koordinaten:^0 %s" - -- English: "The player ^3%s^0 with the ^3ID %s^0 has left the server.\n^4Time:^0 %s\n^4Reason:^0 %s\n^4Identifier:^0\n %s\n %s\n %s\n^4Coordinates:^0 %s" + -- English: "The player ^3%s^0 with the ^3ID %s^0 has left the server.\n^4Time:^0 %s\n^4Reason:^0 %s\n^4Identifier:^0\n %s\n %s\n %s\n^4Coordinates:^0 %s" text = "Der Spieler ^3%s^0 mit der ^3ID %s^0 hat den Server verlassen.\n^4Uhrzeit:^0 %s\n^4Grund:^0 %s\n^4Identifier:^0\n %s\n %s\n %s\n^4Koordinaten:^0 %s" }, @@ -73,7 +73,7 @@ Config.DisconnectLogger = { } } ---------------------------------------------------------------- --- For more Information go to: https://github.com/MSK-Scripts/msk_bansystem/blob/main/README.md +-- For more Information go to: https://docu.msk-scripts.de/msk-core/functions/server/ban-system Config.BanSystem = { enable = true, -- Set to true if you want to use this Feature @@ -83,7 +83,7 @@ Config.BanSystem = { botAvatar = "https://i.imgur.com/PizJGsh.png", commands = { - enable = false, + enable = true, groups = {'superadmin', 'admin', 'god'}, ban = 'banPlayer', unban = 'unbanPlayer' diff --git a/fxmanifest.lua b/fxmanifest.lua index baab991..beb2670 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ games { 'gta5' } author 'Musiker15 - MSK Scripts' name 'msk_core' description 'Functions for MSK Scripts' -version '2.6.5' +version '2.6.6' lua54 'yes' diff --git a/server/functions/ace.lua b/server/functions/ace.lua index 6a2fc42..3b49d22 100644 --- a/server/functions/ace.lua +++ b/server/functions/ace.lua @@ -1,5 +1,9 @@ MSK.IsAceAllowed = function(playerId, command) - return IsPlayerAceAllowed(playerId, ('command.%s'):format(command)) + if not MSK.String.StartsWith(command, 'command.') then + command = ('command.%s'):format(command) + end + + return IsPlayerAceAllowed(playerId, command) end exports('IsAceAllowed', MSK.IsAceAllowed) @@ -21,23 +25,39 @@ local allowAce = function(allow) end MSK.AddAce = function(principal, ace, allow) - if type(principal) == 'string' then - principal = 'group.' .. principal - elseif type(principal) == 'number' then - principal = 'player.' .. principal + if not MSK.String.StartsWith(principal, 'group.') and not MSK.String.StartsWith(principal, 'player.') then + if type(principal) == 'string' then + principal = 'group.' .. principal + elseif type(principal) == 'number' then + principal = 'player.' .. principal + end end + if not MSK.String.StartsWith(ace, 'command.') then + ace = ('command.%s'):format(ace) + end + + logging('debug', 'MSK.AddAce', principal, ace, allowAce(allow)) + ExecuteCommand(('add_ace %s %s %s'):format(principal, ace, allowAce(allow))) end exports('AddAce', MSK.AddAce) MSK.RemoveAce = function(principal, ace, allow) - if type(principal) == 'string' then - principal = 'group.' .. principal - elseif type(principal) == 'number' then - principal = 'player.' .. principal + if not MSK.String.StartsWith(principal, 'group.') and not MSK.String.StartsWith(principal, 'player.') then + if type(principal) == 'string' then + principal = 'group.' .. principal + elseif type(principal) == 'number' then + principal = 'player.' .. principal + end + end + + if not MSK.String.StartsWith(ace, 'command.') then + ace = ('command.%s'):format(ace) end + logging('debug', 'MSK.RemoveAce', principal, ace, allowAce(allow)) + ExecuteCommand(('remove_ace %s %s %s'):format(principal, ace, allowAce(allow))) end exports('RemoveAce', MSK.RemoveAce) @@ -47,6 +67,12 @@ MSK.AddPrincipal = function(child, parent) principal = 'player.' .. principal end + if not MSK.String.StartsWith(parent, 'group.') then + parent = ('group.%s'):format(parent) + end + + logging('debug', 'MSK.AddPrincipal', child, parent) + ExecuteCommand(('add_principal %s %s'):format(child, parent)) end exports('AddPrincipal', MSK.AddPrincipal) @@ -56,6 +82,12 @@ MSK.RemovePrincipal = function(child, parent) principal = 'player.' .. principal end + if not MSK.String.StartsWith(parent, 'group.') then + parent = ('group.%s'):format(parent) + end + + logging('debug', 'MSK.RemovePrincipal', child, parent) + ExecuteCommand(('remove_principal %s %s'):format(child, parent)) end exports('RemovePrincipal', MSK.RemovePrincipal) \ No newline at end of file diff --git a/server/functions/bansystem.lua b/server/functions/bansystem.lua index a0055f1..e37b418 100644 --- a/server/functions/bansystem.lua +++ b/server/functions/bansystem.lua @@ -230,6 +230,10 @@ exports('UnbanPlayer', MSK.UnbanPlayer) exports('unbanPlayer', MSK.UnbanPlayer) -- Support for old Scripts if Config.BanSystem.enable and Config.BanSystem.commands.enable then + while not MSK.RegisterCommand do + Wait(10) + end + MSK.RegisterCommand(Config.BanSystem.commands.ban, function(source, args, raw) local playerId = source local targetId, time, reason = args.playerId, args.time, args.reason