diff --git a/VERSION b/VERSION index aaf8be7..6f96ed0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.5 \ No newline at end of file +1.3.6 \ No newline at end of file diff --git a/client.lua b/client.lua index 2e4b469..7e6a21c 100644 --- a/client.lua +++ b/client.lua @@ -5,36 +5,12 @@ AddEventHandler('esx:onPlayerDeath', function() TriggerServerEvent('msk_jobGPS:setDeath') end) -RegisterNetEvent('msk_jobGPS:activateGPS') AddEventHandler('msk_jobGPS:activateGPS', function(GPS) isActivated = true - addBlips(GPS) end) -RegisterNetEvent('msk_jobGPS:deactivateGPS') AddEventHandler('msk_jobGPS:deactivateGPS', function() isActivated = false - removeBlips() -end) - -RegisterNetEvent('msk_jobGPS:refreshBlips') -AddEventHandler('msk_jobGPS:refreshBlips', function(GPS) - refreshBlips(GPS) -end) - -RegisterNetEvent('msk_jobGPS:deactivateGPSById') -AddEventHandler('msk_jobGPS:deactivateGPSById', function(source) - logging('debug', 'Deactivating Blip by ID') - if not activeBlips[source] then return end - - for k, blip in pairs(Blips) do - if activeBlips[source].blip == blip then - table.remove(k) - end - end - - RemoveBlip(activeBlips[source].blip) - activeBlips[source] = nil end) if Config.Commands.panicbutton.enable then @@ -60,14 +36,16 @@ end RegisterNetEvent('msk_jobGPS:activatePanicbutton') AddEventHandler('msk_jobGPS:activatePanicbutton', function(xPlayer) - if activeBlips[xPlayer.source] then SetBlipColour(activeBlips[xPlayer.source].blip, Config.Panicbutton.blipColor) end + local playerId = tonumber(xPlayer.source) + + if activeBlips[playerId] then SetBlipColour(activeBlips[playerId].blip, Config.Panicbutton.blipColor) end SetNewWaypoint(xPlayer.coords.x, xPlayer.coords.y) end) addBlips = function(GPS) for playerId, v in pairs(GPS) do - logging('debug', job, playerId, v) - -- v = xPlayer, playerPed, netId, heading + logging('debug', playerId, v) + -- v = xPlayer, netId, coords, heading local xPlayer = v.xPlayer if ESX.PlayerData.identifier ~= xPlayer.identifier then @@ -83,7 +61,8 @@ addBlips = function(GPS) AddTextEntry("BLIP_OTHPLYR", Config.GPS.blip.prefix) SetBlipCategory(blip, 7) - -- ShowNumberOnBlip(blip, playerId) + ShowOutlineIndicatorOnBlip(blip, true) + SetBlipSecondaryColour(blip, 255, 0, 0) ShowHeadingIndicatorOnBlip(blip, true) AddTextEntry("NAME_" .. xPlayer.name, "~a~") @@ -91,16 +70,14 @@ addBlips = function(GPS) AddTextComponentString(xPlayer.name) EndTextCommandSetBlipName(blip) - table.insert(Blips, {blip = blip, source = playerId}) + Blips[#Blips + 1] = blip activeBlips[playerId] = {isActive = false, blip = blip} end end end +RegisterNetEvent('msk_jobGPS:activateGPS', addBlips) addBlip = function(GPS, xPlayer, heading) - logging('debug', 'addBlip') - if ESX.PlayerData.identifier == xPlayer.identifier then return end - logging('debug', 'Add Blip for ' .. xPlayer.source) local blip = AddBlipForCoord(xPlayer.coords.x, xPlayer.coords.y, xPlayer.coords.z) @@ -114,7 +91,8 @@ addBlip = function(GPS, xPlayer, heading) AddTextEntry("BLIP_OTHPLYR", Config.GPS.blip.prefix) SetBlipCategory(blip, 7) - -- ShowNumberOnBlip(blip, xPlayer.source) + ShowOutlineIndicatorOnBlip(blip, true) + SetBlipSecondaryColour(blip, 255, 0, 0) ShowHeadingIndicatorOnBlip(blip, true) AddTextEntry("NAME_" .. xPlayer.name, "~a~") @@ -122,43 +100,32 @@ addBlip = function(GPS, xPlayer, heading) AddTextComponentString(xPlayer.name) EndTextCommandSetBlipName(blip) - table.insert(Blips, {blip = blip, source = xPlayer.source}) - activeBlips[xPlayer.source] = {isActive = false, blip = blip} -end - -removeBlips = function() - logging('debug', 'removeBlips') - - for k, blip in pairs(Blips) do - RemoveBlip(blip.blip) - end - - Blips = {} - activeBlips = {} + Blips[#Blips + 1] = blip + activeBlips[tonumber(xPlayer.source)] = {isActive = false, blip = blip} end refreshBlips = function(GPS) logging('debug', 'refreshBlips') for playerId, v in pairs(GPS) do - -- v = xPlayer, netId, heading + -- v = xPlayer, netId, coords, heading local xPlayer = v.xPlayer if ESX.PlayerData.identifier ~= xPlayer.identifier then if not activeBlips[playerId] then addBlip(GPS, xPlayer, v.heading) end logging('debug', 'Blip is active') - local inOneSync = inOneSync(v.netId) + local OneSync = inOneSync(v.netId) - if inOneSync and not activeBlips[playerId].isActive then + if OneSync and not activeBlips[playerId].isActive then logging('debug', 'inOneSync') - + CreateThread(function() activeBlips[playerId].isActive = true - while activeBlips[playerId] and activeBlips[playerId].isActive and DoesEntityExist(inOneSync.ped) do - local coords = GetEntityCoords(inOneSync.ped) - local heading = math.ceil(GetEntityHeading(inOneSync.ped)) + while activeBlips[playerId] and activeBlips[playerId].isActive and DoesEntityExist(OneSync.ped) do + local coords = GetEntityCoords(OneSync.ped) + local heading = math.ceil(GetEntityHeading(OneSync.ped)) SetBlipCoords(activeBlips[playerId].blip, coords.x, coords.y, coords.z) SetBlipRotation(activeBlips[playerId].blip, heading) @@ -166,7 +133,7 @@ refreshBlips = function(GPS) Wait(0) end end) - elseif not inOneSync then + elseif not OneSync then logging('debug', 'not inOneSync') activeBlips[playerId].isActive = false @@ -176,6 +143,44 @@ refreshBlips = function(GPS) end end end +RegisterNetEvent('msk_jobGPS:refreshBlips', refreshBlips) + +removeBlips = function() + logging('debug', 'removeBlips') + + for k, blip in pairs(Blips) do + RemoveBlip(blip) + end + + Blips = {} + activeBlips = {} +end +RegisterNetEvent('msk_jobGPS:deactivateGPS', removeBlips) + +removeBlipById = function(playerId, leftServer) + if not activeBlips[playerId] then return end + if Config.StayActivated.enable then + activeBlips[playerId].isActive = false + + if leftServer then + SetBlipColour(activeBlips[playerId].blip, 40) + end + + Wait(Config.StayActivated.seconds * 1000) + end + logging('debug', 'Deactivating Blip by ID for ID: ' .. playerId) + + for k, blip in pairs(Blips) do + if activeBlips[playerId].blip == blip then + Blips[k] = nil + break + end + end + + RemoveBlip(activeBlips[playerId].blip) + activeBlips[playerId] = nil +end +RegisterNetEvent('msk_jobGPS:deactivateGPSById', removeBlipById) inOneSync = function(netId) local playerPed = NetworkDoesNetworkIdExist(netId) and NetworkGetEntityFromNetworkId(netId) @@ -200,5 +205,5 @@ end logging = function(code, ...) if not Config.Debug then return end - MSK.logging(code, ...) + MSK.Logging(code, ...) end \ No newline at end of file diff --git a/config.lua b/config.lua index 84dcb08..d4bf94b 100644 --- a/config.lua +++ b/config.lua @@ -1,7 +1,8 @@ Config = {} ---------------------------------------------------------------- -Config.VersionChecker = true +Config.Locale = 'de' Config.Debug = true +Config.VersionChecker = true ---------------------------------------------------------------- -- !!! This function is clientside AND serverside !!! Config.Notification = function(source, message) @@ -29,7 +30,6 @@ Config.Panicbutton = { 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 - notifyNearestPlayers = true, } ---------------------------------------------------------------- diff --git a/fxmanifest.lua b/fxmanifest.lua index faf56e0..e35d9d4 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,12 +4,13 @@ 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.5' +version '1.3.6' shared_script { '@es_extended/imports.lua', '@msk_core/import.lua', - 'config.lua' + 'config.lua', + 'translations.lua' } client_scripts { diff --git a/server.lua b/server.lua index b53a827..9b78113 100644 --- a/server.lua +++ b/server.lua @@ -21,39 +21,37 @@ if Config.Panicbutton.item.enable then end) end -RegisterNetEvent('msk_jobGPS:togglePanicbutton') -AddEventHandler('msk_jobGPS:togglePanicbutton', function() +RegisterNetEvent('msk_jobGPS:togglePanicbutton', function() local src = source togglePanicbutton(src) end) -RegisterNetEvent('msk_jobGPS:notifyNearestPlayers') -AddEventHandler('msk_jobGPS:notifyNearestPlayers', function(playerId) - Config.Notification(playerId, 'The Player has activated the Panicbutton') +RegisterNetEvent('msk_jobGPS:notifyNearestPlayers', function(playerId) + Config.Notification(playerId, Translation[Config.Locale]['panic_activated']:format('Der Spieler')) end) togglePanicbutton = function(source) local src = source local xPlayer = ESX.GetPlayerFromId(src) - local canUseItem = false + local canUseItem = true if not isAllowed(xPlayer, 'panic') then return end + if Config.Panicbutton.item.enable then - local hasItem = xPlayer.getInventoryItem(Config.Panicbutton.item.item) + local hasItem = xPlayer.hasItem(Config.Panicbutton.item.item) - if hasItem and hasItem.count > 0 then canUseItem = true end - else - canUseItem = true + if not hasItem or hasItem and hasItem.count == 0 then + canUseItem = false + end end - if not GPS[xPlayer.job.name][xPlayer.source] then canUseItem = false end - if not canUseItem then return Config.Notification(src, 'You have to active GPS first') 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 - local xPlayers = ESX.GetExtendedPlayers('job', xPlayer.job.name) - for k, xTarget in pairs(xPlayers) do - if GPS[xTarget.job.name][xTarget.source] and xTarget.source ~= xPlayer.source then - TriggerClientEvent('msk_jobGPS:activatePanicbutton', xTarget.source, xPlayer) - Config.Notification(xTarget.source, xPlayer.name .. ' activated the Panicbutton') + 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)) end end end @@ -64,27 +62,27 @@ ESX.RegisterUsableItem(Config.GPS.item, function(source) if not isAllowed(xPlayer, 'gps') then return end - if GPS[xPlayer.job.name][src] then - Config.Notification(src, 'GPS deactivated') + if GPS[xPlayer.job.name][tonumber(src)] then + Config.Notification(src, Transalation[Config.Locale]['gps_deactivated']) TriggerClientEvent('msk_jobGPS:deactivateGPS', src) removeBlipById(xPlayer) else - local playerPed = GetPlayerPed(src) - playerJobs[src] = xPlayer.job.name + local playerPed, playerJob = GetPlayerPed(src), xPlayer.job.name + playerJobs[tonumber(src)] = playerJob - for playerId, v in pairs(GPS[playerJobs[src]]) do - Config.Notification(playerId, ('%s activated the GPS'):format(xPlayer.name)) + for playerId, v in pairs(GPS[playerJob]) do + Config.Notification(playerId, Transalation[Config.Locale]['gps_activated_all']:format(xPlayer.name)) end - GPS[playerJobs[src]][src] = { + GPS[playerJob][tonumber(src)] = { xPlayer = xPlayer, netId = NetworkGetNetworkIdFromEntity(playerPed), coords = GetEntityCoords(playerPed), heading = math.ceil(GetEntityHeading(playerPed)) } - Config.Notification(src, 'GPS activated') - TriggerClientEvent('msk_jobGPS:activateGPS', src, GPS[playerJobs[src]]) + Config.Notification(src, Transalation[Config.Locale]['gps_activated']) + TriggerClientEvent('msk_jobGPS:activateGPS', src, GPS[playerJob]) end end) @@ -92,33 +90,32 @@ RegisterNetEvent('esx:playerLogout', function(source) local src = source local xPlayer = ESX.GetPlayerFromId(src) - removeBlipById(xPlayer) + removeBlipById(xPlayer, true) end) RegisterNetEvent('esx:playerDropped', function(playerId, reason) local src = playerId local xPlayer = ESX.GetPlayerFromId(src) - removeBlipById(xPlayer) + removeBlipById(xPlayer, true) 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[xPlayer.job.name] or not GPS[xPlayer.job.name][xPlayer.source] then return end + if not GPS[oldJob.name] or not GPS[oldJob.name][tonumber(src)] then return end - Config.Notification(src, 'GPS deactivated') + Config.Notification(src, Transalation[Config.Locale]['gps_deactivated']) TriggerClientEvent('msk_jobGPS:deactivateGPS', src) removeBlipById(xPlayer) end) -RegisterNetEvent('msk_jobGPS:setDeath') -AddEventHandler('msk_jobGPS:setDeath', function() +RegisterNetEvent('msk_jobGPS:setDeath', function() local src = source local xPlayer = ESX.GetPlayerFromId(src) - Config.Notification(src, 'GPS deactivated') + Config.Notification(src, Transalation[Config.Locale]['gps_deactivated']) TriggerClientEvent('msk_jobGPS:deactivateGPS', src) removeBlipById(xPlayer) end) @@ -130,6 +127,10 @@ AddEventHandler('esx:onRemoveInventoryItem', function(source, item, count) if item == Config.GPS.item and count == 0 then TriggerClientEvent('msk_jobGPS:deactivateGPS', src) removeBlipById(xPlayer) + + for playerId, v in pairs(GPS[playerJob]) do + Config.Notification(playerId, Transalation[Config.Locale]['gps_removed_inventory']:format(xPlayer.name)) + end end end) @@ -139,15 +140,16 @@ CreateThread(function() for job, players in pairs(GPS) do for playerId, info in pairs(players) do - -- info = xPlayer, netId, heading + -- info = xPlayer, netId, coords, heading local playerPed = GetPlayerPed(playerId) - info.coords = GetEntityCoords(playerPed) - info.heading = math.ceil(GetEntityHeading(playerPed)) + GPS[job][playerId].coords = GetEntityCoords(playerPed) + GPS[job][playerId].heading = math.ceil(GetEntityHeading(playerPed)) end end for k, playerId in pairs(GetPlayers()) do + playerId = tonumber(playerId) local playerJob = getPlayerJob(playerId) if GPS[playerJob] and GPS[playerJob][playerId] then @@ -160,41 +162,29 @@ CreateThread(function() end) getPlayerJob = function(playerId) - if playerJobs[playerId] then - return playerJobs[playerId] - end + playerId = tonumber(playerId) - local xPlayer = ESX.GetPlayerFromId(playerId) - if xPlayer then - playerJobs[playerId] = xPlayer.job.name - else - playerJobs[playerId] = 'unemployed' + if not playerJobs[playerId] then + local xPlayer = ESX.GetPlayerFromId(playerId) + + if xPlayer then + playerJobs[playerId] = xPlayer.job.name + end end - return playerJobs[playerId] + return playerJobs[playerId] or 'unemployed' end -removeBlipById = function(xPlayer) +removeBlipById = function(xPlayer, leftServer) local source, job = xPlayer.source, xPlayer.job.name - if GPS[job] and GPS[job][source] then - GPS[job][source] = nil - playerJobs[source] = nil + if GPS[job] and GPS[job][tonumber(source)] then + GPS[job][tonumber(source)] = nil + playerJobs[tonumber(source)] = nil for playerId, v in pairs(GPS[job]) do - Config.Notification(playerId, ('%s deactivated the GPS'):format(xPlayer.name)) - - if not Config.StayActivated.enable then - TriggerClientEvent('msk_jobGPS:deactivateGPSById', playerId, source) - end - end - - if Config.StayActivated.enable then - Wait(Config.StayActivated.seconds * 1000) - - for playerId, v in pairs(GPS[job]) do - TriggerClientEvent('msk_jobGPS:deactivateGPSById', playerId, source) - end + Config.Notification(playerId, Transalation[Config.Locale]['gps_deactivated_all']:format(xPlayer.name)) + TriggerClientEvent('msk_jobGPS:deactivateGPSById', playerId, tonumber(source), leftServer) end end end diff --git a/translations.lua b/translations.lua new file mode 100644 index 0000000..2f34d94 --- /dev/null +++ b/translations.lua @@ -0,0 +1,22 @@ +Transalation = { + ['de'] = { + ['gps_activated'] = 'Du hast dein GPS aktiviert', + ['gps_deactivated'] = 'Du hast dein GPS deaktiviert', + ['gps_activated_all'] = '%s hat das GPS aktiviert', + ['gps_deactivated_all'] = '%s hat das GPS deaktiviert', + ['gps_removed_inventory'] = '%s wurde das GPS abgenommen!', + + ['panic_activate_GPS'] = 'Du musst erst dein GPS aktivieren!', + ['panic_activated'] = '%s hat den Panicbutton ausgelöst!', + }, + ['en'] = { + ['gps_activated'] = 'You activated the GPS', + ['gps_deactivated'] = 'You deactivated the GPS', + ['gps_activated_all'] = '%s activated the GPS', + ['gps_deactivated_all'] = '%s deactivated the GPS', + ['gps_removed_inventory'] = 'The GPS was removed from %s!', + + ['panic_activate_GPS'] = 'You have to active GPS first!', + ['panic_activated'] = '%s has activated Panicbutton!', + } +} \ No newline at end of file