forked from Simnation/Main
e
This commit is contained in:
parent
ab710c86fd
commit
31cbcb2aca
3 changed files with 256 additions and 96 deletions
|
@ -11,6 +11,23 @@ local function Debug(msg)
|
|||
end
|
||||
end
|
||||
|
||||
-- Helper function to draw 3D text
|
||||
function DrawText3D(x, y, z, text)
|
||||
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
|
||||
local px, py, pz = table.unpack(GetGameplayCamCoords())
|
||||
|
||||
SetTextScale(0.35, 0.35)
|
||||
SetTextFont(4)
|
||||
SetTextProportional(1)
|
||||
SetTextColour(255, 255, 255, 215)
|
||||
SetTextEntry("STRING")
|
||||
SetTextCentre(1)
|
||||
AddTextComponentString(text)
|
||||
DrawText(_x, _y)
|
||||
local factor = (string.len(text)) / 370
|
||||
DrawRect(_x, _y + 0.0125, 0.015 + factor, 0.03, 41, 11, 41, 68)
|
||||
end
|
||||
|
||||
-- Function to get model name from hash
|
||||
local function GetModelNameFromHash(hash)
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
|
@ -27,9 +44,32 @@ local function IsNearValidContainer()
|
|||
local playerCoords = GetEntityCoords(playerPed)
|
||||
local foundEntity = nil
|
||||
local foundType = nil
|
||||
local closestDistance = 999.0
|
||||
local closestDistance = 5.0 -- Maximum detection distance
|
||||
|
||||
-- Check for containers in the area (objects)
|
||||
-- First check: Use raycast to detect what player is looking at
|
||||
local rayHandle = StartExpensiveSynchronousShapeTestLosProbe(
|
||||
playerCoords.x, playerCoords.y, playerCoords.z,
|
||||
playerCoords.x + (GetEntityForwardX(playerPed) * 5.0),
|
||||
playerCoords.y + (GetEntityForwardY(playerPed) * 5.0),
|
||||
playerCoords.z,
|
||||
16, playerPed, 4
|
||||
)
|
||||
local _, hit, endCoords, _, entity = GetShapeTestResult(rayHandle)
|
||||
|
||||
if hit and DoesEntityExist(entity) then
|
||||
local model = GetEntityModel(entity)
|
||||
local entityType = GetEntityType(entity)
|
||||
local distance = #(playerCoords - GetEntityCoords(entity))
|
||||
|
||||
-- Check if this entity is a valid container or trailer
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
return entity, containerType
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Second check: Check all objects in area
|
||||
local objects = GetGamePool('CObject')
|
||||
for _, object in ipairs(objects) do
|
||||
if DoesEntityExist(object) and not IsEntityDead(object) then
|
||||
|
@ -37,20 +77,21 @@ local function IsNearValidContainer()
|
|||
local objectCoords = GetEntityCoords(object)
|
||||
local distance = #(playerCoords - objectCoords)
|
||||
|
||||
if distance <= 5.0 and distance < closestDistance then
|
||||
if distance <= closestDistance then
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
if distance < closestDistance then
|
||||
foundEntity = object
|
||||
foundType = containerType
|
||||
closestDistance = distance
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check for trailers in the area (vehicles)
|
||||
-- Third check: Check all vehicles in area (for trailers)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
for _, vehicle in ipairs(vehicles) do
|
||||
if DoesEntityExist(vehicle) and not IsEntityDead(vehicle) then
|
||||
|
@ -58,13 +99,14 @@ local function IsNearValidContainer()
|
|||
local vehicleCoords = GetEntityCoords(vehicle)
|
||||
local distance = #(playerCoords - vehicleCoords)
|
||||
|
||||
if distance <= 5.0 and distance < closestDistance then
|
||||
if distance <= closestDistance then
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
if distance < closestDistance then
|
||||
foundEntity = vehicle
|
||||
foundType = containerType
|
||||
closestDistance = distance
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -145,6 +187,152 @@ local function PlayRobberyAnimation(containerType)
|
|||
end)
|
||||
end
|
||||
|
||||
-- Function to add target to specific entity
|
||||
local function AddTargetToEntity(entity, containerType)
|
||||
if not DoesEntityExist(entity) or not containerType then return false end
|
||||
|
||||
-- Check if we've already added this entity
|
||||
if addedEntities[entity] then return false end
|
||||
|
||||
-- Add target to this specific entity
|
||||
exports['qb-target']:AddTargetEntity(entity, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "container_heist:client:startRobbery",
|
||||
icon = "fas fa-angle-double-right",
|
||||
label = "Break into " .. containerType.label,
|
||||
containerType = containerType,
|
||||
}
|
||||
},
|
||||
distance = 3.0
|
||||
})
|
||||
|
||||
addedEntities[entity] = true
|
||||
return true
|
||||
end
|
||||
|
||||
-- Function to scan and add all nearby containers to target system
|
||||
local function ScanAndAddContainersToTarget()
|
||||
local playerPed = PlayerPedId()
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
local count = 0
|
||||
|
||||
-- Check for containers in the area (objects)
|
||||
local objects = GetGamePool('CObject')
|
||||
for _, object in ipairs(objects) do
|
||||
if DoesEntityExist(object) and not IsEntityDead(object) then
|
||||
local objectCoords = GetEntityCoords(object)
|
||||
local distance = #(playerCoords - objectCoords)
|
||||
|
||||
if distance <= 50.0 then
|
||||
local model = GetEntityModel(object)
|
||||
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
if AddTargetToEntity(object, containerType) then
|
||||
count = count + 1
|
||||
Debug("Added target to container: " .. containerType.model .. " at distance: " .. distance)
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check for trailers in the area (vehicles)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
for _, vehicle in ipairs(vehicles) do
|
||||
if DoesEntityExist(vehicle) and not IsEntityDead(vehicle) then
|
||||
local vehicleCoords = GetEntityCoords(vehicle)
|
||||
local distance = #(playerCoords - vehicleCoords)
|
||||
|
||||
if distance <= 50.0 then
|
||||
local model = GetEntityModel(vehicle)
|
||||
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
if AddTargetToEntity(vehicle, containerType) then
|
||||
count = count + 1
|
||||
Debug("Added target to trailer: " .. containerType.model .. " at distance: " .. distance)
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
-- Function to visualize containers for debugging
|
||||
local function VisualizeContainers()
|
||||
if not Config.Debug then return end
|
||||
|
||||
CreateThread(function()
|
||||
while Config.Debug do
|
||||
local playerPed = PlayerPedId()
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
|
||||
-- Check for containers in the area (objects)
|
||||
local objects = GetGamePool('CObject')
|
||||
for _, object in ipairs(objects) do
|
||||
if DoesEntityExist(object) and not IsEntityDead(object) then
|
||||
local objectCoords = GetEntityCoords(object)
|
||||
local distance = #(playerCoords - objectCoords)
|
||||
|
||||
if distance <= 20.0 then
|
||||
local model = GetEntityModel(object)
|
||||
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
-- Draw a marker at the container
|
||||
DrawMarker(1, objectCoords.x, objectCoords.y, objectCoords.z + 2.0,
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||
1.0, 1.0, 1.0, 255, 0, 0, 100, false, true, 2, false, nil, nil, false)
|
||||
|
||||
-- Draw text with container type
|
||||
DrawText3D(objectCoords.x, objectCoords.y, objectCoords.z + 2.5, containerType.label)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check for trailers in the area (vehicles)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
for _, vehicle in ipairs(vehicles) do
|
||||
if DoesEntityExist(vehicle) and not IsEntityDead(vehicle) then
|
||||
local vehicleCoords = GetEntityCoords(vehicle)
|
||||
local distance = #(playerCoords - vehicleCoords)
|
||||
|
||||
if distance <= 20.0 then
|
||||
local model = GetEntityModel(vehicle)
|
||||
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
-- Draw a marker at the trailer
|
||||
DrawMarker(1, vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 2.0,
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||
1.0, 1.0, 1.0, 0, 0, 255, 100, false, true, 2, false, nil, nil, false)
|
||||
|
||||
-- Draw text with trailer type
|
||||
DrawText3D(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 2.5, containerType.label)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Wait(0)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Function to start container robbery
|
||||
local function StartContainerRobbery(container, containerType)
|
||||
if isRobbing then return end
|
||||
|
@ -244,85 +432,6 @@ local function StartContainerRobbery(container, containerType)
|
|||
currentContainer = nil
|
||||
end
|
||||
|
||||
-- Function to scan and add all nearby containers to target system
|
||||
local function ScanAndAddContainersToTarget()
|
||||
local playerPed = PlayerPedId()
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
local count = 0
|
||||
|
||||
-- Check for containers in the area (objects)
|
||||
local objects = GetGamePool('CObject')
|
||||
for _, object in ipairs(objects) do
|
||||
if DoesEntityExist(object) and not IsEntityDead(object) then
|
||||
local objectCoords = GetEntityCoords(object)
|
||||
local distance = #(playerCoords - objectCoords)
|
||||
|
||||
if distance <= 50.0 then
|
||||
local model = GetEntityModel(object)
|
||||
|
||||
if not addedEntities[object] then
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
exports['qb-target']:AddTargetEntity(object, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "container_heist:client:startRobbery",
|
||||
icon = "fas fa-angle-double-right",
|
||||
label = "Break into " .. containerType.label,
|
||||
containerType = containerType,
|
||||
}
|
||||
},
|
||||
distance = 3.0
|
||||
})
|
||||
addedEntities[object] = true
|
||||
count = count + 1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check for trailers in the area (vehicles)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
for _, vehicle in ipairs(vehicles) do
|
||||
if DoesEntityExist(vehicle) and not IsEntityDead(vehicle) then
|
||||
local vehicleCoords = GetEntityCoords(vehicle)
|
||||
local distance = #(playerCoords - vehicleCoords)
|
||||
|
||||
if distance <= 50.0 then
|
||||
local model = GetEntityModel(vehicle)
|
||||
|
||||
if not addedEntities[vehicle] then
|
||||
for _, containerType in pairs(Config.ContainerTypes) do
|
||||
if model == GetHashKey(containerType.model) then
|
||||
exports['qb-target']:AddTargetEntity(vehicle, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "container_heist:client:startRobbery",
|
||||
icon = "fas fa-angle-double-right",
|
||||
label = "Break into " .. containerType.label,
|
||||
containerType = containerType,
|
||||
}
|
||||
},
|
||||
distance = 3.0
|
||||
})
|
||||
addedEntities[vehicle] = true
|
||||
count = count + 1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
-- Command to start container robbery
|
||||
RegisterCommand('robcontainer', function()
|
||||
local container, containerType = IsNearValidContainer()
|
||||
|
@ -349,6 +458,46 @@ RegisterCommand('scancontainers', function()
|
|||
})
|
||||
end, false)
|
||||
|
||||
-- Command to force refresh all targets
|
||||
RegisterCommand('refreshcontainers', function()
|
||||
-- Clear existing targets
|
||||
addedEntities = {}
|
||||
|
||||
-- Force a new scan
|
||||
local count = ScanAndAddContainersToTarget()
|
||||
|
||||
lib.notify({
|
||||
title = "Container Refresh",
|
||||
description = "Refreshed " .. count .. " containers/trailers",
|
||||
type = 'success',
|
||||
position = 'top',
|
||||
duration = 3000
|
||||
})
|
||||
end, false)
|
||||
|
||||
-- Command to toggle debug mode
|
||||
RegisterCommand('containerdebug', function()
|
||||
Config.Debug = not Config.Debug
|
||||
if Config.Debug then
|
||||
lib.notify({
|
||||
title = "Container Debug",
|
||||
description = "Debug mode enabled",
|
||||
type = 'inform',
|
||||
position = 'top',
|
||||
duration = 3000
|
||||
})
|
||||
VisualizeContainers()
|
||||
else
|
||||
lib.notify({
|
||||
title = "Container Debug",
|
||||
description = "Debug mode disabled",
|
||||
type = 'inform',
|
||||
position = 'top',
|
||||
duration = 3000
|
||||
})
|
||||
end
|
||||
end, false)
|
||||
|
||||
-- Debug command to show all nearby containers and trailers
|
||||
RegisterCommand('containersdebug', function()
|
||||
if not Config.Debug then return end
|
||||
|
@ -492,11 +641,22 @@ CreateThread(function()
|
|||
end
|
||||
end)
|
||||
|
||||
-- Initial scan when resource starts
|
||||
CreateThread(function()
|
||||
Wait(2000) -- Wait for everything to load
|
||||
ScanAndAddContainersToTarget()
|
||||
|
||||
-- If debug mode is enabled, start visualizing containers
|
||||
if Config.Debug then
|
||||
VisualizeContainers()
|
||||
end
|
||||
end)
|
||||
|
||||
-- Automatically scan for containers periodically
|
||||
CreateThread(function()
|
||||
while true do
|
||||
ScanAndAddContainersToTarget()
|
||||
Wait(30000) -- Scan every 30 seconds
|
||||
Wait(10000) -- Scan every 10 seconds
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Config = {}
|
||||
|
||||
-- General Settings
|
||||
Config.Debug = false -- Set to true for debug prints
|
||||
Config.Debug = true -- Set to true for debug prints
|
||||
Config.CooldownTime = 1 -- Minutes between heists (per player)
|
||||
Config.GlobalCooldown = 1 -- Minutes between heists (server-wide)
|
||||
Config.PoliceRequired = 1 -- Minimum police required
|
||||
|
|
|
@ -170,14 +170,13 @@ RegisterNetEvent('container_heist:server:finishRobbery', function(containerId, c
|
|||
|
||||
rewardsGiven = rewardsGiven + 1
|
||||
end
|
||||
end -- <-- This end statement was missing
|
||||
end
|
||||
|
||||
if rewardsGiven == 0 then
|
||||
TriggerClientEvent('QBCore:Notify', src, "The container was empty!", "error")
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Clean up cooldowns periodically
|
||||
CreateThread(function()
|
||||
while true do
|
||||
|
@ -206,3 +205,4 @@ CreateThread(function()
|
|||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue