Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: LEO alert customisation
  • Loading branch information
MrGriefs committed Nov 21, 2021
1 parent 83e9347 commit 62446d3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
config.lua
11 changes: 6 additions & 5 deletions client.lua
Expand Up @@ -157,12 +157,13 @@ RegisterNetEvent('seatbelt:ClientNotify', function(serverId)
local player = GetPlayerFromServerId(serverId)
local playerPed = GetPlayerPed(player) -- onesync notice: returns -1 if not loaded
if player ~= PlayerId() and IsLEO() and not IsHudHidden() and IsPedInAnyVehicle(playerPed) then
if #(GetEntityCoords(ped) - GetEntityCoords(GetPlayerPed(player))) < 19.999 then
local vehicle = GetVehiclePedIsIn(playerPed)
local identifier = GetPlayerIdentifier_(serverId, playerPed, vehicle)
if #(GetEntityCoords(ped) - GetEntityCoords(GetPlayerPed(player))) < Constants.Distance and identifier then
ShowNotification(
'<C>Player ' ..
serverId ..
'</C> is not weaing a seatbelt in <C>~y~' ..
GetVehicleNumberPlateText(GetVehiclePedIsIn(playerPed)) ..
identifier ..
' is not weaing a seatbelt in <C>~y~' ..
GetVehicleNumberPlateText(vehicle) ..
'~s~</C>.'
)
end
Expand Down
15 changes: 15 additions & 0 deletions config.lua
@@ -0,0 +1,15 @@
--- Configuration variables
--- @type table<string, any>
Config = {
--- Changes how players are identified to LEOs. Cannot be nilish
--- - `1` = Player ID (i.e. "Player 7")
--- - `2` = Seat position (i.e. "Driver", "Passenger", "Back left passenger", "Far back left passenger")
--- - `3` = Username (i.e. "Hagen Hyena", "1D-32 Backer P.")
--- @type number
PlayerIdentifierType = 1,


--- Distance which LEOs can detect seatbelt-less occupants within.
--- @type number
Distance = 20,
}
1 change: 1 addition & 0 deletions fxmanifest.lua
Expand Up @@ -8,6 +8,7 @@ author 'Reece Stokes <hagen@hyena.gay>'

client_script {
'@framework/util.lua',
'config.lua',
'util.lua',
'client.lua',
}
Expand Down
37 changes: 37 additions & 0 deletions util.lua
Expand Up @@ -25,6 +25,43 @@ else
end
end

-- config setup
Constants = {
Distance = Config.Distance + 0.0,
}

local GetPlayerIdentifierMethods = {
function(serverId)
return '<C>Player ' .. serverId .. '</C>'
end,
function(_, playerPed, vehicle)
local hash = GetEntityModel(vehicle)
local seats = GetVehicleModelNumberOfSeats(hash)
local names = {
'Driver',
'Passenger',
'Back left passenger',
'Back right passenger',
'Far back left passenger',
'Far back right passenger',
}
for seat = 1, math.min(#names, seats) do
if GetPedInVehicleSeat(vehicle, seat - 2) == playerPed then
return names[seat]
end
end
end,
function(serverId)
return '<C>' .. GetPlayerName(serverId) .. '</C>'
end,
}

--- GetPlayerIdentifier is a reserved namespace
GetPlayerIdentifier_ = GetPlayerIdentifierMethods[Config.PlayerIdentifierType]

GetPlayerIdentifierMethods = nil
Config = nil

function DoesPedVehicleHaveSeatbelt(ped)
return not (
not IsPedInAnyVehicle(ped)
Expand Down

0 comments on commit 62446d3

Please sign in to comment.