1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-28 02:37:52 +02:00
parent 8a40491de2
commit 3cfe5d57dc
3 changed files with 156 additions and 2 deletions

View file

@ -78,6 +78,11 @@ function EmptyTrashCans()
nextEmptyTime = currentTime + (Config.EmptyInterval * 60)
}
-- Spawn random items if enabled
if Config.RandomItems.enabled then
SpawnRandomItems(containerID)
end
emptiedCount = emptiedCount + 1
end
end
@ -132,6 +137,52 @@ function EmptyTrashCan(containerID)
end
end
-- Spawn random items in a trash can with simplified probability system
function SpawnRandomItems(containerID)
-- Check if we should spawn items based on chance
if math.random(1, 100) > Config.RandomItems.chanceToSpawn then
return
end
-- Determine how many items to spawn
local itemCount = math.random(Config.RandomItems.minItems, Config.RandomItems.maxItems)
local spawnedItems = {}
-- Try to spawn each item based on its individual chance
for i = 1, itemCount do
-- Randomly select an item to try spawning
local itemToTry = Config.RandomItems.items[math.random(1, #Config.RandomItems.items)]
-- Check if this item should spawn based on its chance
if math.random(1, 100) <= itemToTry.chance then
-- Determine amount
local amount = math.random(itemToTry.amount[1], itemToTry.amount[2])
-- Add to inventory
exports["tgiann-inventory"]:AddItemToSecondaryInventory("stash", containerID, itemToTry.name, amount)
-- Track for logging
table.insert(spawnedItems, {name = itemToTry.name, amount = amount})
end
end
-- Log the spawned items
if #spawnedItems > 0 and Config.Logs.enabled then
local itemList = ""
for _, item in pairs(spawnedItems) do
itemList = itemList .. '' .. item.amount .. 'x ' .. item.name .. '\n'
end
TriggerEvent('qb-log:server:CreateLog', Config.Logs.webhookName,
Config.Logs.spawnTitle,
Config.Logs.spawnColor,
'**Trash Can:** ' .. containerID ..
'\n**Action:** Random items spawned' ..
'\n**Total Items:** ' .. #spawnedItems ..
'\n**Items:**\n' .. itemList)
end
end
-- Command to manually trigger trash emptying (admin only)
QBCore.Commands.Add('emptytrash', 'Empty all trash cans (Admin Only)', {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
@ -142,3 +193,37 @@ QBCore.Commands.Add('emptytrash', 'Empty all trash cans (Admin Only)', {}, false
TriggerClientEvent('ox_lib:notify', source, Config.Notifications.noPermission)
end
end, 'admin')
-- Command to manually spawn items in a trash can (admin only)
QBCore.Commands.Add('filltrash', 'Fill trash can with random items (Admin Only)', {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
if Player.PlayerData.permission == "admin" or Player.PlayerData.permission == "god" then
-- Get the trash can the player is looking at
TriggerClientEvent('trash:client:getTargetTrashCan', source)
else
TriggerClientEvent('ox_lib:notify', source, Config.Notifications.noPermission)
end
end, 'admin')
-- Receive the target trash can from client
RegisterNetEvent('trash:server:fillTargetTrashCan', function(containerID)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player or not containerID then return end
if Player.PlayerData.permission == "admin" or Player.PlayerData.permission == "god" then
-- Register this trash can if it's new
if not trashCans[containerID] then
TriggerEvent('trash:server:registerTrashCan', containerID)
end
-- Spawn items in it
SpawnRandomItems(containerID)
TriggerClientEvent('ox_lib:notify', src, {
title = 'System',
description = 'Mülltonne wurde mit zufälligen Items gefüllt',
type = 'success'
})
end
end)