From 0b8ae9c0572da3dc7208791efecb8a441e0b6d75 Mon Sep 17 00:00:00 2001 From: Musiker15 Date: Tue, 28 May 2024 11:50:42 +0200 Subject: [PATCH] Update v1.4.0 * Added more options for Config.StayActivated * Added option to deactivate Panicbutton completely * Removed some unnecessary code --- VERSION | 2 +- client.lua | 25 ++++------------ config.lua | 20 ++++++++----- fxmanifest.lua | 2 +- server.lua | 77 ++++++++++++++++++++++-------------------------- translations.lua | 4 +++ 6 files changed, 59 insertions(+), 71 deletions(-) diff --git a/VERSION b/VERSION index 8ed486a..e21e727 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.7 \ No newline at end of file +1.4.0 \ No newline at end of file diff --git a/client.lua b/client.lua index b19a732..7b50643 100644 --- a/client.lua +++ b/client.lua @@ -13,7 +13,7 @@ AddEventHandler('msk_jobGPS:deactivateGPS', function() isActivated = false end) -if Config.Commands.panicbutton.enable then +if Config.Panicbutton.enable and Config.Commands.panicbutton.enable then RegisterCommand(Config.Commands.panicbutton.command, function() if not Config.allowedJobs[ESX.PlayerData.job.name] then return end if not Config.allowedJobs[ESX.PlayerData.job.name].panicbutton then return end @@ -157,17 +157,16 @@ removeBlips = function() end RegisterNetEvent('msk_jobGPS:deactivateGPS', removeBlips) -removeBlipById = function(playerId, leftServer) +removeBlipById = function(playerId, reason) if not activeBlips[playerId] then return end if Config.StayActivated.enable then activeBlips[playerId].isActive = false - - if leftServer then + + if Config.StayActivated[reason] then SetBlipColour(activeBlips[playerId].blip, 40) + Wait(Config.StayActivated.seconds * 1000) end - - Wait(Config.StayActivated.seconds * 1000) end logging('debug', 'Deactivating Blip by ID for ID: ' .. playerId) @@ -190,20 +189,6 @@ inOneSync = function(netId) return false end -isAllowed = function(xPlayer, action) - for job, v in pairs(Config.allowedJobs) do - if xPlayer.job.name == job then - if action == 'gps' and v.gps then - return true - elseif action == 'panic' and v.panicbutton then - return true - end - end - end - - return false -end - logging = function(code, ...) if not Config.Debug then return end MSK.Logging(code, ...) diff --git a/config.lua b/config.lua index d4bf94b..9351c80 100644 --- a/config.lua +++ b/config.lua @@ -1,23 +1,28 @@ Config = {} ---------------------------------------------------------------- Config.Locale = 'de' -Config.Debug = true +Config.Debug = false Config.VersionChecker = true ---------------------------------------------------------------- -- !!! This function is clientside AND serverside !!! -Config.Notification = function(source, message) +Config.Notification = function(source, message, info) if IsDuplicityVersion() then -- serverside - MSK.Notification(source, 'MSK JobGPS', message) + MSK.Notification(source, 'MSK JobGPS', message, info) else -- clientside - MSK.Notification('MSK JobGPS', message) + MSK.Notification('MSK JobGPS', message, info) end end ---------------------------------------------------------------- Config.StayActivated = { -- If set to true and someone deactivate the GPS then the Blip will be removed after X seconds. -- If set to false and someone deactivated the GPS then the Blip will be removed immediately. - enable = true, - seconds = 60 + enable = true, -- Set to false to deactivated this feature completely + seconds = 60, + + ['stayOnDeactivate'] = false, + ['stayOnLeaveServer'] = true, + ['stayOnDeath'] = true, + ['stayOnRemoveItem'] = true, } Config.GPS = { @@ -27,6 +32,7 @@ Config.GPS = { } Config.Panicbutton = { + enable = true, -- Set false to deactivated this feature completely item = {enable = false, item = 'panicbutton'}, -- You need that item in your inventory if set to true hotkey = {enable = true, key = 'f9'}, -- Command has to be activated // RegisterKeyMapping (https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/) blipColor = 1, -- This will change the Blipcolor of GPS Blip @@ -49,6 +55,6 @@ Config.allowedJobs = { ['vagos'] = {gps = true, panicbutton = false}, ['crips'] = {gps = true, panicbutton = false}, ['ballas'] = {gps = true, panicbutton = false}, - ['lm'] = {gps = true, panicbutton = false}, ['mg13'] = {gps = true, panicbutton = false}, + ['lm'] = {gps = true, panicbutton = false}, } \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index 3d31042..de91f14 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ games { 'gta5' } author 'Musiker15 - MSK Scripts' name 'msk_jobGPS' description 'Creates Blips for all players at the same job if they activate there gps' -version '1.3.7' +version '1.4.0' shared_script { '@es_extended/imports.lua', diff --git a/server.lua b/server.lua index f97434d..f24eef2 100644 --- a/server.lua +++ b/server.lua @@ -15,7 +15,7 @@ if Config.Commands.gps.enable then end) end -if Config.Panicbutton.item.enable then +if Config.Panicbutton.enable and Config.Panicbutton.item.enable then ESX.RegisterUsableItem(Config.Panicbutton.item.item, function(source) togglePanicbutton(source) end) @@ -26,16 +26,18 @@ RegisterNetEvent('msk_jobGPS:togglePanicbutton', function() togglePanicbutton(src) end) -RegisterNetEvent('msk_jobGPS:notifyNearestPlayers', function(playerId) - Config.Notification(playerId, Translation[Config.Locale]['panic_activated']:format('Der Spieler')) +RegisterNetEvent('msk_jobGPS:notifyNearestPlayers', function(targetId) + Config.Notification(targetId, Translation[Config.Locale]['panic_activated']:format(Translation[Config.Locale]['someone']), 'warning') end) togglePanicbutton = function(source) + if not Config.Panicbutton.enable then return end local src = source local xPlayer = ESX.GetPlayerFromId(src) local canUseItem = true - if not isAllowed(xPlayer, 'panic') then return end + if not Config.allowedJobs[xPlayer.job.name] then return end + if not Config.allowedJobs[xPlayer.job.name].panicbutton then return end if Config.Panicbutton.item.enable then local hasItem = xPlayer.hasItem(Config.Panicbutton.item.item) @@ -46,13 +48,13 @@ togglePanicbutton = function(source) end if not GPS[xPlayer.job.name][tonumber(src)] then canUseItem = false end - if not canUseItem then return Config.Notification(src, Translation[Config.Locale]['panic_activate_GPS']) end - Config.Notification(src, Translation[Config.Locale]['panic_pressed']) + if not canUseItem then return Config.Notification(src, Translation[Config.Locale]['panic_activate_GPS'], 'error') end + Config.Notification(src, Translation[Config.Locale]['panic_pressed'], 'info') for playerId, info in pairs(GPS[xPlayer.job.name]) do if tonumber(playerId) ~= tonumber(src) then TriggerClientEvent('msk_jobGPS:activatePanicbutton', playerId, xPlayer) - Config.Notification(playerId, Translation[Config.Locale]['panic_activated']:format(xPlayer.name)) + Config.Notification(playerId, Translation[Config.Locale]['panic_activated']:format(xPlayer.name), 'warning') end end end @@ -61,18 +63,19 @@ ESX.RegisterUsableItem(Config.GPS.item, function(source) local src = source local xPlayer = ESX.GetPlayerFromId(src) - if not isAllowed(xPlayer, 'gps') then return end + if not Config.allowedJobs[xPlayer.job.name] then return end + if not Config.allowedJobs[xPlayer.job.name].gps then return end if GPS[xPlayer.job.name][tonumber(src)] then - Config.Notification(src, Translation[Config.Locale]['gps_deactivated']) + Config.Notification(src, Translation[Config.Locale]['gps_deactivated'], 'info') TriggerClientEvent('msk_jobGPS:deactivateGPS', src) - removeBlipById(xPlayer) + removeBlipById(xPlayer, 'stayOnDeactivate') else local playerPed, playerJob = GetPlayerPed(src), xPlayer.job.name playerJobs[tonumber(src)] = playerJob for playerId, v in pairs(GPS[playerJob]) do - Config.Notification(playerId, Translation[Config.Locale]['gps_activated_all']:format(xPlayer.name)) + Config.Notification(playerId, Translation[Config.Locale]['gps_activated_all']:format(xPlayer.name), 'info') end GPS[playerJob][tonumber(src)] = { @@ -82,7 +85,7 @@ ESX.RegisterUsableItem(Config.GPS.item, function(source) heading = math.ceil(GetEntityHeading(playerPed)) } - Config.Notification(src, Translation[Config.Locale]['gps_activated']) + Config.Notification(src, Translation[Config.Locale]['gps_activated'], 'info') TriggerClientEvent('msk_jobGPS:activateGPS', src, GPS[playerJob]) end end) @@ -91,34 +94,37 @@ RegisterNetEvent('esx:playerLogout', function(source) local src = source local xPlayer = ESX.GetPlayerFromId(src) - removeBlipById(xPlayer, true) + removeBlipById(xPlayer, 'stayOnLeaveServer') end) RegisterNetEvent('esx:playerDropped', function(playerId, reason) local src = playerId local xPlayer = ESX.GetPlayerFromId(src) - removeBlipById(xPlayer, true) + removeBlipById(xPlayer, 'stayOnLeaveServer') end) RegisterNetEvent("esx:setJob", function(playerId, newJob, oldJob) if newJob.name == oldJob.name then return end local src = playerId local xPlayer = ESX.GetPlayerFromId(src) - if not GPS[oldJob.name] or not GPS[oldJob.name][tonumber(src)] then return end + if not GPS[oldJob.name] then return end + if not not GPS[oldJob.name][tonumber(src)] then return end - Config.Notification(src, Translation[Config.Locale]['gps_deactivated']) + Config.Notification(src, Translation[Config.Locale]['gps_deactivated'], 'info') TriggerClientEvent('msk_jobGPS:deactivateGPS', src) - removeBlipById(xPlayer) + removeBlipById(xPlayer, 'stayOnJobChange') end) RegisterNetEvent('msk_jobGPS:setDeath', function() local src = source local xPlayer = ESX.GetPlayerFromId(src) + if not GPS[xPlayer.job.name] then return end + if not GPS[xPlayer.job.name][tonumber(xPlayer.source)] then return end - Config.Notification(src, Translation[Config.Locale]['gps_deactivated']) + Config.Notification(src, Translation[Config.Locale]['gps_deactivated'], 'info') TriggerClientEvent('msk_jobGPS:deactivateGPS', src) - removeBlipById(xPlayer) + removeBlipById(xPlayer, 'stayOnDeath') end) AddEventHandler('esx:onRemoveInventoryItem', function(source, item, count) @@ -126,11 +132,14 @@ AddEventHandler('esx:onRemoveInventoryItem', function(source, item, count) local xPlayer = ESX.GetPlayerFromId(src) if item == Config.GPS.item and count == 0 then + if not GPS[xPlayer.job.name] then return end + if not GPS[xPlayer.job.name][tonumber(xPlayer.source)] then return end + TriggerClientEvent('msk_jobGPS:deactivateGPS', src) - removeBlipById(xPlayer) + removeBlipById(xPlayer, 'stayOnRemoveItem') for playerId, v in pairs(GPS[xPlayer.job.name]) do - Config.Notification(playerId, Translation[Config.Locale]['gps_removed_inventory']:format(xPlayer.name)) + Config.Notification(playerId, Translation[Config.Locale]['gps_removed_inventory']:format(xPlayer.name), 'warning') end end end) @@ -176,45 +185,31 @@ getPlayerJob = function(playerId) return playerJobs[playerId] or 'unemployed' end -removeBlipById = function(xPlayer, leftServer) +removeBlipById = function(xPlayer, reason) local source, job = xPlayer.source, xPlayer.job.name if GPS[job] and GPS[job][tonumber(source)] then GPS[job][tonumber(source)] = nil for playerId, v in pairs(GPS[job]) do - Config.Notification(playerId, Translation[Config.Locale]['gps_deactivated_all']:format(xPlayer.name)) - TriggerClientEvent('msk_jobGPS:deactivateGPSById', playerId, tonumber(source), leftServer) + Config.Notification(playerId, Translation[Config.Locale]['gps_deactivated_all']:format(xPlayer.name), 'info') + TriggerClientEvent('msk_jobGPS:deactivateGPSById', playerId, tonumber(source), reason) end end end -isAllowed = function(xPlayer, action) - for job, v in pairs(Config.allowedJobs) do - if xPlayer.job.name == job then - if action == 'gps' and v.gps then - return true - elseif action == 'panic' and v.panicbutton then - return true - end - end - end - - return false -end - logging = function(code, ...) if not Config.Debug then return end MSK.Logging(code, ...) end GithubUpdater = function() - GetCurrentVersion = function() + local GetCurrentVersion = function() return GetResourceMetadata( GetCurrentResourceName(), "version" ) end local CurrentVersion = GetCurrentVersion() - local resourceName = "^4["..GetCurrentResourceName().."]^0" + local resourceName = "[^2"..GetCurrentResourceName().."^0]" if Config.VersionChecker then PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_jobGPS/main/VERSION', function(Error, NewestVersion, Header) @@ -228,9 +223,7 @@ GithubUpdater = function() print("###############################") end) else - print("###############################") print(resourceName .. '^2 ✓ Resource loaded^0') - print("###############################") end end GithubUpdater() \ No newline at end of file diff --git a/translations.lua b/translations.lua index fe25a0b..1412f6a 100644 --- a/translations.lua +++ b/translations.lua @@ -9,6 +9,8 @@ Translation = { ['panic_pressed'] = 'Panicbutton gedrückt', ['panic_activate_GPS'] = 'Du musst erst dein GPS aktivieren!', ['panic_activated'] = '%s hat den Panicbutton ausgelöst!', + + ['someone'] = 'Jemand', }, ['en'] = { ['gps_activated'] = 'You activated the GPS', @@ -20,5 +22,7 @@ Translation = { ['panic_pressed'] = 'Panicbutton pressed', ['panic_activate_GPS'] = 'You have to active GPS first!', ['panic_activated'] = '%s has activated Panicbutton!', + + ['someone'] = 'Someone', } } \ No newline at end of file