Security HUD
System Watchdog
×
Threads Scanned
-- / --
SYS. LOAD --%
AI SHIELD ACTIVE
DMCA Policy
×

📋 DMCA Compliance

This platform and community fully complies with the Digital Millennium Copyright Act (DMCA) and international copyright laws. We take all copyright protection seriously.

🛡️ Copyright Protection

If you believe a posted item belongs to you or violates your copyright, you may file a DMCA takedown request through our official channels. Upon receiving a valid claim, the infringing content will be removed within 24 hours.

What's new
×
Fiveguard

Question Qb core help

Adamnaylor76

Member
Joined
Dec 28, 2023
Messages
8
Reaction score
0
Points
156
Location
Uk
I’m new to qb core and was wondering, if I wanted to reward players with a chance to get a random item from a loot pool while doing jobs ect.. as well as getting paid how would I go about adding that? Will I need a full script? Or can I just write a line of code?

Similar to how the qb-garbage has a chance to give you a crypto stick

TIA
 

sh4dow_g2

Gold Elite
Joined
Jan 23, 2022
Messages
91
Reaction score
134
Points
256
Location
United Kingdom
You could do something like this



local lootPool = {
{item = "water", probability = 0.5},
{item = "bread", probability = 0.3},
{item = "crypto_stick", probability = 0.1},
{item = "gold_watch", probability = 0.1}
}

local function getRandomItem()
local randomValue = math.random()
local cumulativeProbability = 0

for _, loot in ipairs(lootPool) do
cumulativeProbability = cumulativeProbability + loot.probability
if randomValue <= cumulativeProbability then
return loot.item
end
end
end

RegisterNetEvent('qb-customjob:server:CompleteTask')
AddEventHandler('qb-customjob:server:CompleteTask', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)

-- Normal payment logic
Player.Functions.AddMoney('cash', 100, "Completed job task")

-- Random item reward logic
local randomItem = getRandomItem()
if randomItem then
Player.Functions.AddItem(randomItem, 1)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[randomItem], 'add')
end
end)
 
Top