Skip to content

Commit

Permalink
Update csrp_client.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
harleykradovill authored Aug 15, 2024
1 parent c687e28 commit 90363fd
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions csrp_client.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
json = require("json")
-- Harley Kradovill
-- For use by Coastal State Roleplay
-- https://www.coastalstateroleplay.com/

-- Add command suggestions
json = require("json")
TriggerEvent('chat:addSuggestion', '/rti', 'Set a GPS route to your selected call', {})

TriggerEvent('chat:addSuggestion', '/vehreg', 'Register your current vehicle to your selected identity', {})

TriggerEvent('chat:addSuggestion', '/showid', 'Show your selected identity to nearby players', {})


local activeBlips = {}

RegisterCommand('rti', function()
TriggerServerEvent('fetchIncidentDetails')
end, false)
Expand Down Expand Up @@ -107,7 +109,7 @@ AddEventHandler("displayId", function(playerSource, senderName, name, dob)
local senderID = GetPlayerFromServerId(playerSource)
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local radius = 10.0
local radius = 10.0

if GetDistanceBetweenCoords(playerCoords, GetEntityCoords(GetPlayerPed(senderID)), true) <= radius then
TriggerEvent('chat:addMessage', {
Expand All @@ -118,7 +120,46 @@ AddEventHandler("displayId", function(playerSource, senderName, name, dob)
end
end)

RegisterNetEvent('updateBlips')
AddEventHandler('updateBlips', function(codes)
-- Remove all existing blips
for _, blip in pairs(activeBlips) do
RemoveBlip(blip)
end
activeBlips = {}

local postals = LoadResourceFile(GetCurrentResourceName(), 'postals.json')
if not postals then
print("Error: Unable to load postals.json")
return
end

local postalData = json.decode(postals)

for _, code in ipairs(codes) do
for _, postal in pairs(postalData) do
if tostring(postal.code) == tostring(code) then
local blip = AddBlipForCoord(postal.x, postal.y, postal.z or 0.0)
SetBlipSprite(blip, 58)
SetBlipDisplay(blip, 2)
SetBlipScale(blip, 1.2)
SetBlipColour(blip, 30)
SetBlipCategory(blip, 2)


SetBlipAsShortRange(blip, false)

BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Call: " .. tostring(code))
EndTextCommandSetBlipName(blip)

table.insert(activeBlips, blip)
--print("Blip created at postal code: " .. tostring(code))
break
end
end
end
end)

-- UNIVERSAL FUNCTION TO DRAW NOTIFICATION

Expand Down

0 comments on commit 90363fd

Please sign in to comment.