forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
812c710ac4
commit
92b36f06c9
1 changed files with 16 additions and 96 deletions
|
@ -21,40 +21,6 @@ local function GetModelNameFromHash(hash)
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to check if player is at the correct position (rear for trailers, front/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 front/door (positive dot product)
|
|
||||||
return forwardDot > 0.7 -- Threshold to ensure player is at the front/door of the container
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Function to check if player is near a valid container
|
-- Function to check if player is near a valid container
|
||||||
local function IsNearValidContainer()
|
local function IsNearValidContainer()
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
|
@ -74,19 +40,10 @@ local function IsNearValidContainer()
|
||||||
if distance <= 5.0 and distance < closestDistance then
|
if distance <= 5.0 and distance < closestDistance then
|
||||||
for _, containerType in pairs(Config.ContainerTypes) do
|
for _, containerType in pairs(Config.ContainerTypes) do
|
||||||
if model == GetHashKey(containerType.model) then
|
if model == GetHashKey(containerType.model) then
|
||||||
-- Check if player is at the front/door for containers
|
foundEntity = object
|
||||||
if IsPlayerAtCorrectPosition(object, containerType) then
|
foundType = containerType
|
||||||
foundEntity = object
|
closestDistance = distance
|
||||||
foundType = containerType
|
break
|
||||||
closestDistance = distance
|
|
||||||
break
|
|
||||||
else
|
|
||||||
lib.notify({
|
|
||||||
title = Config.Notifications.title,
|
|
||||||
description = "You need to stand at the front/door of the container!",
|
|
||||||
type = 'error'
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -104,19 +61,10 @@ local function IsNearValidContainer()
|
||||||
if distance <= 5.0 and distance < closestDistance then
|
if distance <= 5.0 and distance < closestDistance then
|
||||||
for _, containerType in pairs(Config.ContainerTypes) do
|
for _, containerType in pairs(Config.ContainerTypes) do
|
||||||
if model == GetHashKey(containerType.model) then
|
if model == GetHashKey(containerType.model) then
|
||||||
-- Check if player is at the rear for trailers
|
foundEntity = vehicle
|
||||||
if IsPlayerAtCorrectPosition(vehicle, containerType) then
|
foundType = containerType
|
||||||
foundEntity = vehicle
|
closestDistance = distance
|
||||||
foundType = containerType
|
break
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -243,34 +191,14 @@ local function StartContainerRobbery(container, containerType)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get container dimensions
|
-- Position player for animation - use current player position and orientation
|
||||||
local containerModel = GetEntityModel(container)
|
local playerPed = PlayerPedId()
|
||||||
local min, max = GetModelDimensions(containerModel)
|
local playerCoords = GetEntityCoords(playerPed)
|
||||||
local containerLength = max.y - min.y
|
local playerHeading = GetEntityHeading(playerPed)
|
||||||
|
|
||||||
-- Position player for animation
|
|
||||||
local containerCoords = GetEntityCoords(container)
|
|
||||||
local containerHeading = GetEntityHeading(container)
|
|
||||||
local offsetCoords
|
|
||||||
local playerHeading
|
|
||||||
|
|
||||||
-- Different positioning for trailers and containers
|
|
||||||
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 front/door
|
|
||||||
offsetCoords = GetOffsetFromEntityInWorldCoords(container, 0.0, (containerLength/2 + 1.0), 0.0)
|
|
||||||
playerHeading = containerHeading -- Face the front/door of the container
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Set player position and heading
|
|
||||||
SetEntityCoords(PlayerPedId(), offsetCoords.x, offsetCoords.y, offsetCoords.z)
|
|
||||||
SetEntityHeading(PlayerPedId(), playerHeading)
|
|
||||||
|
|
||||||
-- Alert police if configured
|
-- Alert police if configured
|
||||||
if containerType.policeAlert then
|
if containerType.policeAlert then
|
||||||
|
local containerCoords = GetEntityCoords(container)
|
||||||
local streetName = GetStreetNameFromHashKey(GetStreetNameAtCoord(containerCoords.x, containerCoords.y, containerCoords.z))
|
local streetName = GetStreetNameFromHashKey(GetStreetNameAtCoord(containerCoords.x, containerCoords.y, containerCoords.z))
|
||||||
TriggerServerEvent('container_heist:server:alertPolice', containerCoords, streetName, containerType.label)
|
TriggerServerEvent('container_heist:server:alertPolice', containerCoords, streetName, containerType.label)
|
||||||
end
|
end
|
||||||
|
@ -340,9 +268,6 @@ local function ScanAndAddContainersToTarget()
|
||||||
icon = "fas fa-angle-double-right",
|
icon = "fas fa-angle-double-right",
|
||||||
label = "Break into " .. containerType.label,
|
label = "Break into " .. containerType.label,
|
||||||
containerType = containerType,
|
containerType = containerType,
|
||||||
canInteract = function(entity)
|
|
||||||
return IsPlayerAtCorrectPosition(entity, containerType)
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
distance = 3.0
|
distance = 3.0
|
||||||
|
@ -378,9 +303,6 @@ local function ScanAndAddContainersToTarget()
|
||||||
icon = "fas fa-angle-double-right",
|
icon = "fas fa-angle-double-right",
|
||||||
label = "Break into " .. containerType.label,
|
label = "Break into " .. containerType.label,
|
||||||
containerType = containerType,
|
containerType = containerType,
|
||||||
canInteract = function(entity)
|
|
||||||
return IsPlayerAtCorrectPosition(entity, containerType)
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
distance = 3.0
|
distance = 3.0
|
||||||
|
@ -544,9 +466,6 @@ CreateThread(function()
|
||||||
icon = "fas fa-angle-double-right",
|
icon = "fas fa-angle-double-right",
|
||||||
label = "Break into " .. containerType.label,
|
label = "Break into " .. containerType.label,
|
||||||
containerType = containerType,
|
containerType = containerType,
|
||||||
canInteract = function(entity)
|
|
||||||
return IsPlayerAtCorrectPosition(entity, containerType)
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
distance = 3.0
|
distance = 3.0
|
||||||
|
@ -606,9 +525,10 @@ RegisterNetEvent('container_heist:client:policeAlert', function(coords, streetNa
|
||||||
title = alertTitle,
|
title = alertTitle,
|
||||||
description = string.format(Config.Notifications.policeMessage, streetName),
|
description = string.format(Config.Notifications.policeMessage, streetName),
|
||||||
type = 'inform',
|
type = 'inform',
|
||||||
position = 'right',
|
position = 'top',
|
||||||
icon = alertIcon,
|
icon = alertIcon,
|
||||||
iconColor = '#ff0000'
|
iconColor = '#ff0000',
|
||||||
|
duration = 20000 -- 10 Sekunden (10000 Millisekunden)
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Add blip to map
|
-- Add blip to map
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue