1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-20 17:07:46 +02:00
parent 5cb18574a7
commit 491ceff534
4 changed files with 186 additions and 152 deletions

View file

@ -1,5 +1,5 @@
local QBCore = exports['qb-core']:GetCoreObject()
local pointCooldowns = {}
local zoneCooldowns = {}
local playerCooldowns = {}
local globalCooldowns = {}
@ -10,6 +10,11 @@ local function Debug(msg)
end
end
-- Register usable item
QBCore.Functions.CreateUseableItem(Config.RequiredItems.flex.name, function(source)
TriggerClientEvent('container_heist:client:useFlexItem', source)
end)
-- Check if player has required items
QBCore.Functions.CreateCallback('container_heist:server:checkRequiredItems', function(source, cb)
local src = source
@ -22,7 +27,7 @@ QBCore.Functions.CreateCallback('container_heist:server:checkRequiredItems', fun
end)
-- Check cooldowns
QBCore.Functions.CreateCallback('container_heist:server:checkCooldown', function(source, cb, pointId)
QBCore.Functions.CreateCallback('container_heist:server:checkCooldown', function(source, cb, zoneId)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return cb({success = false, message = "Player not found"}) end
@ -36,27 +41,27 @@ QBCore.Functions.CreateCallback('container_heist:server:checkCooldown', function
return cb({success = false, message = "You need to wait " .. timeLeft .. " more minutes before attempting another heist!"})
end
-- Check point cooldown
if pointCooldowns[pointId] and (currentTime - pointCooldowns[pointId]) < (Config.CooldownTime * 60) then
-- Check zone cooldown
if zoneCooldowns[zoneId] and (currentTime - zoneCooldowns[zoneId]) < (Config.CooldownTime * 60) then
return cb({success = false, message = Config.Notifications.alreadyRobbed})
end
-- Find point type
local pointType = nil
for _, point in pairs(Config.ContainerPoints) do
if point.id == pointId then
pointType = point.type
-- Find zone type
local zoneType = nil
for _, zone in pairs(Config.ContainerZones) do
if zone.id == zoneId then
zoneType = zone.type
break
end
end
if not pointType then
return cb({success = false, message = "Invalid point!"})
if not zoneType then
return cb({success = false, message = "Invalid zone!"})
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)
if globalCooldowns[zoneType] and (currentTime - globalCooldowns[zoneType]) < (Config.GlobalCooldown * 60) then
local timeLeft = math.ceil(((globalCooldowns[zoneType] + (Config.GlobalCooldown * 60)) - currentTime) / 60)
return cb({success = false, message = Config.Notifications.globalCooldown .. " (" .. timeLeft .. " minutes left)"})
end
@ -104,7 +109,7 @@ RegisterNetEvent('container_heist:server:alertPolice', function(coords, streetNa
end)
-- Finish robbery and give rewards
RegisterNetEvent('container_heist:server:finishRobbery', function(pointId, containerTypeName)
RegisterNetEvent('container_heist:server:finishRobbery', function(zoneId, containerTypeName)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
@ -114,7 +119,7 @@ RegisterNetEvent('container_heist:server:finishRobbery', function(pointId, conta
-- Set cooldowns
playerCooldowns[citizenId] = currentTime
pointCooldowns[pointId] = currentTime
zoneCooldowns[zoneId] = currentTime
globalCooldowns[containerTypeName] = currentTime
-- Get container type
@ -194,10 +199,10 @@ CreateThread(function()
end
end
-- Clean up point cooldowns
for pointId, cooldownTime in pairs(pointCooldowns) do
-- Clean up zone cooldowns
for zoneId, cooldownTime in pairs(zoneCooldowns) do
if (currentTime - cooldownTime) > (Config.CooldownTime * 60) then
pointCooldowns[pointId] = nil
zoneCooldowns[zoneId] = nil
end
end