forked from Simnation/Main
ed
This commit is contained in:
parent
8a40491de2
commit
3cfe5d57dc
3 changed files with 156 additions and 2 deletions
|
@ -59,3 +59,32 @@ end)
|
|||
RegisterNetEvent('trash:client:notifyEmptied', function()
|
||||
lib.notify(Config.Notifications.trashCanEmptied)
|
||||
end)
|
||||
|
||||
-- Get the trash can the player is looking at (for admin command)
|
||||
RegisterNetEvent('trash:client:getTargetTrashCan', function()
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
local found = false
|
||||
|
||||
-- Check if we're looking at a trash can
|
||||
if currentEntity and DoesEntityExist(currentEntity) then
|
||||
local model = GetEntityModel(currentEntity)
|
||||
|
||||
-- Check if this model is in our trash can list
|
||||
for _, trashModel in ipairs(Config.TrashCanModels) do
|
||||
if model == GetHashKey(trashModel) then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if found then
|
||||
local containerID = GetContainerIDFromEntity(currentEntity)
|
||||
TriggerServerEvent('trash:server:fillTargetTrashCan', containerID)
|
||||
else
|
||||
lib.notify(Config.Notifications.noTrashCanFound)
|
||||
end
|
||||
else
|
||||
lib.notify(Config.Notifications.noTrashCanFound)
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -6,12 +6,13 @@ Config.CheckFrequency = 30 -- How often to check for trash cans to empty (in mi
|
|||
|
||||
-- Trash can models that can be interacted with
|
||||
Config.TrashCanModels = {
|
||||
'prop_bin_08a',
|
||||
'p_secret_weapon_02',
|
||||
'prop_bin_01a',
|
||||
'prop_bin_03a',
|
||||
'prop_bin_04a',
|
||||
'prop_bin_07a',
|
||||
'prop_bin_07d',
|
||||
'prop_bin_08a',
|
||||
'prop_cs_bin_01',
|
||||
'prop_cs_bin_01_skinned',
|
||||
'prop_cs_bin_02',
|
||||
|
@ -26,6 +27,43 @@ Config.TrashCanInventory = {
|
|||
label = 'Mülltonne'
|
||||
}
|
||||
|
||||
-- Random item spawn settings
|
||||
Config.RandomItems = {
|
||||
enabled = true, -- Enable/disable random item spawning
|
||||
chanceToSpawn = 75, -- Percentage chance that items will spawn after emptying (0-100)
|
||||
minItems = 1, -- Minimum number of items to spawn
|
||||
maxItems = 5, -- Maximum number of items to spawn
|
||||
|
||||
-- Items that can spawn in trash cans with their probabilities
|
||||
-- Format: {name = "item_name", amount = {min, max}, chance = probability_percentage}
|
||||
items = {
|
||||
-- Common trash items (70-90% chance)
|
||||
{name = "empty_bottle", amount = {1, 5}, chance = 90},
|
||||
{name = "empty_can", amount = {1, 5}, chance = 85},
|
||||
{name = "paper_trash", amount = {1, 3}, chance = 80},
|
||||
{name = "banana_peel", amount = {1, 2}, chance = 75},
|
||||
{name = "plastic_bag", amount = {1, 3}, chance = 70},
|
||||
|
||||
-- Uncommon items (30-60% chance)
|
||||
{name = "broken_phone", amount = {1, 1}, chance = 60},
|
||||
{name = "old_newspaper", amount = {1, 3}, chance = 50},
|
||||
{name = "empty_cigarette_pack", amount = {1, 2}, chance = 40},
|
||||
{name = "food_waste", amount = {1, 3}, chance = 30},
|
||||
|
||||
-- Rare items (10-25% chance)
|
||||
{name = "damaged_electronics", amount = {1, 1}, chance = 25},
|
||||
{name = "scrap_metal", amount = {1, 2}, chance = 20},
|
||||
{name = "rubber_gloves", amount = {1, 1}, chance = 15},
|
||||
{name = "aluminum_can", amount = {1, 3}, chance = 10},
|
||||
|
||||
-- Very rare items (1-5% chance)
|
||||
{name = "lost_wallet", amount = {1, 1}, chance = 5},
|
||||
{name = "broken_watch", amount = {1, 1}, chance = 3},
|
||||
{name = "old_jewelry", amount = {1, 1}, chance = 2},
|
||||
{name = "rare_collectible", amount = {1, 1}, chance = 1},
|
||||
}
|
||||
}
|
||||
|
||||
-- Notification settings
|
||||
Config.Notifications = {
|
||||
noTrashCanFound = {
|
||||
|
@ -56,5 +94,7 @@ Config.Logs = {
|
|||
enabled = true,
|
||||
webhookName = 'trash', -- Name of the webhook in qb-log
|
||||
emptyTitle = 'Trash Can Emptied',
|
||||
emptyColor = 'blue'
|
||||
emptyColor = 'blue',
|
||||
spawnTitle = 'Items Spawned in Trash',
|
||||
spawnColor = 'green'
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue