194 lines
6.1 KiB
Lua
194 lines
6.1 KiB
Lua
RegisterNUICallback("creator_select_points", function(data, cb)
|
|
local zoneData = creator:raycastRectangle()
|
|
creator:open()
|
|
|
|
if not zoneData then
|
|
return cb(nil)
|
|
end
|
|
|
|
zoneData.points = table.map(zoneData.points, function(pt)
|
|
return { x = pt.x, y = pt.y, z = pt.z }
|
|
end)
|
|
|
|
cb(zoneData)
|
|
end)
|
|
|
|
RegisterNUICallback("select_garage", function(data, cb)
|
|
if data and data.zone and data.zone.points then
|
|
creator.raycast.points = table.map(data.zone.points, function(pt)
|
|
return vec3(pt.x, pt.y, pt.z)
|
|
end)
|
|
creator.raycast.height = data.zone.thickness
|
|
else
|
|
creator.raycast.points = {}
|
|
end
|
|
cb(true)
|
|
end)
|
|
|
|
RegisterNUICallback("select_point", function(data, cb)
|
|
if data and data.options and data.options.model then
|
|
if not IsModelInCdimage(data.options.model) then
|
|
Notification(i18n.t("creator.raycast.model_is_not_valid", { model = data.options.model }), "error")
|
|
return cb(nil)
|
|
end
|
|
end
|
|
|
|
local pointType = (data and data.pointType) or "empty"
|
|
local count = (data and data.count) or 1
|
|
local options = (data and data.options) or nil
|
|
|
|
local selectedPoints = creator:selectPoint(pointType, count, options)
|
|
creator:open()
|
|
|
|
if not selectedPoints then
|
|
return cb(nil)
|
|
end
|
|
|
|
local mapped = table.map(selectedPoints, function(pt)
|
|
local entry = { x = pt.x, y = pt.y, z = pt.z }
|
|
if pt.w then entry.w = pt.w end
|
|
return entry
|
|
end)
|
|
|
|
if count == 1 then
|
|
return cb(mapped[1])
|
|
end
|
|
cb(mapped)
|
|
end)
|
|
|
|
RegisterNUICallback("select_entity", function(data, cb)
|
|
local entityType = (data and data.entityType) or "object"
|
|
local count = (data and data.count) or 1
|
|
local options = (data and data.options) or nil
|
|
|
|
Debug("select_entity", data)
|
|
|
|
local selectedEntities = creator:selectEntity(entityType, count, options)
|
|
creator:open()
|
|
|
|
if not selectedEntities then
|
|
return cb(nil)
|
|
end
|
|
|
|
local mapped = table.map(selectedEntities, function(entry)
|
|
return {
|
|
entity = entry.entity,
|
|
coords = { x = entry.coords.x, y = entry.coords.y, z = entry.coords.z, w = entry.coords.w }
|
|
}
|
|
end)
|
|
|
|
if count == 1 then
|
|
return cb(mapped[1])
|
|
end
|
|
cb(mapped)
|
|
end)
|
|
|
|
RegisterNUICallback("create_garage", function(data, cb)
|
|
Debug("create_garage", data)
|
|
|
|
local pedCoords = GetEntityCoords(cache.ped)
|
|
local streetHash = GetStreetNameAtCoord(pedCoords.x, pedCoords.y, pedCoords.z)
|
|
local streetNameRaw = GetStreetNameFromHashKey(streetHash)
|
|
local streetName = string.gsub(streetNameRaw, "%-", " ") .. " Garage"
|
|
|
|
local result = lib.callback.await("garages:createGarage", false, streetName, data)
|
|
cb(result)
|
|
end)
|
|
|
|
RegisterNUICallback("update_garage", function(data, cb)
|
|
local success = lib.callback.await("garages:updateGarage", false, data)
|
|
if success then
|
|
Notification(i18n.t("creator.garage_updated"), "success")
|
|
else
|
|
Notification(i18n.t("creator.garage_update_failed"), "error")
|
|
end
|
|
cb(success)
|
|
end)
|
|
|
|
RegisterNUICallback("remove_garage", function(data, cb)
|
|
local success = lib.callback.await("garages:removeGarage", false, data)
|
|
cb(success)
|
|
end)
|
|
|
|
RegisterNUICallback("teleport_to_garage", function(garageId, cb)
|
|
local garageData = Config.Garages[garageId]
|
|
if not garageData then
|
|
Notification(i18n.t("garage_not_found"), "error")
|
|
return cb(false)
|
|
end
|
|
|
|
local menuCoords = garageData.coords.menuCoords
|
|
RequestCollisionAtCoord(menuCoords.x, menuCoords.y, menuCoords.z)
|
|
SetEntityCoords(cache.ped, menuCoords.x, menuCoords.y, menuCoords.z, false, false, false, false)
|
|
Notification(i18n.t("creator.teleported_to_garage", { garage = garageId }), "success")
|
|
cb(true)
|
|
end)
|
|
|
|
RegisterNUICallback("creator_select_shell", function(data, cb)
|
|
local garageType = (data and data.garageType) or "vehicle"
|
|
local currentShell = (data and data.currentShellId)
|
|
local interiorType = (data and data.interiorType)
|
|
|
|
if interiorType == "shell" and #Config.Shells == 0 then
|
|
creator:open()
|
|
Notification(i18n.t("creator.shell_selector.no_shells_available"), "error")
|
|
return cb(nil)
|
|
end
|
|
|
|
if garageType == "boat" then
|
|
creator:open()
|
|
return cb(nil)
|
|
end
|
|
|
|
DefaultPlayerCoords = GetEntityCoords(cache.ped)
|
|
|
|
if interiorType == "shell" then
|
|
local shellId, shellCoords = RayCastSelector("shell")
|
|
if not shellId or not shellCoords then
|
|
creator:open()
|
|
return cb(nil)
|
|
end
|
|
|
|
local exitCoords = RayCastSelector("exit", { coords = shellCoords, tier = shellId })
|
|
Debug("exitCoords", exitCoords)
|
|
|
|
if not exitCoords then
|
|
creator:open()
|
|
return cb(nil)
|
|
end
|
|
|
|
local shellObject = creator:createShellFromTier(shellCoords.xyz, shellId, shellCoords.w)
|
|
SetEntityCoords(cache.ped, exitCoords.x, exitCoords.y, exitCoords.z, false, false, false, false)
|
|
Wait(100)
|
|
|
|
local vehicleSlots = creator:selectPoint("vehicle", nil, { pressEnterToSelect = true, disablePoints = true })
|
|
SetEntityCoords(cache.ped, DefaultPlayerCoords.x, DefaultPlayerCoords.y, DefaultPlayerCoords.z, false, false, false, false)
|
|
DeleteEntity(shellObject)
|
|
|
|
if not vehicleSlots or #vehicleSlots == 0 then
|
|
creator:open()
|
|
return cb(nil)
|
|
end
|
|
|
|
creator:open()
|
|
cb({
|
|
shell = shellId,
|
|
coords = { x = shellCoords.x, y = shellCoords.y, z = shellCoords.z, w = shellCoords.w },
|
|
exitCoords = { x = exitCoords.x, y = exitCoords.y, z = exitCoords.z, w = exitCoords.w },
|
|
vehicleCoords = table.map(vehicleSlots, function(slot)
|
|
return { coords = { x = slot.x, y = slot.y, z = slot.z, w = slot.w } }
|
|
end)
|
|
})
|
|
return
|
|
end
|
|
|
|
local selectedShell = ShowcaseOfGarageShell(currentShell, garageType)
|
|
if not selectedShell then
|
|
creator:open()
|
|
return cb(nil)
|
|
end
|
|
|
|
creator:open()
|
|
cb({ shell = selectedShell })
|
|
end)
|