Scripts/resources/[hp]/hp_gv/client/client.lua

192 lines
5.8 KiB
Lua
Raw Normal View History

2024-12-29 19:48:41 +00:00
QBCore = exports['qb-core']:GetCoreObject()
local car = nil
local ped = nil
local object = nil
local activeItems = {}
local activeVan = nil
local currentVan = nil
local function ds()
if car ~= nil then
DeleteEntity(car)
exports['qb-target']:RemoveZone(currentVan)
car = nil
currentVan = nil
end
if ped ~= nil then
DeleteEntity(ped)
ped = nil
end
if object ~= nil then
DeleteEntity(object)
object = nil
end
if activeItems ~= nil then
activeItems = {}
end
if activeVan ~= nil then
activeVan = nil
end
end
local function spawnTargetMenu(x, y, z, h)
2024-12-30 10:15:34 +00:00
exports['qb-target']:AddBoxZone(currentVan, GetEntityCoords(ped), 1.5, 1.5, {
2024-12-29 19:48:41 +00:00
name = currentVan,
heading = h,
minZ = z - 1.0,
maxZ = z + 1.0,
debugPoly = false
},
{
options = {
{
num = 1,
type = "client",
icon = "fas fa-gun",
2024-12-30 10:15:34 +00:00
label = function()
if activeItems[1].iAmount > 0 then
return activeItems[1].label .. "\n" .. activeItems[1].price .. Config.Lang.Currency .. "\n\n" .. Config.Lang.Buy
else
return Config.Lang.SoldOut
end
end,
2024-12-29 19:48:41 +00:00
action = function(entity)
if IsPedAPlayer(entity) then return false end
TriggerServerEvent('_hp_gv:server:_giveItem', 1)
end,
2024-12-30 10:15:34 +00:00
canInteract = function(entity)
2024-12-29 19:48:41 +00:00
if IsPedAPlayer(entity) then return false end
return true
end,
},
{
num = 2,
type = "client",
icon = "fas fa-gun",
2024-12-30 10:15:34 +00:00
label = function()
if activeItems[2].iAmount > 0 then
return activeItems[2].label .. "\n" .. activeItems[2].price .. Config.Lang.Currency .. "\n\n" .. Config.Lang.Buy
else
return Config.Lang.SoldOut
end
end,
2024-12-29 19:48:41 +00:00
action = function(entity)
if IsPedAPlayer(entity) then return false end
TriggerServerEvent('_hp_gv:server:_giveItem', 2)
end,
2024-12-30 10:15:34 +00:00
canInteract = function(entity)
2024-12-29 19:48:41 +00:00
if IsPedAPlayer(entity) then return false end
return true
end,
},
},
distance = 3.0
})
end
local function spawnProp(car)
2024-12-30 10:15:34 +00:00
object = CreateObject(GetHashKey("xm3_prop_xm3_crate_ammo_01a"), 0, 0, 0, true, true, true)
2024-12-29 19:48:41 +00:00
AttachEntityToEntity(object, car, -1, 0, 0.0 - 1.2, 0.0 - 0.2, 0, 0, 0, false, false, false, false, 1, true)
end
local function addNPC(x, y, z)
local animDict = "amb@world_human_leaning@male@wall@back@hands_together@base"
local anim = "base"
local model = GetHashKey(Config.Gunvans.ped)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(15)
end
ped = CreatePed(4, model, x, y, z, 0.0, true, true)
AttachEntityToEntity(ped, car, -1, 0 - 0.7, 0.0 - 3.0, 0.0 + 0.3, 0, 0, 220.0, false, false, false, false, 1, true)
if not HasAnimDictLoaded(animDict) then
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Wait(100)
end
end
TaskPlayAnim(ped, animDict, anim, 2.0, 2.5, -1, 50, 0, false, false, false)
SetPedCanBeTargetted(ped, false)
SetEntityInvincible(ped, true)
SetEntityAsMissionEntity(ped, true, true)
SetModelAsNoLongerNeeded(model)
FreezeEntityPosition(ped, true)
spawnProp(car)
end
local function addCar(x, y, z, h)
local vehiclehash = GetHashKey('speedo4')
RequestModel(vehiclehash)
Citizen.CreateThread(function()
local waiting = 0
while not HasModelLoaded(vehiclehash) do
waiting = waiting + 100
Citizen.Wait(100)
end
2024-12-30 10:15:34 +00:00
car = CreateVehicle(vehiclehash, x, y, z - 1, h, true, false)
-- Turn on Vehicle
SetVehicleEngineOn(car, true, true, false)
2024-12-29 19:48:41 +00:00
SetVehicleOnGroundProperly(car)
SetEntityInvincible(car, true)
SetVehicleNumberPlateText(car, "GUN00VAN")
2024-12-30 10:15:34 +00:00
SetVehicleDoorsLocked(car, 7)
2024-12-29 19:48:41 +00:00
SetVehicleDoorOpen(car, 2, true, true)
SetVehicleDoorOpen(car, 3, true, true)
FreezeEntityPosition(car, true)
SetVehicleUndriveable(car, true)
SetVehicleMod(car, 5, 1, false)
SetVehicleMod(car, 48, 24, false)
addNPC(x, y, z)
spawnTargetMenu(x, y, z, h)
2024-12-30 10:15:34 +00:00
Wait(1000)
SoundVehicleHornThisFrame(car)
SetEntityLights(car, true)
Wait(100)
SoundVehicleHornThisFrame(car)
SetEntityLights(car, false)
2024-12-29 19:48:41 +00:00
end)
end
RegisterNetEvent('_hp_gv:client:_spawnVan')
2024-12-30 10:15:34 +00:00
AddEventHandler('_hp_gv:client:_spawnVan', function()
activeVan = GlobalState.ActiveVan
currentVan = "GunVan" .. (activeVan*2)
activeItems = GlobalState.ActiveItems
2024-12-29 19:48:41 +00:00
2024-12-30 10:15:34 +00:00
addCar(Config.Gunvans.vehicles[activeVan].coords['x'], Config.Gunvans.vehicles[activeVan].coords['y'],
Config.Gunvans.vehicles[activeVan].coords['z'], Config.Gunvans.vehicles[activeVan].heading)
2024-12-29 19:48:41 +00:00
end)
RegisterNetEvent('_hp_gv:client:_destroyVan')
2024-12-30 10:15:34 +00:00
AddEventHandler('_hp_gv:client:_destroyVan', function()
2024-12-29 19:48:41 +00:00
ds()
end)
2024-12-30 10:15:34 +00:00
if Config.Debug then
AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
return
end
ds()
end)
end