183 lines
5.0 KiB
Lua
183 lines
5.0 KiB
Lua
local cameraSpeedKeys = {
|
|
x = "lookSpeedX",
|
|
y = "lookSpeedY",
|
|
speed = "moveSpeed"
|
|
}
|
|
|
|
RegisterNUICallback("toggle_hide_decorate", function(data, cb)
|
|
decorate:toggleHideDecorate()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("spawn_object", function(data, cb)
|
|
if not decorate.active then return cb("ok") end
|
|
|
|
decorate:removeCurrentObject()
|
|
|
|
local isLightItem = table.find(LIGHT_ITEMS, function(item)
|
|
return item.object == data.modelName
|
|
end)
|
|
|
|
local camCoords = decorate:getCamCoords()
|
|
local camRot = decorate:getCamRot()
|
|
local forward = Utils.GetForwardVector(camRot) * 5.0
|
|
local spawnPos = camCoords + forward
|
|
|
|
local spawnedEntity = SpawnObject(data.modelName, spawnPos, vec3(0.0, 0.0, 0.0))
|
|
cb(spawnedEntity)
|
|
|
|
if not spawnedEntity then
|
|
return Notification("Object is not spawned", "error")
|
|
end
|
|
|
|
decorate.currentObject = {
|
|
modelName = data.modelName,
|
|
handle = spawnedEntity,
|
|
price = data.price
|
|
}
|
|
|
|
Debug("Spawned object", "decorate.currentObject", decorate.currentObject)
|
|
|
|
if not isLightItem then return end
|
|
|
|
while decorate.currentObject and decorate.currentObject.handle do
|
|
Wait(0)
|
|
local objRot = GetEntityRotation(decorate.currentObject.handle)
|
|
local objCoords = GetEntityCoords(decorate.currentObject.handle)
|
|
local direction = RotationToDirection(objRot)
|
|
|
|
DrawSpotLight(
|
|
objCoords.x, objCoords.y, objCoords.z,
|
|
direction.x, direction.y, direction.z,
|
|
255, 255, 255,
|
|
100.0, 20.0, 1.0,
|
|
Config.DefaultLightIntensity, 0.0
|
|
)
|
|
end
|
|
end)
|
|
|
|
RegisterNUICallback("place_object_on_ground", function(data, cb)
|
|
local currentHandle = decorate.currentObject and decorate.currentObject.handle
|
|
if not currentHandle then return cb("ok") end
|
|
decorate:placeObjectOnGround()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("set_current_page", function(data, cb)
|
|
decorate.currentPage = data
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("toggle_cursor", function(data, cb)
|
|
decorate:setFocus()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("save_locations", function(data, cb)
|
|
decorate:saveObjects()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("sell_current_object", function(data, cb)
|
|
local stashId = decorate.currentObject and decorate.currentObject.stashId
|
|
if not stashId then
|
|
Error("sell_current_object", "Selected object id is nil", stashId)
|
|
return
|
|
end
|
|
|
|
local foundObject = table.find(decorate.objects, function(obj)
|
|
return obj.id == decorate.currentObject.stashId
|
|
end)
|
|
|
|
if not foundObject then
|
|
Error("sell_current_object", "Object not found", decorate.currentObject.stashId)
|
|
return
|
|
end
|
|
|
|
TriggerServerEvent("garages:decorate:sellFurniture", currentlyInGarage, decorate.currentObject.stashId)
|
|
decorate:removeCurrentObject()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("update_stash", function(data, cb)
|
|
TriggerServerEvent("garages:decorate:updateObject", currentlyInGarage, decorate.currentObject.stashId, data)
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("buy_object", function(data, cb)
|
|
local currentObj = decorate.currentObject
|
|
if not currentObj then
|
|
Error("buy_object", "Current object is nil", currentObj)
|
|
cb("ok")
|
|
return
|
|
end
|
|
|
|
Debug("buy_object", "Current object", currentObj)
|
|
|
|
local success = lib.callback.await("garages:decorate:buyDecorationObject", false, currentObj.price)
|
|
if not success then
|
|
decorate:removeCurrentObject()
|
|
cb("ok")
|
|
return
|
|
end
|
|
|
|
decorate:saveCurrentObject()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("get_owned_objects", function(data, cb)
|
|
cb(decorate.objects)
|
|
end)
|
|
|
|
RegisterNUICallback("select_owned_object", function(data, cb)
|
|
local objectId = data
|
|
local foundObject = table.find(decorate.objects, function(obj)
|
|
return obj.id == objectId
|
|
end)
|
|
|
|
if not foundObject then
|
|
Error("select_owned_object", "Object not found", objectId)
|
|
return
|
|
end
|
|
|
|
decorate.currentObject = {
|
|
handle = foundObject.handle,
|
|
modelName = foundObject.modelName,
|
|
stashId = foundObject.id
|
|
}
|
|
|
|
Debug("Selected object", "data", foundObject, "objectData", foundObject)
|
|
cb(true)
|
|
end)
|
|
|
|
RegisterNUICallback("deselect_owned_object", function(data, cb)
|
|
decorate:removeCurrentObject()
|
|
decorate:refreshObjects()
|
|
cb(true)
|
|
end)
|
|
|
|
RegisterNUICallback("remove_current_object", function(data, cb)
|
|
decorate:removeCurrentObject()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("updateCameraSpeed", function(data, cb)
|
|
local settingKey = cameraSpeedKeys[data.type]
|
|
CameraOptions[settingKey] = data.value
|
|
end)
|
|
|
|
RegisterNUICallback("toggle_gizmo_mode", function(data, cb)
|
|
decorate:toggleGizmoMode()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("toggle_free_camera", function(data, cb)
|
|
decorate:toggleFreeCamera()
|
|
cb("ok")
|
|
end)
|
|
|
|
RegisterNUICallback("open_buy_object_modal", function(data, cb)
|
|
decorate:openBuyObjectModal()
|
|
cb("ok")
|
|
end)
|