forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
a71624a6ba
commit
d3f4114333
1 changed files with 165 additions and 250 deletions
|
@ -1,8 +1,7 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
local isRobbing = false
|
local pointCooldowns = {}
|
||||||
local currentPoint = nil
|
local playerCooldowns = {}
|
||||||
local containerBlip = nil
|
local globalCooldowns = {}
|
||||||
local nearbyPoint = nil
|
|
||||||
|
|
||||||
-- Debug function
|
-- Debug function
|
||||||
local function Debug(msg)
|
local function Debug(msg)
|
||||||
|
@ -11,286 +10,202 @@ local function Debug(msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Helper function to draw 3D text
|
-- Check if player has required items
|
||||||
function DrawText3D(x, y, z, text)
|
lib.callback.register('container_heist:server:checkRequiredItems', function(source)
|
||||||
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
|
local src = source
|
||||||
local px, py, pz = table.unpack(GetGameplayCamCoords())
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
if not Player then return false end
|
||||||
|
|
||||||
SetTextScale(0.35, 0.35)
|
-- Check for required flex tool
|
||||||
SetTextFont(4)
|
local hasItem = exports['tgiann-inventory']:HasItem(src, Config.RequiredItems.flex.name, Config.RequiredItems.flex.amount)
|
||||||
SetTextProportional(1)
|
return hasItem
|
||||||
SetTextColour(255, 255, 255, 215)
|
end)
|
||||||
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, 41, 11, 41, 68)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Function to find the nearest container point
|
-- Check cooldowns
|
||||||
local function GetNearestContainerPoint()
|
lib.callback.register('container_heist:server:checkCooldown', function(source, pointId)
|
||||||
local playerPed = PlayerPedId()
|
local src = source
|
||||||
local playerCoords = GetEntityCoords(playerPed)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
local closestPoint = nil
|
if not Player then return {success = false, message = "Player not found"} end
|
||||||
local minDistance = 3.0 -- Maximum interaction distance
|
|
||||||
|
|
||||||
|
local citizenId = Player.PlayerData.citizenid
|
||||||
|
local currentTime = os.time()
|
||||||
|
|
||||||
|
-- Check player cooldown
|
||||||
|
if playerCooldowns[citizenId] and (currentTime - playerCooldowns[citizenId]) < (Config.CooldownTime * 60) then
|
||||||
|
local timeLeft = math.ceil(((playerCooldowns[citizenId] + (Config.CooldownTime * 60)) - currentTime) / 60)
|
||||||
|
return {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
|
||||||
|
return {success = false, message = Config.Notifications.alreadyRobbed}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Find point type
|
||||||
|
local pointType = nil
|
||||||
for _, point in pairs(Config.ContainerPoints) do
|
for _, point in pairs(Config.ContainerPoints) do
|
||||||
local distance = #(playerCoords - point.coords)
|
if point.id == pointId then
|
||||||
if distance < minDistance then
|
pointType = point.type
|
||||||
minDistance = distance
|
break
|
||||||
closestPoint = point
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return closestPoint, minDistance
|
if not pointType then
|
||||||
end
|
return {success = false, message = "Invalid point!"}
|
||||||
|
|
||||||
-- Function to create a blip at the robbery location
|
|
||||||
local function CreateRobberyBlip(coords)
|
|
||||||
if containerBlip then
|
|
||||||
RemoveBlip(containerBlip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
containerBlip = AddBlipForCoord(coords)
|
-- Check global cooldown for container type
|
||||||
|
if globalCooldowns[pointType] and (currentTime - globalCooldowns[pointType]) < (Config.GlobalCooldown * 60) then
|
||||||
-- Set blip color based on job
|
local timeLeft = math.ceil(((globalCooldowns[pointType] + (Config.GlobalCooldown * 60)) - currentTime) / 60)
|
||||||
local playerJob = QBCore.Functions.GetPlayerData().job.name
|
return {success = false, message = Config.Notifications.globalCooldown .. " (" .. timeLeft .. " minutes left)"}
|
||||||
if playerJob == "marshal" then
|
|
||||||
SetBlipColour(containerBlip, 38) -- Purple for Marshal
|
|
||||||
elseif playerJob == "sheriff" then
|
|
||||||
SetBlipColour(containerBlip, 16) -- Orange for Sheriff
|
|
||||||
else
|
|
||||||
SetBlipColour(containerBlip, Config.Blip.color) -- Default color for regular police
|
|
||||||
end
|
end
|
||||||
|
|
||||||
SetBlipSprite(containerBlip, Config.Blip.sprite)
|
return {success = true}
|
||||||
SetBlipScale(containerBlip, Config.Blip.scale)
|
end)
|
||||||
SetBlipAsShortRange(containerBlip, true)
|
|
||||||
BeginTextCommandSetBlipName("STRING")
|
|
||||||
AddTextComponentString(Config.Blip.label)
|
|
||||||
EndTextCommandSetBlipName(containerBlip)
|
|
||||||
|
|
||||||
if Config.Blip.flash then
|
-- Get police count
|
||||||
SetBlipFlashes(containerBlip, true)
|
lib.callback.register('container_heist:server:getPoliceCount', function()
|
||||||
end
|
local policeCount = 0
|
||||||
|
local players = QBCore.Functions.GetPlayers()
|
||||||
|
|
||||||
-- Remove blip after duration
|
for _, playerId in ipairs(players) do
|
||||||
SetTimeout(Config.Blip.duration * 1000, function()
|
local Player = QBCore.Functions.GetPlayer(playerId)
|
||||||
if containerBlip then
|
if Player then
|
||||||
RemoveBlip(containerBlip)
|
-- Check if player's job is in the list of police jobs
|
||||||
containerBlip = nil
|
for _, jobName in ipairs(Config.PoliceJobs) do
|
||||||
|
if Player.PlayerData.job.name == jobName and Player.PlayerData.job.onduty then
|
||||||
|
policeCount = policeCount + 1
|
||||||
|
break -- No need to check other job names for this player
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Function to play container robbery animation
|
|
||||||
local function PlayRobberyAnimation(containerType)
|
|
||||||
local playerPed = PlayerPedId()
|
|
||||||
local animDict = containerType.animation.dict
|
|
||||||
local animName = containerType.animation.name
|
|
||||||
|
|
||||||
RequestAnimDict(animDict)
|
|
||||||
while not HasAnimDictLoaded(animDict) do
|
|
||||||
Wait(10)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
TaskPlayAnim(playerPed, animDict, animName, 8.0, -8.0, containerType.animation.duration, containerType.animation.flag, 0, false, false, false)
|
return policeCount
|
||||||
|
end)
|
||||||
|
|
||||||
-- Add particle effects for welding
|
-- Alert police
|
||||||
local boneIndex = GetPedBoneIndex(playerPed, 28422)
|
RegisterNetEvent('container_heist:server:alertPolice', function(coords, streetName, containerLabel)
|
||||||
local particleDict = "core"
|
local src = source
|
||||||
local particleName = "ent_amb_welding"
|
local players = QBCore.Functions.GetPlayers()
|
||||||
|
|
||||||
RequestNamedPtfxAsset(particleDict)
|
for _, playerId in ipairs(players) do
|
||||||
while not HasNamedPtfxAssetLoaded(particleDict) do
|
local Player = QBCore.Functions.GetPlayer(playerId)
|
||||||
Wait(10)
|
if Player then
|
||||||
|
-- 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, containerLabel)
|
||||||
|
break -- No need to send multiple alerts to the same player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
UseParticleFxAssetNextCall(particleDict)
|
-- Finish robbery and give rewards
|
||||||
local particleHandle = StartParticleFxLoopedOnPedBone(particleName, playerPed, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, boneIndex, 0.5, false, false, false)
|
RegisterNetEvent('container_heist:server:finishRobbery', function(pointId, containerTypeName)
|
||||||
|
local src = source
|
||||||
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
if not Player then return end
|
||||||
|
|
||||||
-- Clean up after animation
|
local citizenId = Player.PlayerData.citizenid
|
||||||
SetTimeout(containerType.animation.duration, function()
|
local currentTime = os.time()
|
||||||
StopParticleFxLooped(particleHandle, 0)
|
|
||||||
StopAnimTask(playerPed, animDict, animName, 1.0)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Function to start container robbery
|
-- Set cooldowns
|
||||||
local function StartContainerRobbery(point)
|
playerCooldowns[citizenId] = currentTime
|
||||||
if isRobbing then return end
|
pointCooldowns[pointId] = currentTime
|
||||||
|
globalCooldowns[containerTypeName] = currentTime
|
||||||
|
|
||||||
isRobbing = true
|
-- Get container type
|
||||||
currentPoint = point
|
local containerType = Config.ContainerTypes[containerTypeName]
|
||||||
|
|
||||||
-- Get container type from point
|
|
||||||
local containerType = Config.ContainerTypes[point.type]
|
|
||||||
if not containerType then
|
if not containerType then
|
||||||
QBCore.Functions.Notify("Invalid container type!", "error")
|
Debug("Container type not found: " .. containerTypeName)
|
||||||
isRobbing = false
|
|
||||||
currentPoint = nil
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if player has required tools
|
-- Decrease durability of flex tool if configured
|
||||||
local hasTools = lib.callback.await('container_heist:server:checkRequiredItems', false)
|
if Config.RequiredItems.flex.durability then
|
||||||
if not hasTools then
|
local itemData = exports['tgiann-inventory']:GetItemByName(src, Config.RequiredItems.flex.name)
|
||||||
QBCore.Functions.Notify(Config.Notifications.noTools, "error")
|
if itemData and itemData.info then
|
||||||
isRobbing = false
|
local newDurability = math.max(0, (itemData.info.durabilityPercent or 100) - Config.RequiredItems.flex.durabilityDecrease)
|
||||||
currentPoint = nil
|
exports['tgiann-inventory']:UpdateItemMetadata(src, Config.RequiredItems.flex.name, itemData.slot, {
|
||||||
return
|
durabilityPercent = newDurability,
|
||||||
|
serie = itemData.info.serie or "TOOL-" .. math.random(100000, 999999),
|
||||||
|
usedTotalAmmo = itemData.info.usedTotalAmmo or 0,
|
||||||
|
ammo = itemData.info.ammo or 0
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Remove item if durability reaches 0
|
||||||
|
if newDurability <= 0 and Config.RequiredItems.flex.remove then
|
||||||
|
exports['tgiann-inventory']:RemoveItem(src, Config.RequiredItems.flex.name, 1)
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, "Your " .. Config.RequiredItems.flex.label .. " broke!", "error")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif Config.RequiredItems.flex.remove then
|
||||||
|
-- Remove item if configured
|
||||||
|
exports['tgiann-inventory']:RemoveItem(src, Config.RequiredItems.flex.name, Config.RequiredItems.flex.amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check cooldowns
|
-- Give rewards based on chances
|
||||||
local cooldownCheck = lib.callback.await('container_heist:server:checkCooldown', false, point.id)
|
local rewardsGiven = 0
|
||||||
if not cooldownCheck.success then
|
for _, reward in pairs(containerType.rewards) do
|
||||||
QBCore.Functions.Notify(cooldownCheck.message, "error")
|
if math.random(1, 100) <= reward.chance then
|
||||||
isRobbing = false
|
local amount = math.random(reward.min, reward.max)
|
||||||
currentPoint = nil
|
|
||||||
return
|
if reward.item == "cash" then
|
||||||
|
Player.Functions.AddMoney("cash", amount)
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, "Found $" .. amount, "success")
|
||||||
|
else
|
||||||
|
-- Add item with proper metadata for weapons
|
||||||
|
if string.match(reward.item, "weapon_") then
|
||||||
|
exports['tgiann-inventory']:AddItem(src, reward.item, amount, nil, {
|
||||||
|
serie = "HEIST-" .. math.random(100000, 999999),
|
||||||
|
durabilityPercent = 100,
|
||||||
|
usedTotalAmmo = 0,
|
||||||
|
ammo = 0
|
||||||
|
})
|
||||||
|
else
|
||||||
|
exports['tgiann-inventory']:AddItem(src, reward.item, amount)
|
||||||
|
end
|
||||||
|
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, "Found " .. amount .. "x " .. reward.label, "success")
|
||||||
|
end
|
||||||
|
|
||||||
|
rewardsGiven = rewardsGiven + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check police count
|
if rewardsGiven == 0 then
|
||||||
local policeCount = lib.callback.await('container_heist:server:getPoliceCount', false)
|
TriggerClientEvent('QBCore:Notify', src, "The container was empty!", "error")
|
||||||
if policeCount < Config.PoliceRequired then
|
|
||||||
QBCore.Functions.Notify(Config.Notifications.notEnoughPolice, "error")
|
|
||||||
isRobbing = false
|
|
||||||
currentPoint = nil
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Position player for animation
|
-- Clean up cooldowns periodically
|
||||||
SetEntityCoords(PlayerPedId(), point.coords.x, point.coords.y, point.coords.z)
|
|
||||||
SetEntityHeading(PlayerPedId(), point.heading)
|
|
||||||
|
|
||||||
-- Alert police if configured
|
|
||||||
if containerType.policeAlert then
|
|
||||||
local streetName = GetStreetNameFromHashKey(GetStreetNameAtCoord(point.coords.x, point.coords.y, point.coords.z))
|
|
||||||
TriggerServerEvent('container_heist:server:alertPolice', point.coords, streetName, containerType.label)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Start robbery progress bar
|
|
||||||
PlayRobberyAnimation(containerType)
|
|
||||||
|
|
||||||
QBCore.Functions.Progressbar("container_robbery", 'Breaking into ' .. containerType.label, containerType.animation.duration, false, true, {
|
|
||||||
disableMovement = true,
|
|
||||||
disableCarMovement = true,
|
|
||||||
disableMouse = false,
|
|
||||||
disableCombat = true,
|
|
||||||
}, {}, {}, {}, function() -- Done
|
|
||||||
-- Success
|
|
||||||
TriggerServerEvent('container_heist:server:finishRobbery', point.id, point.type)
|
|
||||||
QBCore.Functions.Notify(Config.Notifications.success, "success")
|
|
||||||
isRobbing = false
|
|
||||||
currentPoint = nil
|
|
||||||
end, function() -- Cancel
|
|
||||||
-- Cancelled
|
|
||||||
QBCore.Functions.Notify(Config.Notifications.failed, "error")
|
|
||||||
isRobbing = false
|
|
||||||
currentPoint = nil
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Command to start container robbery
|
|
||||||
RegisterCommand('robcontainer', function()
|
|
||||||
local point, distance = GetNearestContainerPoint()
|
|
||||||
|
|
||||||
if point then
|
|
||||||
StartContainerRobbery(point)
|
|
||||||
else
|
|
||||||
QBCore.Functions.Notify("No container nearby!", "error")
|
|
||||||
end
|
|
||||||
end, false)
|
|
||||||
|
|
||||||
-- Command to toggle debug mode
|
|
||||||
RegisterCommand('containerdebug', function()
|
|
||||||
Config.Debug = not Config.Debug
|
|
||||||
|
|
||||||
if Config.Debug then
|
|
||||||
QBCore.Functions.Notify("Container Debug mode enabled", "primary")
|
|
||||||
else
|
|
||||||
QBCore.Functions.Notify("Container Debug mode disabled", "primary")
|
|
||||||
end
|
|
||||||
end, false)
|
|
||||||
|
|
||||||
-- Main thread for checking nearby container points
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
local playerPed = PlayerPedId()
|
Wait(60000) -- Check every minute
|
||||||
local playerCoords = GetEntityCoords(playerPed)
|
local currentTime = os.time()
|
||||||
local wait = 1000
|
|
||||||
local point, distance = GetNearestContainerPoint()
|
|
||||||
|
|
||||||
if point and distance < 3.0 then
|
-- Clean up player cooldowns
|
||||||
wait = 0
|
for citizenId, cooldownTime in pairs(playerCooldowns) do
|
||||||
nearbyPoint = point
|
if (currentTime - cooldownTime) > (Config.CooldownTime * 60) then
|
||||||
|
playerCooldowns[citizenId] = nil
|
||||||
-- Draw marker
|
|
||||||
DrawMarker(1, point.coords.x, point.coords.y, point.coords.z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.8, 0.8, 0.8, 0, 255, 0, 100, false, true, 2, false, nil, nil, false)
|
|
||||||
|
|
||||||
-- Draw text
|
|
||||||
DrawText3D(point.coords.x, point.coords.y, point.coords.z, point.label .. " [E]")
|
|
||||||
|
|
||||||
-- Check for interaction
|
|
||||||
if IsControlJustReleased(0, 38) and distance < 1.5 then -- E key
|
|
||||||
StartContainerRobbery(point)
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
nearbyPoint = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Wait(wait)
|
-- Clean up point cooldowns
|
||||||
end
|
for pointId, cooldownTime in pairs(pointCooldowns) do
|
||||||
end)
|
if (currentTime - cooldownTime) > (Config.CooldownTime * 60) then
|
||||||
|
pointCooldowns[pointId] = nil
|
||||||
-- Debug thread for showing all container points
|
end
|
||||||
CreateThread(function()
|
end
|
||||||
while true do
|
|
||||||
Wait(0)
|
-- Clean up global cooldowns
|
||||||
|
for containerType, cooldownTime in pairs(globalCooldowns) do
|
||||||
if Config.Debug then
|
if (currentTime - cooldownTime) > (Config.GlobalCooldown * 60) then
|
||||||
for _, point in pairs(Config.ContainerPoints) do
|
globalCooldowns[containerType] = nil
|
||||||
DrawMarker(1, point.coords.x, point.coords.y, point.coords.z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 255, 0, 0, 100, false, true, 2, false, nil, nil, false)
|
|
||||||
DrawText3D(point.coords.x, point.coords.y, point.coords.z + 0.5, point.id .. " (" .. point.type .. ")")
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
Wait(1000)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Event to show police alert
|
|
||||||
RegisterNetEvent('container_heist:client:policeAlert', function(coords, streetName, containerLabel)
|
|
||||||
local playerJob = QBCore.Functions.GetPlayerData().job.name
|
|
||||||
local alertTitle = Config.Notifications.policeTitle
|
|
||||||
|
|
||||||
-- Customize alert based on job
|
|
||||||
if playerJob == "marshal" then
|
|
||||||
alertTitle = "MARSHAL SERVICE ALERT"
|
|
||||||
elseif playerJob == "sheriff" then
|
|
||||||
alertTitle = "SHERIFF DEPARTMENT ALERT"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Create alert for police officers
|
|
||||||
QBCore.Functions.Notify(alertTitle .. ": " .. string.format(Config.Notifications.policeMessage, streetName), "police", 10000)
|
|
||||||
|
|
||||||
-- Add blip to map
|
|
||||||
CreateRobberyBlip(coords)
|
|
||||||
|
|
||||||
-- Play alert sound
|
|
||||||
PlaySound(-1, "Lose_1st", "GTAO_FM_Events_Soundset", 0, 0, 1)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Clean up on resource stop
|
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
|
||||||
if resourceName == GetCurrentResourceName() then
|
|
||||||
if containerBlip then
|
|
||||||
RemoveBlip(containerBlip)
|
|
||||||
end
|
|
||||||
|
|
||||||
if isRobbing then
|
|
||||||
StopAnimTask(PlayerPedId(), "amb@world_human_welding@male@base", "base", 1.0)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue