forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
e5cefcb85b
commit
06dcf1e338
1 changed files with 25 additions and 10 deletions
|
@ -165,13 +165,33 @@ end)
|
||||||
|
|
||||||
-- Register a new bowl (for props placed with ProPlacer)
|
-- Register a new bowl (for props placed with ProPlacer)
|
||||||
RegisterNetEvent('pet-bowls:client:registerNewBowl', function(modelName, bowlType)
|
RegisterNetEvent('pet-bowls:client:registerNewBowl', function(modelName, bowlType)
|
||||||
|
-- Check if we received parameters directly or as part of a data table
|
||||||
|
local model, type
|
||||||
|
|
||||||
|
-- Handle both direct parameters and data table format
|
||||||
|
if type(modelName) == "table" and modelName.modelName then
|
||||||
|
-- We received a data table from qb-target
|
||||||
|
model = modelName.modelName
|
||||||
|
type = modelName.bowlType
|
||||||
|
else
|
||||||
|
-- We received direct parameters
|
||||||
|
model = modelName
|
||||||
|
type = bowlType
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Ensure we have valid parameters
|
||||||
|
if not model or not type then
|
||||||
|
print("^1[Pet-Bowls]^7 Missing model or type for bowl registration")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Find the closest valid prop
|
-- Find the closest valid prop
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
local playerCoords = GetEntityCoords(playerPed)
|
local playerCoords = GetEntityCoords(playerPed)
|
||||||
|
|
||||||
local closestObject = nil
|
local closestObject = nil
|
||||||
local closestDistance = 3.0 -- Maximum distance to consider
|
local closestDistance = 3.0 -- Maximum distance to consider
|
||||||
local validModel = GetHashKey(modelName)
|
local validModel = GetHashKey(model)
|
||||||
|
|
||||||
local objects = GetGamePool('CObject')
|
local objects = GetGamePool('CObject')
|
||||||
for _, object in pairs(objects) do
|
for _, object in pairs(objects) do
|
||||||
|
@ -194,7 +214,7 @@ RegisterNetEvent('pet-bowls:client:registerNewBowl', function(modelName, bowlTyp
|
||||||
local coords = GetEntityCoords(closestObject)
|
local coords = GetEntityCoords(closestObject)
|
||||||
local heading = GetEntityHeading(closestObject)
|
local heading = GetEntityHeading(closestObject)
|
||||||
|
|
||||||
TriggerServerEvent('pet-bowls:server:placeBowl', bowlId, modelName, bowlType, {
|
TriggerServerEvent('pet-bowls:server:placeBowl', bowlId, model, type, {
|
||||||
x = coords.x,
|
x = coords.x,
|
||||||
y = coords.y,
|
y = coords.y,
|
||||||
z = coords.z,
|
z = coords.z,
|
||||||
|
@ -205,13 +225,13 @@ RegisterNetEvent('pet-bowls:client:registerNewBowl', function(modelName, bowlTyp
|
||||||
placedBowls[bowlId] = {
|
placedBowls[bowlId] = {
|
||||||
object = closestObject,
|
object = closestObject,
|
||||||
id = bowlId,
|
id = bowlId,
|
||||||
model = modelName,
|
model = model,
|
||||||
type = bowlType,
|
type = type,
|
||||||
fillLevel = 0
|
fillLevel = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Add target
|
-- Add target
|
||||||
AddTargetToBowl(closestObject, bowlId, bowlType)
|
AddTargetToBowl(closestObject, bowlId, type)
|
||||||
|
|
||||||
lib.notify(Config.Notifications.bowlPlaced)
|
lib.notify(Config.Notifications.bowlPlaced)
|
||||||
else
|
else
|
||||||
|
@ -310,8 +330,3 @@ Citizen.CreateThread(function()
|
||||||
|
|
||||||
print("^2[Pet-Bowls]^7 Added registration targets to " .. addedTargets .. " unregistered bowl props")
|
print("^2[Pet-Bowls]^7 Added registration targets to " .. addedTargets .. " unregistered bowl props")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Event handler for registering from target
|
|
||||||
RegisterNetEvent('pet-bowls:client:registerNewBowl', function(data)
|
|
||||||
TriggerEvent('pet-bowls:client:registerNewBowl', data.modelName, data.bowlType)
|
|
||||||
end)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue