ed
This commit is contained in:
parent
a700c6d796
commit
ef4fd3eece
2 changed files with 230 additions and 127 deletions
|
@ -16,7 +16,7 @@ function LoadBowls()
|
|||
id = bowl.bowl_id,
|
||||
model = bowl.model,
|
||||
type = bowl.type,
|
||||
fillLevel = bowl.fill_level,
|
||||
fill_level = bowl.fill_level,
|
||||
coords = bowl.coords
|
||||
}
|
||||
end
|
||||
|
@ -51,12 +51,13 @@ RegisterNetEvent('pet-bowls:server:placeBowl', function(bowlId, model, bowlType,
|
|||
id = bowlId,
|
||||
model = model,
|
||||
type = bowlType,
|
||||
fillLevel = 0,
|
||||
fill_level = 0,
|
||||
coords = coordsJson
|
||||
}
|
||||
|
||||
-- Notify all clients about the new bowl
|
||||
TriggerClientEvent('pet-bowls:client:updateBowlLevel', -1, bowlId, 0)
|
||||
print('^2[Pet-Bowls]^7 New bowl registered: ' .. bowlId)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
@ -84,10 +85,10 @@ RegisterNetEvent('pet-bowls:server:fillBowl', function(bowlId, itemName, fillAmo
|
|||
-- Update bowl fill level
|
||||
local bowl = bowls[bowlId]
|
||||
if bowl then
|
||||
local newLevel = math.min(100, bowl.fillLevel + fillAmount)
|
||||
local newLevel = math.min(100, bowl.fill_level + fillAmount)
|
||||
|
||||
-- Update in memory
|
||||
bowl.fillLevel = newLevel
|
||||
bowl.fill_level = newLevel
|
||||
|
||||
-- Update in database
|
||||
MySQL.update('UPDATE pet_bowls SET fill_level = ?, last_refill = CURRENT_TIMESTAMP WHERE bowl_id = ?',
|
||||
|
@ -97,6 +98,8 @@ RegisterNetEvent('pet-bowls:server:fillBowl', function(bowlId, itemName, fillAmo
|
|||
-- Update all clients
|
||||
TriggerClientEvent('pet-bowls:client:updateBowlLevel', -1, bowlId, newLevel)
|
||||
TriggerClientEvent('ox_lib:notify', src, Config.Notifications.bowlFilled)
|
||||
|
||||
print('^2[Pet-Bowls]^7 Bowl ' .. bowlId .. ' filled to ' .. newLevel .. '%')
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -123,17 +126,17 @@ RegisterNetEvent('pet-bowls:server:consumeBowl', function(bowlId)
|
|||
if not bowlConfig then return end
|
||||
|
||||
-- Check if bowl has content
|
||||
if bowl.fillLevel <= 0 then
|
||||
if bowl.fill_level <= 0 then
|
||||
TriggerClientEvent('ox_lib:notify', src, Config.Notifications.bowlEmpty)
|
||||
return
|
||||
end
|
||||
|
||||
-- Consume from bowl
|
||||
local consumeAmount = bowlConfig.consumeAmount
|
||||
local newLevel = math.max(0, bowl.fillLevel - consumeAmount)
|
||||
local newLevel = math.max(0, bowl.fill_level - consumeAmount)
|
||||
|
||||
-- Update in memory
|
||||
bowl.fillLevel = newLevel
|
||||
bowl.fill_level = newLevel
|
||||
|
||||
-- Update in database
|
||||
MySQL.update('UPDATE pet_bowls SET fill_level = ? WHERE bowl_id = ?',
|
||||
|
@ -162,6 +165,8 @@ RegisterNetEvent('pet-bowls:server:consumeBowl', function(bowlId)
|
|||
-- Update all clients
|
||||
TriggerClientEvent('pet-bowls:client:updateBowlLevel', -1, bowlId, newLevel)
|
||||
TriggerClientEvent('ox_lib:notify', src, Config.Notifications.consumed)
|
||||
|
||||
print('^2[Pet-Bowls]^7 Bowl ' .. bowlId .. ' consumed, new level: ' .. newLevel .. '%')
|
||||
end)
|
||||
|
||||
-- Remove a bowl from database (if needed)
|
||||
|
@ -179,4 +184,11 @@ RegisterNetEvent('pet-bowls:server:removeBowl', function(bowlId)
|
|||
|
||||
-- Notify all clients
|
||||
TriggerClientEvent('pet-bowls:client:bowlRemoved', -1, bowlId)
|
||||
|
||||
print('^2[Pet-Bowls]^7 Bowl removed: ' .. bowlId)
|
||||
end)
|
||||
|
||||
-- Register command to register bowls
|
||||
QBCore.Commands.Add('registerbowl', 'Register a nearby bowl prop', {}, false, function(source, args)
|
||||
TriggerClientEvent('pet-bowls:client:openRegisterBowlMenu', source)
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue