1
0
Fork 0
forked from Simnation/Main
Main/resources/[jobs]/[crime]/nordi_containerheist/client/main.lua

177 lines
5.6 KiB
Lua
Raw Normal View History

2025-07-20 02:41:44 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
2025-07-20 04:10:11 +02:00
local isRobbing = false
2025-07-20 17:07:46 +02:00
local inZone = false
local currentZoneId = nil
2025-07-20 02:41:44 +02:00
-- Debug function
local function Debug(msg)
if Config.Debug then
print("[Container Heist] " .. msg)
end
end
2025-07-20 17:07:46 +02:00
-- Function to check if a point is inside a polygon
local function IsPointInPolygon(point, polygon)
local x, y = point.x, point.y
local inside = false
local j = #polygon
for i = 1, #polygon do
if (polygon[i].y > y) ~= (polygon[j].y > y) and
x < (polygon[j].x - polygon[i].x) * (y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x then
inside = not inside
end
j = i
end
return inside
end
-- Function to check if player is in any container zone
local function GetCurrentZone()
2025-07-20 04:10:11 +02:00
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
2025-07-20 03:18:58 +02:00
2025-07-20 17:07:46 +02:00
for _, zone in pairs(Config.ContainerZones) do
if IsPointInPolygon(playerCoords, zone.points) and
playerCoords.z >= zone.minZ and playerCoords.z <= zone.maxZ then
return zone
2025-07-20 02:41:44 +02:00
end
end
2025-07-20 17:07:46 +02:00
return nil
2025-07-20 04:10:11 +02:00
end
2025-07-20 17:36:21 +02:00
-- Simple command to test if the script is working
RegisterCommand('containertest', function()
local playerCoords = GetEntityCoords(PlayerPedId())
print("Player coords: " .. playerCoords.x .. ", " .. playerCoords.y .. ", " .. playerCoords.z)
2025-07-20 04:10:11 +02:00
2025-07-20 17:07:46 +02:00
local zone = GetCurrentZone()
if zone then
2025-07-20 17:36:21 +02:00
QBCore.Functions.Notify("You are in zone: " .. zone.id, "success")
print("In zone: " .. zone.id)
2025-07-20 04:10:11 +02:00
else
2025-07-20 17:36:21 +02:00
QBCore.Functions.Notify("You are not in any container zone", "error")
print("Not in any zone")
2025-07-20 17:27:40 +02:00
end
2025-07-20 17:36:21 +02:00
end, false)
2025-07-20 17:27:40 +02:00
2025-07-20 17:36:21 +02:00
-- Command to start robbery (for testing)
RegisterCommand('robcontainer', function()
2025-07-20 17:27:40 +02:00
local zone = GetCurrentZone()
if zone then
2025-07-20 17:36:21 +02:00
QBCore.Functions.Notify("Starting robbery in zone: " .. zone.id, "success")
TriggerServerEvent('container_heist:server:testRobbery', zone.id, zone.type)
2025-07-20 17:27:40 +02:00
else
2025-07-20 17:36:21 +02:00
QBCore.Functions.Notify("You are not in any container zone", "error")
2025-07-20 17:27:40 +02:00
end
end, false)
2025-07-20 17:36:21 +02:00
-- Register usable item event handler
RegisterNetEvent('container_heist:client:useFlexItem', function()
print("useFlexItem event triggered")
local zone = GetCurrentZone()
2025-07-20 04:05:16 +02:00
2025-07-20 17:36:21 +02:00
if zone then
print("Player is in zone: " .. zone.id)
QBCore.Functions.Notify("Starting robbery with flex tool in zone: " .. zone.id, "success")
TriggerServerEvent('container_heist:server:testRobbery', zone.id, zone.type)
2025-07-20 04:10:11 +02:00
else
2025-07-20 17:36:21 +02:00
QBCore.Functions.Notify(Config.Notifications.notInZone, "error")
2025-07-20 03:42:24 +02:00
end
2025-07-20 17:36:21 +02:00
end)
2025-07-20 03:42:24 +02:00
2025-07-20 17:07:46 +02:00
-- Main thread for checking if player is in a zone
2025-07-20 03:18:58 +02:00
CreateThread(function()
while true do
2025-07-20 04:10:11 +02:00
local sleep = 1000
2025-07-20 17:07:46 +02:00
local zone = GetCurrentZone()
2025-07-20 03:54:06 +02:00
2025-07-20 17:07:46 +02:00
if zone then
if not inZone or currentZoneId ~= zone.id then
inZone = true
currentZoneId = zone.id
QBCore.Functions.Notify("You entered " .. zone.label .. ". Use your flex tool to break in.", "primary")
2025-07-20 17:36:21 +02:00
print("Entered zone: " .. zone.id)
2025-07-20 17:07:46 +02:00
end
sleep = 500
else
if inZone then
inZone = false
currentZoneId = nil
2025-07-20 17:36:21 +02:00
print("Left zone")
2025-07-20 03:54:06 +02:00
end
end
2025-07-20 04:05:16 +02:00
2025-07-20 17:07:46 +02:00
Wait(sleep)
end
end)
-- Debug thread for visualizing zones
CreateThread(function()
while true do
2025-07-20 04:10:11 +02:00
if Config.Debug then
2025-07-20 17:07:46 +02:00
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
for _, zone in pairs(Config.ContainerZones) do
-- Draw lines connecting the points to visualize the zone
for i = 1, #zone.points do
local j = i % #zone.points + 1
local point1 = zone.points[i]
local point2 = zone.points[j]
-- Draw line at ground level
DrawLine(
point1.x, point1.y, zone.minZ,
point2.x, point2.y, zone.minZ,
255, 0, 0, 255
)
2025-07-20 17:36:21 +02:00
end
2025-07-20 17:07:46 +02:00
-- Calculate center of zone for label
local centerX, centerY = 0, 0
for _, point in ipairs(zone.points) do
centerX = centerX + point.x
centerY = centerY + point.y
end
centerX = centerX / #zone.points
centerY = centerY / #zone.points
-- Draw zone label
local centerZ = (zone.minZ + zone.maxZ) / 2
2025-07-20 17:36:21 +02:00
DrawTextOnCoord(centerX, centerY, centerZ, zone.id .. " (" .. zone.type .. ")")
end
Wait(0)
2025-07-20 17:07:46 +02:00
else
Wait(1000)
2025-07-20 02:41:44 +02:00
end
2025-07-20 04:10:11 +02:00
end
end)
2025-07-20 17:36:21 +02:00
-- Function to draw text in 3D space
function DrawTextOnCoord(x, y, z, text)
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
if onScreen then
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, 0, 0, 0, 75)
2025-07-20 04:10:11 +02:00
end
2025-07-20 17:36:21 +02:00
end
2025-07-20 17:27:40 +02:00
-- Print message when resource starts
AddEventHandler('onClientResourceStart', function(resourceName)
if (GetCurrentResourceName() == resourceName) then
2025-07-20 17:36:21 +02:00
print("^2[Container Heist]^7: Client script started successfully")
2025-07-20 17:27:40 +02:00
end
end)