Skip to content

Commit

Permalink
Update v1.4.0
Browse files Browse the repository at this point in the history
* Added more options for Config.StayActivated
* Added option to deactivate Panicbutton completely
* Removed some unnecessary code
  • Loading branch information
Musiker15 committed May 28, 2024
1 parent dd14b2a commit 0b8ae9c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 71 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.7
1.4.0
25 changes: 5 additions & 20 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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, ...)
Expand Down
20 changes: 13 additions & 7 deletions config.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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
Expand All @@ -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},
}
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
77 changes: 35 additions & 42 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)] = {
Expand All @@ -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)
Expand All @@ -91,46 +94,52 @@ 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)
local src = source
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)
Expand Down Expand Up @@ -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)
Expand All @@ -228,9 +223,7 @@ GithubUpdater = function()
print("###############################")
end)
else
print("###############################")
print(resourceName .. '^2 ✓ Resource loaded^0')
print("###############################")
end
end
GithubUpdater()
4 changes: 4 additions & 0 deletions translations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
}
}

0 comments on commit 0b8ae9c

Please sign in to comment.