This commit is contained in:
Nordi98 2025-07-20 03:54:06 +02:00
parent 34e3fad675
commit d3942f9c62
4 changed files with 222 additions and 1219 deletions

View file

@ -1,5 +1,5 @@
local QBCore = exports['qb-core']:GetCoreObject()
local containerCooldowns = {}
local pointCooldowns = {}
local playerCooldowns = {}
local globalCooldowns = {}

@ -22,7 +22,7 @@ lib.callback.register('container_heist:server:checkRequiredItems', function(sour
end)

-- Check cooldowns
lib.callback.register('container_heist:server:checkCooldown', function(source, containerId)
lib.callback.register('container_heist:server:checkCooldown', function(source, pointId)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return {success = false, message = "Player not found"} end
@ -36,19 +36,30 @@ lib.callback.register('container_heist:server:checkCooldown', function(source, c
return {success = false, message = "You need to wait " .. timeLeft .. " more minutes before attempting another heist!"}
end
-- Check container cooldown
if containerCooldowns[containerId] and (currentTime - containerCooldowns[containerId]) < (Config.CooldownTime * 60) then
-- Check point cooldown
if pointCooldowns[pointId] and (currentTime - pointCooldowns[pointId]) < (Config.CooldownTime * 60) then
return {success = false, message = Config.Notifications.alreadyRobbed}
end
-- Check global cooldown for container type
for containerType, cooldownTime in pairs(globalCooldowns) do
if (currentTime - cooldownTime) < (Config.GlobalCooldown * 60) then
local timeLeft = math.ceil(((cooldownTime + (Config.GlobalCooldown * 60)) - currentTime) / 60)
return {success = false, message = Config.Notifications.globalCooldown .. " (" .. timeLeft .. " minutes left)"}
-- Find point type
local pointType = nil
for _, point in pairs(Config.ContainerPoints) do
if point.id == pointId then
pointType = point.type
break
end
end
if not pointType then
return {success = false, message = "Invalid point!"}
end
-- Check global cooldown for container type
if globalCooldowns[pointType] and (currentTime - globalCooldowns[pointType]) < (Config.GlobalCooldown * 60) then
local timeLeft = math.ceil(((globalCooldowns[pointType] + (Config.GlobalCooldown * 60)) - currentTime) / 60)
return {success = false, message = Config.Notifications.globalCooldown .. " (" .. timeLeft .. " minutes left)"}
end
return {success = true}
end)

@ -74,7 +85,7 @@ lib.callback.register('container_heist:server:getPoliceCount', function()
end)

-- Alert police
RegisterNetEvent('container_heist:server:alertPolice', function(coords, streetName, containerType)
RegisterNetEvent('container_heist:server:alertPolice', function(coords, streetName, containerLabel)
local src = source
local players = QBCore.Functions.GetPlayers()
@ -84,7 +95,7 @@ RegisterNetEvent('container_heist:server:alertPolice', function(coords, streetNa
-- Check if player's job is in the list of police jobs
for _, jobName in ipairs(Config.PoliceJobs) do
if Player.PlayerData.job.name == jobName and Player.PlayerData.job.onduty then
TriggerClientEvent('container_heist:client:policeAlert', playerId, coords, streetName, containerType)
TriggerClientEvent('container_heist:client:policeAlert', playerId, coords, streetName, containerLabel)
break -- No need to send multiple alerts to the same player
end
end
@ -93,7 +104,7 @@ RegisterNetEvent('container_heist:server:alertPolice', function(coords, streetNa
end)

-- Finish robbery and give rewards
RegisterNetEvent('container_heist:server:finishRobbery', function(containerId, containerType)
RegisterNetEvent('container_heist:server:finishRobbery', function(pointId, containerTypeName)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
@ -103,8 +114,15 @@ RegisterNetEvent('container_heist:server:finishRobbery', function(containerId, c
-- Set cooldowns
playerCooldowns[citizenId] = currentTime
containerCooldowns[containerId] = currentTime
globalCooldowns[containerType] = currentTime
pointCooldowns[pointId] = currentTime
globalCooldowns[containerTypeName] = currentTime
-- Get container type
local containerType = Config.ContainerTypes[containerTypeName]
if not containerType then
Debug("Container type not found: " .. containerTypeName)
return
end
-- Decrease durability of flex tool if configured
if Config.RequiredItems.flex.durability then
@ -129,23 +147,9 @@ RegisterNetEvent('container_heist:server:finishRobbery', function(containerId, c
exports['tgiann-inventory']:RemoveItem(src, Config.RequiredItems.flex.name, Config.RequiredItems.flex.amount)
end
-- Find the container type in config
local containerConfig = nil
for _, config in pairs(Config.ContainerTypes) do
if config.type == containerType then
containerConfig = config
break
end
end
if not containerConfig then
Debug("Container type not found in config: " .. containerType)
return
end
-- Give rewards based on chances
local rewardsGiven = 0
for _, reward in pairs(containerConfig.rewards) do
for _, reward in pairs(containerType.rewards) do
if math.random(1, 100) <= reward.chance then
local amount = math.random(reward.min, reward.max)
@ -190,10 +194,10 @@ CreateThread(function()
end
end
-- Clean up container cooldowns
for containerId, cooldownTime in pairs(containerCooldowns) do
-- Clean up point cooldowns
for pointId, cooldownTime in pairs(pointCooldowns) do
if (currentTime - cooldownTime) > (Config.CooldownTime * 60) then
containerCooldowns[containerId] = nil
pointCooldowns[pointId] = nil
end
end
@ -205,4 +209,3 @@ CreateThread(function()
end
end
end)