This commit is contained in:
Nordi98 2025-07-20 18:04:26 +02:00
parent 4676cbfc6d
commit 2a1f7bf95c
2 changed files with 109 additions and 345 deletions

View file

@ -21,6 +21,40 @@ local function GetModelNameFromHash(hash)
return "Unknown"
end

-- Function to check if player is at the correct position (rear for trailers, door for containers)
local function IsPlayerAtCorrectPosition(entity, containerType)
local playerPos = GetEntityCoords(PlayerPedId())
local entityPos = GetEntityCoords(entity)
local entityHeading = GetEntityHeading(entity)
local entityForwardVector = GetEntityForwardVector(entity)
-- Get vector from entity to player
local toPlayerVector = vector3(
playerPos.x - entityPos.x,
playerPos.y - entityPos.y,
0.0
)
-- Normalize the vector
local length = math.sqrt(toPlayerVector.x^2 + toPlayerVector.y^2)
if length > 0 then
toPlayerVector = vector3(toPlayerVector.x / length, toPlayerVector.y / length, 0.0)
else
return false
end
-- Calculate dot product with forward vector
local forwardDot = toPlayerVector.x * entityForwardVector.x + toPlayerVector.y * entityForwardVector.y
if string.match(containerType.type, "trailer") then
-- For trailers, player should be at the rear (negative dot product)
return forwardDot < -0.7 -- Threshold to ensure player is behind the trailer
else
-- For containers, player should be at the door (positive dot product)
return forwardDot > 0.7 -- Threshold to ensure player is in front of the container
end
end

-- Function to check if player is near a valid container
local function IsNearValidContainer()
local playerPed = PlayerPedId()
@ -40,10 +74,19 @@ local function IsNearValidContainer()
if distance <= 5.0 and distance < closestDistance then
for _, containerType in pairs(Config.ContainerTypes) do
if model == GetHashKey(containerType.model) then
foundEntity = object
foundType = containerType
closestDistance = distance
break
-- Check if player is at the door for containers
if IsPlayerAtCorrectPosition(object, containerType) then
foundEntity = object
foundType = containerType
closestDistance = distance
break
else
lib.notify({
title = Config.Notifications.title,
description = "You need to stand at the door of the container!",
type = 'error'
})
end
end
end
end
@ -61,10 +104,19 @@ local function IsNearValidContainer()
if distance <= 5.0 and distance < closestDistance then
for _, containerType in pairs(Config.ContainerTypes) do
if model == GetHashKey(containerType.model) then
foundEntity = vehicle
foundType = containerType
closestDistance = distance
break
-- Check if player is at the rear for trailers
if IsPlayerAtCorrectPosition(vehicle, containerType) then
foundEntity = vehicle
foundType = containerType
closestDistance = distance
break
else
lib.notify({
title = Config.Notifications.title,
description = "You need to stand at the rear of the trailer!",
type = 'error'
})
end
end
end
end
@ -191,14 +243,31 @@ local function StartContainerRobbery(container, containerType)
return
end
-- Get container dimensions
local containerModel = GetEntityModel(container)
local min, max = GetModelDimensions(containerModel)
local containerLength = max.y - min.y
-- 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)
local offsetCoords
local playerHeading
-- Check if this is a trailer type
if string.match(containerType.type, "trailer") then
-- For trailers, position at the rear
offsetCoords = GetOffsetFromEntityInWorldCoords(container, 0.0, -(containerLength/2 + 1.0), 0.0)
playerHeading = containerHeading + 180.0 -- Face the rear of the trailer
else
-- For containers, position at the door (front)
offsetCoords = GetOffsetFromEntityInWorldCoords(container, 0.0, containerLength/2 + 1.0, 0.0)
playerHeading = containerHeading -- Face the front of the container
end
-- Set player position and heading
SetEntityCoords(PlayerPedId(), offsetCoords.x, offsetCoords.y, offsetCoords.z)
SetEntityHeading(PlayerPedId(), containerHeading + containerType.heading)
SetEntityHeading(PlayerPedId(), playerHeading)
-- Alert police if configured
if containerType.policeAlert then
@ -271,6 +340,9 @@ local function ScanAndAddContainersToTarget()
icon = "fas fa-angle-double-right",
label = "Break into " .. containerType.label,
containerType = containerType,
canInteract = function(entity)
return IsPlayerAtCorrectPosition(entity, containerType)
end
}
},
distance = 3.0
@ -306,6 +378,9 @@ local function ScanAndAddContainersToTarget()
icon = "fas fa-angle-double-right",
label = "Break into " .. containerType.label,
containerType = containerType,
canInteract = function(entity)
return IsPlayerAtCorrectPosition(entity, containerType)
end
}
},
distance = 3.0
@ -469,6 +544,9 @@ CreateThread(function()
icon = "fas fa-angle-double-right",
label = "Break into " .. containerType.label,
containerType = containerType,
canInteract = function(entity)
return IsPlayerAtCorrectPosition(entity, containerType)
end
}
},
distance = 3.0