From 2b98a0edcc7d6d08c9a78610f3a6ac796fb470b2 Mon Sep 17 00:00:00 2001 From: Loaf <60279520+loaf-scripts@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:57:10 +0100 Subject: [PATCH] bugfix, blips, throw from vehicle --- client/client.lua | 79 ++++++++++++++++++++++++++++++++++++---- client/framework/esx.lua | 8 ++++ client/framework/qb.lua | 8 ++++ client/functions.lua | 17 +++++++++ config.lua | 3 ++ fxmanifest.lua | 2 +- locales/en.lua | 4 ++ 7 files changed, 112 insertions(+), 9 deletions(-) diff --git a/client/client.lua b/client/client.lua index 94df4f2..6b1f80a 100644 --- a/client/client.lua +++ b/client/client.lua @@ -1,4 +1,4 @@ ----@alias stinger { id: string, netId?: number, entity?: number, coords: vector3, rotation: vector3, minOffset: vector3, maxOffset: vector3, point?: table } +---@alias stinger { id: string, netId?: number, entity?: number, coords: vector3, rotation: vector3, minOffset: vector3, maxOffset: vector3, point?: table, blip?: number } ---@type {string: stinger } local stingers = lib.callback.await("loaf_spikestrips:getSpikestrips") @@ -17,10 +17,22 @@ local function placeStinger() local playerPed = cache.ped local offset = GetOffsetFromEntityInWorldCoords(playerPed, -0.2, 2.0, 0.0) local heading = GetEntityHeading(playerPed) + local onFoot = IsPedOnFoot(playerPed) + local skipAnimation = false local stinger local netId - if not IsPedOnFoot(playerPed) then + if not onFoot and cache.vehicle then + local model = GetEntityModel(cache.vehicle) + local min = model and GetModelDimensions(model) or { y = -2.5 } + + offset = GetOffsetFromEntityInWorldCoords(cache.vehicle, 0.0, min.y, 0.0) + heading -= 90 + skipAnimation = true + end + + if not Config.AllowFromVehicle and not onFoot then + Notify(L("cant_vehicle"), "error") return end @@ -54,13 +66,14 @@ local function placeStinger() if Config.SpawnMethod == "local" then stinger = CreateObject(model, offset.x, offset.y, offset.z, false, false, false) placing = stinger - else + elseif Config.SpawnMethod == "networked" then stinger = CreateObject(model, offset.x, offset.y, offset.z, true, true, false) netId = NetworkGetNetworkIdFromEntity(stinger) end FreezeEntityPosition(stinger, true) SetEntityVisible(stinger, false, false) + SetEntityCoordsNoOffset(stinger, offset.x, offset.y, offset.z, true, true, true) SetEntityHeading(stinger, heading) PlaceObjectOnGroundProperly(stinger) @@ -70,14 +83,16 @@ local function placeStinger() TriggerServerEvent("loaf_spikestrips:placedSpikestrip", coords, GetEntityRotation(stinger, 2), minOffset, maxOffset, netId) - -- Player deploying animation - TaskPlayAnim(playerPed, playerDict, "enter", 1000.0, -1.0, 200, 16, 0, false, false, false) + if not skipAnimation then + -- Player deploying animation + TaskPlayAnim(playerPed, playerDict, "enter", 1000.0, -1.0, 200, 16, 0, false, false, false) - WaitForAnimation(playerPed, playerDict, "enter") + WaitForAnimation(playerPed, playerDict, "enter") - SetAnimRate(playerPed, 3.0, 1.0, false) + SetAnimRate(playerPed, 3.0, 1.0, false) - Wait(550) + Wait(550) + end -- Stinger animation PlayEntityAnim(stinger, "p_stinger_s_deploy", stingerDict, 1000.0, false, true, false, 0.0, 0) @@ -184,6 +199,10 @@ RegisterNetEvent("loaf_spikestrips:spikestripAdded", function(placer, id, coords point = point, } + if Config.Blips and IsPolice() then + stingers[id].blip = CreateStingerBlip(coords) + end + if Config.RemoveDistance and placer == cache.serverId then while #(GetEntityCoords(cache.ped) - coords) < Config.RemoveDistance and stingers[id] do Wait(1000) @@ -214,9 +233,14 @@ RegisterNetEvent("loaf_spikestrips:spikestripRemoved", function(id) end if stinger.point then + stinger.point:onExit() stinger.point:remove() end + if stinger.blip then + RemoveBlip(stinger.blip) + end + if Config.SpawnMethod == "local" and stinger.entity then if Config.InteractStyle == "target" and targettableEntities[stinger.entity] then targettableEntities[stinger.entity] = nil @@ -426,12 +450,51 @@ if Config.Command then TriggerEvent("chat:addSuggestion", "/" .. Config.Command, L("place_description"), {}) end +local function refreshBlips(isPolice) + for _, stinger in pairs(stingers) do + if Config.Blips and isPolice and not stinger.blip then + stinger.blip = CreateStingerBlip(stinger.coords) + elseif stinger.blip then + RemoveBlip(stinger.blip) + stinger.blip = nil + end + end +end + +if Config.Blips and Config.BlipsCommand then + RegisterCommand(Config.BlipsCommand, function() + local isPolice = IsPolice() + + if not isPolice then + return debugprint("not police") + end + + Config.Blips = not Config.Blips + + refreshBlips(isPolice) + end, false) +end + +AddEventHandler("loaf_spikestrips:toggleIsPolice", function(isPolice) + if not Config.Blips then + return + end + + refreshBlips(isPolice) +end) + +AddTextEntry("SPIKESTRIP_BLIP", L("blip_name")) + AddEventHandler("onResourceStop", function(resource) if resource ~= GetCurrentResourceName() then return end for _, stinger in pairs(stingers) do + if stinger.blip then + RemoveBlip(stinger.blip) + end + if stinger.entity then DeleteEntity(stinger.entity) end diff --git a/client/framework/esx.lua b/client/framework/esx.lua index 74f2a66..a237076 100644 --- a/client/framework/esx.lua +++ b/client/framework/esx.lua @@ -30,7 +30,15 @@ RegisterNetEvent("esx:setJob", function(job) return end + local wasPolice = IsPolice() + ESX.PlayerData.job = job + + local isPolice = IsPolice() + + if wasPolice ~= isPolice then + TriggerEvent("loaf_spikestrips:toggleIsPolice", isPolice) + end end) function IsPolice() diff --git a/client/framework/qb.lua b/client/framework/qb.lua index 951655b..05962a9 100644 --- a/client/framework/qb.lua +++ b/client/framework/qb.lua @@ -13,7 +13,15 @@ end local PlayerJob = QB.Functions.GetPlayerData().job RegisterNetEvent("QBCore:Client:OnJobUpdate", function(jobInfo) + local wasPolice = IsPolice() + PlayerJob = jobInfo + + local isPolice = IsPolice() + + if wasPolice ~= isPolice then + TriggerEvent("loaf_spikestrips:toggleIsPolice", isPolice) + end end) function IsPolice() diff --git a/client/functions.lua b/client/functions.lua index 0979285..51bafc9 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -88,6 +88,23 @@ function WaitForControlAndNetId(netId) return entity end +---@param coords vector3 | vector4 +---@return number +function CreateStingerBlip(coords) + local blip = AddBlipForCoord(coords.x, coords.y, coords.z) + + SetBlipSprite(blip, 237) -- 237, 274, 677 + SetBlipColour(blip, 39) + SetBlipScale(blip, 0.6) + SetBlipAsShortRange(blip, true) + SetBlipDisplay(blip, 2) + + BeginTextCommandSetBlipName("SPIKESTRIP_BLIP") + EndTextCommandSetBlipName(blip) + + return blip +end + function ShowHelpText(textEntry) ClearHelp(true) BeginTextCommandDisplayHelp(textEntry) diff --git a/config.lua b/config.lua index 3bfbcc7..bde5adf 100644 --- a/config.lua +++ b/config.lua @@ -13,7 +13,10 @@ Config.NotificationSystem = "ox_lib" -- framework or ox_lib, modify in client/fu Config.SpawnMethod = "server" -- local (non-networked), networked or server Config.BurstNPC = false -- burst tires of NPCs? note that this can be resource intensive Config.LogSystem = false -- "discord" or "ox_lib". Set your discord webhook in server/logs.lua. Set to false to disable +Config.Blips = false -- show blips of all spike strips on the map for allowed jobs? +Config.AllowFromVehicle = false -- allow throwing spike strips from vehicles? +Config.BlipsCommand = "spikestripblips" -- command to toggle blips (set to false to disable) Config.Command = "spikestrip" -- command to place spike strip, set to false to disable Config.ClearCommand = "clearspikestrips" -- admin command to clear all spike strips, set to false to disable diff --git a/fxmanifest.lua b/fxmanifest.lua index 0d2edc0..f91ae84 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,7 +5,7 @@ lua54 "yes" author "Loaf Scripts" description "Spike strip script that only bursts the touching tires." -version "2.0.1" +version "2.1.0" shared_scripts { "@ox_lib/init.lua", diff --git a/locales/en.lua b/locales/en.lua index d283479..5c5ef51 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -19,4 +19,8 @@ Locales = { logs_removed_distance = "Removed the spike strip {id} because the player went too far away", logs_picked_up = "Picked up the spike strip {id}", logs_placed_spikestrip = "Placed a spike strip with the id {id}", + + cant_vehicle = "You can't place spike strips from a vehicle", + + blip_name = "Spike Strip", } \ No newline at end of file