diff --git a/client/cl_anticombatlog.lua b/client/cl_anticombatlog.lua index 1d099fc..c789f53 100644 --- a/client/cl_anticombatlog.lua +++ b/client/cl_anticombatlog.lua @@ -53,5 +53,4 @@ local display = function(data) end end) end - RegisterNetEvent('msk_core:anticombatlog', display) \ No newline at end of file diff --git a/client/cl_input.lua b/client/cl_input.lua index d1f51ff..64adcd2 100644 --- a/client/cl_input.lua +++ b/client/cl_input.lua @@ -41,6 +41,11 @@ MSK.CloseInput = function() end exports('CloseInput', MSK.CloseInput) exports('closeInput', MSK.CloseInput) -- Support for old Scripts +RegisterNetEvent('msk_core:closeInput', MSK.CloseInput) + +MSK.Register('msk_core:input', function(source, header, placeholder, field) + return MSK.Input(header, placeholder, field) +end) RegisterNUICallback('submitInput', function(data) if data.input == '' then data.input = nil end diff --git a/client/cl_numpad.lua b/client/cl_numpad.lua index f2c18dc..14ab1ea 100644 --- a/client/cl_numpad.lua +++ b/client/cl_numpad.lua @@ -40,6 +40,11 @@ MSK.CloseNumpad = function() }) end exports('CloseNumpad', MSK.CloseNumpad) +RegisterNetEvent('msk_core:closeNumpad', MSK.CloseNumpad) + +MSK.Register('msk_core:numpad', function(source, pin, show) + return MSK.Numpad(pin, show) +end) RegisterNUICallback('submitNumpad', function(data) callback(true) diff --git a/client/cl_showCoords.lua b/client/cl_showCoords.lua index 6b1cee1..1d676dd 100644 --- a/client/cl_showCoords.lua +++ b/client/cl_showCoords.lua @@ -15,6 +15,10 @@ MSK.DoesShowCoords = function() end exports('DoesShowCoords', MSK.DoesShowCoords) +MSK.Register('msk_core:doesShowCoords', function(source) + return showCoords +end) + local DrawGenericText = function(text) SetTextColour(186, 186, 186, 255) SetTextFont(7) diff --git a/client/main.lua b/client/main.lua index 4b4bb29..266bcc4 100644 --- a/client/main.lua +++ b/client/main.lua @@ -53,6 +53,7 @@ MSK.Notification = function(title, message, typ, duration) end MSK.Notify = MSK.Notification exports('Notification', MSK.Notification) +RegisterNetEvent("msk_core:notification", MSK.Notification) MSK.HelpNotification = function(text) BeginTextCommandDisplayHelp('STRING') @@ -61,6 +62,7 @@ MSK.HelpNotification = function(text) end MSK.HelpNotify = MSK.HelpNotification exports('HelpNotification', MSK.HelpNotification) +RegisterNetEvent("msk_core:helpNotification", MSK.HelpNotification) MSK.AdvancedNotification = function(text, title, subtitle, icon, flash, icontype) if not flash then flash = true end @@ -74,6 +76,7 @@ MSK.AdvancedNotification = function(text, title, subtitle, icon, flash, icontype end MSK.AdvancedNotify = MSK.AdvancedNotification exports('AdvancedNotification', MSK.AdvancedNotification) +RegisterNetEvent("msk_core:advancedNotification", MSK.AdvancedNotification) MSK.ScaleformAnnounce = function(header, text, typ, duration) local scaleform = '' @@ -117,6 +120,7 @@ MSK.ScaleformAnnounce = function(header, text, typ, duration) end MSK.Scaleform = MSK.ScaleformAnnounce exports('ScaleformAnnounce', MSK.ScaleformAnnounce) +RegisterNetEvent("msk_core:scaleformNotification", MSK.ScaleformAnnounce) MSK.Subtitle = function(text, duration) BeginTextCommandPrint('STRING') @@ -124,6 +128,7 @@ MSK.Subtitle = function(text, duration) EndTextCommandPrint(duration or 8000, true) end exports('Subtitle', MSK.Subtitle) +RegisterNetEvent("msk_core:subtitle", MSK.Subtitle) MSK.Spinner = function(text, typ, duration) BeginTextCommandBusyspinnerOn('STRING') @@ -135,6 +140,7 @@ MSK.Spinner = function(text, typ, duration) end) end exports('Spinner', MSK.Spinner) +RegisterNetEvent("msk_core:spinner", MSK.Spinner) MSK.Draw3DText = function(coords, text, size, font) local coords = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) @@ -160,10 +166,33 @@ MSK.Draw3DText = function(coords, text, size, font) ClearDrawOrigin() end exports('Draw3DText', MSK.Draw3DText) +RegisterNetEvent("msk_core:draw3DText", MSK.Draw3DText) + +MSK.DrawGenericText = function(text, outline, font, size, color, position) + if not font then font = 0 end + if not size then size = 0.34 end + if not color then color = {r = 255, g = 255, b = 255, a = 255} end + if not position then position = {height = 0.90, width = 0.50} end + + SetTextColour(color.r, color.g, color.b, color.a) + SetTextFont(font) + SetTextScale(size, size) + SetTextWrap(0.0, 1.0) + SetTextCentre(true) + SetTextDropshadow(0, 0, 0, 0, 255) + SetTextEdge(1, 0, 0, 0, 205) + if outline then SetTextOutline() end + BeginTextCommandDisplayText("STRING") + AddTextComponentSubstringPlayerName(text) + EndTextCommandDisplayText(position.width, position.height) +end +exports('DrawGenericText', MSK.DrawGenericText) +RegisterNetEvent("msk_core:drawGenericText", MSK.DrawGenericText) MSK.HasItem = function(item) if Config.Framework == 'standalone' then - return logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem')) + logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem')) + return end local hasItem = MSK.Trigger('msk_core:hasItem', item) @@ -197,6 +226,38 @@ MSK.IsVehicleEmpty = function(vehicle) end exports('IsVehicleEmpty', MSK.IsVehicleEmpty) +MSK.IsSpawnPointClear = function(coords, maxDistance) + local nearbyVehicles = {} + + if coords then + coords = vector3(coords.x, coords.y, coords.z) + else + coords = GetEntityCoords(PlayerPedId()) + end + + for k, vehicle in pairs(GetGamePool('CVehicle')) do + local distance = #(coords - GetEntityCoords(vehicle)) + + if distance <= maxDistance then + nearbyVehicles[#nearbyVehicles + 1] = vehicle + end + end + + return #nearbyVehicles == 0 +end +exports('IsSpawnPointClear', MSK.IsSpawnPointClear) + +MSK.GetPedVehicleSeat = function(ped, vehicle) + if not ped then ped = PlayerPedId() end + if not vehicle then GetVehiclePedIsIn(ped, false) end + + for i = -1, 16 do + if (GetPedInVehicleSeat(vehicle, i) == ped) then return i end + end + return -1 +end +exports('GetPedVehicleSeat', MSK.GetPedVehicleSeat) + MSK.GetPedMugshot = function(ped, transparent) if not DoesEntityExist(ped) then return end local mugshot = transparent and RegisterPedheadshotTransparent(ped) or RegisterPedheadshot(ped) @@ -220,6 +281,7 @@ end MSK.ProgressStart = MSK.Progressbar -- Support for old Scripts exports('Progressbar', MSK.Progressbar) exports('ProgressStart', MSK.Progressbar) -- Support for old Scripts +RegisterNetEvent("msk_core:progressbar", MSK.Progressbar) MSK.ProgressStop = function() SendNUIMessage({ @@ -227,23 +289,26 @@ MSK.ProgressStop = function() }) end exports('ProgressStop', MSK.ProgressStop) +RegisterNetEvent("msk_core:progressbarStop", MSK.ProgressStop) -RegisterNetEvent("msk_core:notification", function(title, message, typ, time) - MSK.Notification(title, message, typ, time) -end) - -RegisterNetEvent('msk_core:advancedNotification', function(text, title, subtitle, icon, flash, icontype) - MSK.AdvancedNotification(text, title, subtitle, icon, flash, icontype) -end) - -RegisterNetEvent("msk_core:scaleformNotification", function(title, message, typ, duration) - MSK.ScaleformAnnounce(title, message, typ, duration) -end) - -RegisterNetEvent("msk_core:subtitle", function(message, duration) - MSK.Subtitle(message, duration) -end) +MSK.LoadAnimDict = function(dict) + if not HasAnimDictLoaded(dict) then + RequestAnimDict(dict) -RegisterNetEvent("msk_core:spinner", function(text, typ, duration) - MSK.Spinner(text, typ, duration) -end) \ No newline at end of file + while not HasAnimDictLoaded(dict) do + Wait(1) + end + end +end +exports('LoadAnimDict', MSK.LoadAnimDict) + +MSK.LoadModel = function(modelHash) + if not HasModelLoaded(modelHash) then + RequestModel(modelHash) + + while not HasModelLoaded(modelHash) do + Wait(1) + end + end +end +exports('LoadModel', MSK.LoadModel) \ No newline at end of file diff --git a/config.lua b/config.lua index 4ecd35d..f4c0a8f 100644 --- a/config.lua +++ b/config.lua @@ -6,7 +6,6 @@ Config.VersionChecker = true -- Only Required for MSK.RegisterCommand and MSK.HasItem // View Docu for more Information about that! Config.Framework = 'esx' -- Set to 'standalone', 'esx' or 'qbcore' ---------------------------------------------------------------- --- /coords Config.showCoords = { enable = true, command = 'coords', diff --git a/fxmanifest.lua b/fxmanifest.lua index 647b25b..4fc2e54 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ games { 'gta5' } author 'Musiker15 - MSK Scripts' name 'msk_core' description 'Core functions for MSK Scripts' -version '2.2.0' +version '2.3.0' lua54 'yes' diff --git a/server/main.lua b/server/main.lua index 4f4be0e..2f83948 100644 --- a/server/main.lua +++ b/server/main.lua @@ -11,92 +11,6 @@ exports('getCoreObject', function() end) local RegisteredCommands = {} -MSK.RegisterCommand = function(name, group, cb, console, framework, suggestion) - if type(name) == 'table' then - for k, v in ipairs(name) do - MSK.RegisterCommand(v, group, cb, console, framework, suggestion) - end - return - end - - if RegisteredCommands[name] then - logging('debug', ('Command ^3%s^0 is already registerd. Overriding Command...'):format(name)) - end - - local added = addChatSuggestions(name, suggestion) - while not added do Wait(1) end - - RegisteredCommands[name] = {group = group, cb = cb, console = console, suggestion = suggestion} - - RegisterCommand(name, function(source, args, rawCommand) - local source = source - local Command, error = RegisteredCommands[name], nil - - if not Command.console and source == 0 then - logging('error', 'You can not run this Command in Server Console!') - else - if Command.suggestion and Command.suggestion.arguments then - local newArgs = {} - - for k, v in ipairs(Command.suggestion.arguments) do - if v.action == 'number' then - if args[k] then - if tonumber(args[k]) then - newArgs[v.name] = args[k] - else - error = ('Argument %s is not a number!'):format(v.name) - end - end - elseif v.action == 'playerId' then - if args[k] then - local targetId = args[k] - if targetId == 'me' then targetId = source end - - if tonumber(targetId) > 0 and doesPlayerIdExist(targetId) then - newArgs[v.name] = targetId - else - error = ('PlayerId %s does not exist!'):format(targetId) - end - end - else - newArgs[v.name] = args[k] - end - - if not error and not newArgs[v.name] and v.val then - error = ('Argument Mismatch with Argument %s'):format(v.name) - end - if error then break end - end - - args = newArgs - end - - if error then - if source == 0 then - logging('error', error) - else - MSK.Notification(source, error) - end - else - if Config.Framework ~= 'standalone' and framework then - local Player = MSK.GetPlayer({source = source}) - cb(Player, args, rawCommand) - else - cb(source, args, rawCommand) - end - end - end - end, true) - - if type(group) == 'table' then - for k, v in ipairs(group) do - ExecuteCommand(('add_ace group.%s command.%s allow'):format(v, name)) - end - else - ExecuteCommand(('add_ace group.%s command.%s allow'):format(group, name)) - end -end -exports('RegisterCommand', MSK.RegisterCommand) MSK.Notification = function(src, title, message, info, time) if not src or src == 0 then return end @@ -105,6 +19,13 @@ end MSK.Notify = MSK.Notification exports('Notification', MSK.Notification) +MSK.HelpNotification = function(src, text) + if not src or src == 0 then return end + TriggerClientEvent('msk_core:helpNotification', src, text) +end +MSK.HelpNotify = MSK.HelpNotification +exports('HelpNotification', MSK.HelpNotification) + MSK.AdvancedNotification = function(src, text, title, subtitle, icon, flash, icontype) if not src or src == 0 then return end TriggerClientEvent('msk_core:advancedNotification', src, text, title, subtitle, icon, flash, icontype) @@ -131,6 +52,82 @@ MSK.Spinner = function(src, text, typ, duration) end exports('Spinner', MSK.Spinner) +MSK.Draw3DText = function(src, coords, text, size, font) + if not src or src == 0 then return end + TriggerClientEvent('msk_core:draw3DText', src, coords, text, size, font) +end +exports('Draw3DText', MSK.Draw3DText) + +MSK.DrawGenericText = function(src, text, outline, font, size, color, position) + if not src or src == 0 then return end + TriggerClientEvent('msk_core:drawGenericText', src, text, outline, font, size, color, position) +end +exports('DrawGenericText', MSK.DrawGenericText) + +MSK.Progressbar = function(src, time, text, color) + if not src or src == 0 then return end + TriggerClientEvent('msk_core:progressbar', src, time, text, color) +end +exports('Progressbar', MSK.Progressbar) + +MSK.ProgressStop = function(src) + if not src or src == 0 then return end + TriggerClientEvent('msk_core:progressbarStop', src) +end +exports('ProgressStop', MSK.ProgressStop) + +MSK.Input = function(src, header, placeholder, field) + return MSK.Trigger('msk_core:input', src, header, placeholder, field) +end +exports('Input', MSK.Input) + +MSK.CloseInput = function(src) + if not src or src == 0 then return end + TriggerClientEvent('msk_core:closeInput', src) +end +exports('CloseInput', MSK.CloseInput) + +MSK.Numpad = function(src, pin, show) + return MSK.Trigger('msk_core:numpad', src, pin, show) +end +exports('Numpad', MSK.Numpad) + +MSK.CloseNumpad = function(src) + if not src or src == 0 then return end + TriggerClientEvent('msk_core:closeNumpad', src) +end +exports('CloseNumpad', MSK.CloseNumpad) + +MSK.IsSpawnPointClear = function(coords, maxDistance) + if not coords then return end + if not maxDistance then maxDistance = 5.0 end + + local nearbyVehicles = {} + coords = vector3(coords.x, coords.y, coords.z) + + for k, vehicle in pairs(GetAllVehicles()) do + local distance = #(coords - GetEntityCoords(vehicle)) + + if distance <= maxDistance then + nearbyVehicles[#nearbyVehicles + 1] = vehicle + end + end + + return #nearbyVehicles == 0 +end +exports('IsSpawnPointClear', MSK.IsSpawnPointClear) + +MSK.GetPedVehicleSeat = function(ped, vehicle) + if not ped then return end + if not vehicle then GetVehiclePedIsIn(ped, false) end + + for i = -1, 16 do + if (GetPedInVehicleSeat(vehicle, i) == ped) then return i end + end + return -1 +end +exports('GetPedVehicleSeat', MSK.GetPedVehicleSeat) + MSK.AddWebhook = function(webhook, botColor, botName, botAvatar, title, description, fields, footer, time) local content = {} @@ -176,9 +173,14 @@ end exports('AddWebhook', MSK.AddWebhook) MSK.HasItem = function(Player, item) - if not Player then logging('error', 'Player on Function MSK.HasItem does not exist!') return end + if not Player then + logging('error', 'Player on Function MSK.HasItem does not exist!') + return + end + if Config.Framework == 'standalone' then - return logging('error', ('Function %s can not used without Framework!'):format('^3MSK.HasItem^0')) + logging('error', ('Function %s can not used without Framework!'):format('^3MSK.HasItem^0')) + return end local hasItem @@ -192,6 +194,93 @@ MSK.HasItem = function(Player, item) end exports('HasItem', MSK.HasItem) +MSK.RegisterCommand = function(name, group, cb, console, framework, suggestion) + if type(name) == 'table' then + for k, v in ipairs(name) do + MSK.RegisterCommand(v, group, cb, console, framework, suggestion) + end + return + end + + if RegisteredCommands[name] then + logging('debug', ('Command ^3%s^0 is already registerd. Overriding Command...'):format(name)) + end + + local added = addChatSuggestions(name, suggestion) + while not added do Wait(1) end + + RegisteredCommands[name] = {group = group, cb = cb, console = console, suggestion = suggestion} + + RegisterCommand(name, function(source, args, rawCommand) + local source = source + local Command, error = RegisteredCommands[name], nil + + if not Command.console and source == 0 then + logging('error', 'You can not run this Command in Server Console!') + else + if Command.suggestion and Command.suggestion.arguments then + local newArgs = {} + + for k, v in ipairs(Command.suggestion.arguments) do + if v.action == 'number' then + if args[k] then + if tonumber(args[k]) then + newArgs[v.name] = args[k] + else + error = ('Argument %s is not a number!'):format(v.name) + end + end + elseif v.action == 'playerId' then + if args[k] then + local targetId = args[k] + if targetId == 'me' then targetId = source end + + if tonumber(targetId) > 0 and doesPlayerIdExist(targetId) then + newArgs[v.name] = targetId + else + error = ('PlayerId %s does not exist!'):format(targetId) + end + end + else + newArgs[v.name] = args[k] + end + + if not error and not newArgs[v.name] and v.val then + error = ('Argument Mismatch with Argument %s'):format(v.name) + end + if error then break end + end + + args = newArgs + end + + if error then + if source == 0 then + logging('error', error) + else + MSK.Notification(source, error) + end + else + if Config.Framework ~= 'standalone' and framework then + local Player = MSK.GetPlayer({source = source}) + cb(Player, args, rawCommand) + else + cb(source, args, rawCommand) + end + end + end + end, true) + + if type(group) == 'table' then + for k, v in ipairs(group) do + ExecuteCommand(('add_ace group.%s command.%s allow'):format(v, name)) + end + else + ExecuteCommand(('add_ace group.%s command.%s allow'):format(group, name)) + end +end +exports('RegisterCommand', MSK.RegisterCommand) + doesPlayerIdExist = function(playerId) for k, id in pairs(GetPlayers()) do if id == playerId then diff --git a/server/sv_bansystem.lua b/server/sv_bansystem.lua index ddd7c0f..712587c 100644 --- a/server/sv_bansystem.lua +++ b/server/sv_bansystem.lua @@ -28,7 +28,7 @@ unbanLog = function(source, unbannedby, banId) local botName = Config.BanSystem.botName local botAvatar = Config.BanSystem.botAvatar local title = "MSK Bansystem" - local description = ('Player %s (ID: %s) unbanned BanID %s'):format(unbannedby, source or 0, banId) + local description = ('Player %s (ID: %s) unbanned. BanID %s'):format(unbannedby, source or 0, banId) local fields = false local footer = { text = "© MSK Scripts", diff --git a/server/sv_showCoords.lua b/server/sv_showCoords.lua index 1b4a3ae..fbc4aed 100644 --- a/server/sv_showCoords.lua +++ b/server/sv_showCoords.lua @@ -1,5 +1,16 @@ if Config.showCoords.enable then MSK.RegisterCommand(Config.showCoords.command, Config.showCoords.groups, function(source, args, rawCommand) - TriggerClientEvent('msk_core:showCoords', source) + MSK.ShowCoords(source) end, false --[[console]], false --[[framework]], {help = 'Show your own Coords'}) -end \ No newline at end of file +end + +MSK.ShowCoords = function(src) + TriggerClientEvent('msk_core:showCoords', src) +end +exports('ShowCoords', MSK.ShowCoords) + +MSK.DoesShowCoords = function(src) + if not src or src == 0 then return end + return MSK.Trigger('msk_core:doesShowCoords', src) +end +exports('DoesShowCoords', MSK.DoesShowCoords) \ No newline at end of file diff --git a/shared/shared.lua b/shared/shared.lua index d11c455..b0cc940 100644 --- a/shared/shared.lua +++ b/shared/shared.lua @@ -7,11 +7,17 @@ for i = 97, 122 do table.insert(Charset, string.char(i)) end MSK.GetRandomString = function(length) math.randomseed(GetGameTimer()) - return length > 0 and ESX.GetRandomString(length - 1) .. Charset[math.random(1, #Charset)] or '' + return length > 0 and MSK.GetRandomString(length - 1) .. Charset[math.random(1, #Charset)] or '' end -MSK.GetRandomLetter = MSK.GetRandomString -- Support for old Scripts +MSK.GetRandomLetter = MSK.GetRandomString -- Support for old Versions exports('GetRandomString', MSK.GetRandomString) +MSK.GetConfig = function() + return Config +end +exports('GetConfig', MSK.GetConfig) +exports('getConfig', MSK.GetConfig) -- Support for old Versions + MSK.Round = function(num, decimal) return tonumber(string.format("%." .. (decimal or 0) .. "f", num)) end @@ -34,27 +40,28 @@ MSK.Split = function(str, delimiter) end exports('Split', MSK.Split) -MSK.TableContains = function(table, value) - if not table or not value then return end +MSK.TableContains = function(tbl, val) + if not tbl then return end + if not val then return end - if type(value) == 'table' then - for k, v in pairs(table) do - for k2, v2 in pairs(value) do + if type(val) == 'table' then + for k, v in pairs(tbl) do + for k2, v2 in pairs(val) do if v == v2 then return true end end end else - for k, v in pairs(table) do - if v == value then + for k, v in pairs(tbl) do + if v == val then return true end end end return false end -MSK.Table_Contains = MSK.TableContains -- Support for old Scripts +MSK.Table_Contains = MSK.TableContains -- Support for old Versions exports('TableContains', MSK.TableContains) MSK.Comma = function(int, tag) @@ -78,21 +85,26 @@ MSK.SetTimeout = function(ms, cb) local requestId = Timeout + 1 SetTimeout(ms, function() - if Timeouts[requestId] then Timeouts[requestId] = nil return end + if Timeouts[requestId] then + Timeouts[requestId] = nil + return + end + cb() end) Timeout = requestId return requestId end -MSK.AddTimeout = MSK.SetTimeout -- Support for old Scripts +MSK.AddTimeout = MSK.SetTimeout -- Support for old Versions exports('SetTimeout', MSK.SetTimeout) -MSK.DelTimeout = function(requestId) +MSK.ClearTimeout = function(requestId) if not requestId then return end Timeouts[requestId] = true end -exports('DelTimeout', MSK.DelTimeout) +exports('ClearTimeout', MSK.ClearTimeout) +exports('DelTimeout', MSK.ClearTimeout) -- Support for old Versions MSK.DumpTable = function(tbl, n) if not n then n = 0 end @@ -115,7 +127,7 @@ MSK.Logging = function(code, ...) local script = "[^2"..GetInvokingResource().."^0]" if not MSK.TableContains({'error', 'debug', 'info'}, code) then - -- Support for old Scripts + -- Support for old Versions script = code local action = ... local args = {...} @@ -126,15 +138,9 @@ MSK.Logging = function(code, ...) print(script, Config.LoggingTypes[code], ...) end end -MSK.logging = MSK.Logging -- Support for old Scripts +MSK.logging = MSK.Logging -- Support for old Versions exports('Logging', MSK.Logging) -MSK.GetConfig = function() - return Config -end -exports('GetConfig', MSK.GetConfig) -exports('getConfig', MSK.GetConfig) -- Support for old Scripts - logging = function(code, ...) if not Config.Debug then return end print(Config.LoggingTypes[code], ...)