ed
This commit is contained in:
parent
30e6c02a2f
commit
515271cff0
4 changed files with 684 additions and 0 deletions
308
resources/[jobs]/[crime]/nordi_containerheist/client/main.lua
Normal file
308
resources/[jobs]/[crime]/nordi_containerheist/client/main.lua
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
local containerCooldowns = {}
|
||||
local isRobbing = false
|
||||
local currentContainer = nil
|
||||
local containerBlip = nil
|
||||
|
||||
-- Debug function
|
||||
local function Debug(msg)
|
||||
if Config.Debug then
|
||||
print("[Container Heist] " .. msg)
|
||||
end
|
||||
end
|
||||
|
||||
-- Function to check if player is near a valid container
|
||||
local function IsNearValidContainer()
|
||||
local playerPed = PlayerPedId()
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
|
||||
-- Check for containers in the area
|
||||
local objects = GetGamePool('CObject')
|
||||
for _, object in ipairs(objects) do
|
||||
if DoesEntityExist(object) and not IsEntityDead(object) then
|
||||
local model = GetEntityModel(object)
|
||||
local objectCoords = GetEntityCoords(object)
|
||||
local distance = #(playerCoords - objectCoords)
|
||||
|
||||
if distance <= 5.0 then
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
return object, containerType
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check for trailers in the area
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
for _, vehicle in ipairs(vehicles) do
|
||||
if DoesEntityExist(vehicle) and not IsEntityDead(vehicle) then
|
||||
local model = GetEntityModel(vehicle)
|
||||
local vehicleCoords = GetEntityCoords(vehicle)
|
||||
local distance = #(playerCoords - vehicleCoords)
|
||||
|
||||
if distance <= 5.0 then
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
return vehicle, containerType
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
-- Function to create a blip at the robbery location
|
||||
local function CreateRobberyBlip(coords)
|
||||
if containerBlip then
|
||||
RemoveBlip(containerBlip)
|
||||
end
|
||||
|
||||
containerBlip = AddBlipForCoord(coords)
|
||||
SetBlipSprite(containerBlip, Config.Blip.sprite)
|
||||
SetBlipColour(containerBlip, Config.Blip.color)
|
||||
SetBlipScale(containerBlip, Config.Blip.scale)
|
||||
SetBlipAsShortRange(containerBlip, true)
|
||||
BeginTextCommandSetBlipName("STRING")
|
||||
AddTextComponentString(Config.Blip.label)
|
||||
EndTextCommandSetBlipName(containerBlip)
|
||||
|
||||
if Config.Blip.flash then
|
||||
SetBlipFlashes(containerBlip, true)
|
||||
end
|
||||
|
||||
-- Remove blip after duration
|
||||
SetTimeout(Config.Blip.duration * 1000, function()
|
||||
if containerBlip then
|
||||
RemoveBlip(containerBlip)
|
||||
containerBlip = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Function to play container robbery animation
|
||||
local function PlayRobberyAnimation(containerType)
|
||||
local playerPed = PlayerPedId()
|
||||
local animDict = containerType.animation.dict
|
||||
local animName = containerType.animation.name
|
||||
|
||||
RequestAnimDict(animDict)
|
||||
while not HasAnimDictLoaded(animDict) do
|
||||
Wait(10)
|
||||
end
|
||||
|
||||
TaskPlayAnim(playerPed, animDict, animName, 8.0, -8.0, containerType.animation.duration, containerType.animation.flag, 0, false, false, false)
|
||||
|
||||
-- Add particle effects for welding
|
||||
local boneIndex = GetPedBoneIndex(playerPed, 28422)
|
||||
local particleDict = "core"
|
||||
local particleName = "ent_amb_welding"
|
||||
|
||||
RequestNamedPtfxAsset(particleDict)
|
||||
while not HasNamedPtfxAssetLoaded(particleDict) do
|
||||
Wait(10)
|
||||
end
|
||||
|
||||
UseParticleFxAssetNextCall(particleDict)
|
||||
local particleHandle = StartParticleFxLoopedOnPedBone(particleName, playerPed, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, boneIndex, 0.5, false, false, false)
|
||||
|
||||
-- Clean up after animation
|
||||
SetTimeout(containerType.animation.duration, function()
|
||||
StopParticleFxLooped(particleHandle, 0)
|
||||
StopAnimTask(playerPed, animDict, animName, 1.0)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Function to start container robbery
|
||||
local function StartContainerRobbery(container, containerType)
|
||||
if isRobbing then return end
|
||||
|
||||
isRobbing = true
|
||||
currentContainer = container
|
||||
|
||||
-- Check if player has required tools
|
||||
local hasTools = lib.callback.await('container_heist:server:checkRequiredItems', false)
|
||||
if not hasTools then
|
||||
lib.notify({
|
||||
title = Config.Notifications.title,
|
||||
description = Config.Notifications.noTools,
|
||||
type = 'error'
|
||||
})
|
||||
isRobbing = false
|
||||
currentContainer = nil
|
||||
return
|
||||
end
|
||||
|
||||
-- Check cooldowns
|
||||
local cooldownCheck = lib.callback.await('container_heist:server:checkCooldown', false, NetworkGetNetworkIdFromEntity(container))
|
||||
if not cooldownCheck.success then
|
||||
lib.notify({
|
||||
title = Config.Notifications.title,
|
||||
description = cooldownCheck.message,
|
||||
type = 'error'
|
||||
})
|
||||
isRobbing = false
|
||||
currentContainer = nil
|
||||
return
|
||||
end
|
||||
|
||||
-- Check police count
|
||||
local policeCount = lib.callback.await('container_heist:server:getPoliceCount', false)
|
||||
if policeCount < Config.PoliceRequired then
|
||||
lib.notify({
|
||||
title = Config.Notifications.title,
|
||||
description = Config.Notifications.notEnoughPolice,
|
||||
type = 'error'
|
||||
})
|
||||
isRobbing = false
|
||||
currentContainer = nil
|
||||
return
|
||||
end
|
||||
|
||||
-- Position player for animation
|
||||
local containerCoords = GetEntityCoords(container)
|
||||
local containerHeading = GetEntityHeading(container)
|
||||
local offsetCoords = GetOffsetFromEntityInWorldCoords(container, containerType.offset.x, containerType.offset.y, containerType.offset.z)
|
||||
|
||||
-- Set player position and heading
|
||||
SetEntityCoords(PlayerPedId(), offsetCoords.x, offsetCoords.y, offsetCoords.z)
|
||||
SetEntityHeading(PlayerPedId(), containerHeading + containerType.heading)
|
||||
|
||||
-- Alert police if configured
|
||||
if containerType.policeAlert then
|
||||
local streetName = GetStreetNameFromHashKey(GetStreetNameAtCoord(containerCoords.x, containerCoords.y, containerCoords.z))
|
||||
TriggerServerEvent('container_heist:server:alertPolice', containerCoords, streetName, containerType.label)
|
||||
end
|
||||
|
||||
-- Start robbery progress bar
|
||||
PlayRobberyAnimation(containerType)
|
||||
|
||||
if lib.progressBar({
|
||||
duration = containerType.animation.duration,
|
||||
label = 'Breaking into ' .. containerType.label,
|
||||
useWhileDead = false,
|
||||
canCancel = true,
|
||||
disable = {
|
||||
car = true,
|
||||
move = true,
|
||||
combat = true,
|
||||
},
|
||||
anim = {
|
||||
dict = containerType.animation.dict,
|
||||
clip = containerType.animation.name,
|
||||
},
|
||||
}) then
|
||||
-- Success
|
||||
TriggerServerEvent('container_heist:server:finishRobbery', NetworkGetNetworkIdFromEntity(container), containerType.type)
|
||||
lib.notify({
|
||||
title = Config.Notifications.title,
|
||||
description = Config.Notifications.success,
|
||||
type = 'success'
|
||||
})
|
||||
else
|
||||
-- Cancelled
|
||||
lib.notify({
|
||||
title = Config.Notifications.title,
|
||||
description = Config.Notifications.failed,
|
||||
type = 'error'
|
||||
})
|
||||
end
|
||||
|
||||
isRobbing = false
|
||||
currentContainer = nil
|
||||
end
|
||||
|
||||
-- Command to start container robbery
|
||||
RegisterCommand('robcontainer', function()
|
||||
local container, containerType = IsNearValidContainer()
|
||||
if container and containerType then
|
||||
StartContainerRobbery(container, containerType)
|
||||
else
|
||||
lib.notify({
|
||||
title = Config.Notifications.title,
|
||||
description = "No valid container nearby!",
|
||||
type = 'error'
|
||||
})
|
||||
end
|
||||
end, false)
|
||||
|
||||
-- Setup target interactions for containers
|
||||
CreateThread(function()
|
||||
-- Wait for target system to be ready
|
||||
Wait(1000)
|
||||
|
||||
-- Add target for all container types
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
exports['qb-target']:AddTargetModel(containerType.model, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "container_heist:client:startRobbery",
|
||||
icon = "fas fa-angle-double-right",
|
||||
label = "Break into " .. containerType.label,
|
||||
containerType = containerType,
|
||||
}
|
||||
},
|
||||
distance = 3.0
|
||||
})
|
||||
end
|
||||
|
||||
-- Spawn containers at fixed locations if configured
|
||||
for _, location in pairs(Config.ContainerLocations) do
|
||||
if location.spawnContainer then
|
||||
local hash = GetHashKey(location.model)
|
||||
RequestModel(hash)
|
||||
while not HasModelLoaded(hash) do
|
||||
Wait(10)
|
||||
end
|
||||
|
||||
local container = CreateObject(hash, location.coords.x, location.coords.y, location.coords.z, true, false, false)
|
||||
SetEntityHeading(container, location.heading)
|
||||
FreezeEntityPosition(container, true)
|
||||
SetModelAsNoLongerNeeded(hash)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Event handler for target interaction
|
||||
RegisterNetEvent('container_heist:client:startRobbery', function(data)
|
||||
local container, _ = IsNearValidContainer()
|
||||
if container then
|
||||
StartContainerRobbery(container, data.containerType)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Event to show police alert
|
||||
RegisterNetEvent('container_heist:client:policeAlert', function(coords, streetName, containerType)
|
||||
-- Create alert for police officers
|
||||
lib.notify({
|
||||
title = Config.Notifications.policeTitle,
|
||||
description = string.format(Config.Notifications.policeMessage, streetName),
|
||||
type = 'inform',
|
||||
position = 'top',
|
||||
icon = 'fas fa-exclamation-triangle',
|
||||
iconColor = '#ff0000'
|
||||
})
|
||||
|
||||
-- Add blip to map
|
||||
CreateRobberyBlip(coords)
|
||||
|
||||
-- Play alert sound
|
||||
PlaySound(-1, "Lose_1st", "GTAO_FM_Events_Soundset", 0, 0, 1)
|
||||
end)
|
||||
|
||||
-- Clean up on resource stop
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if resourceName == GetCurrentResourceName() then
|
||||
if containerBlip then
|
||||
RemoveBlip(containerBlip)
|
||||
end
|
||||
|
||||
if isRobbing and currentContainer then
|
||||
StopAnimTask(PlayerPedId(), "amb@world_human_welding@male@base", "base", 1.0)
|
||||
end
|
||||
end
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue