Cleanup and placeable_object replacement
Added cleaned up and improved functionality for placeable object. Example is in unit tests. Cleanup whitespace and removed accessibility as not used/not documented and doesnt appear to be useful with our current work flow
This commit is contained in:
1 parent
b5dd8c018c
commit
3fa933fab1
24 files changed
+698
-903
No files matched your search
@@ -27,7 +27,6 @@ local function SpawnEntity(entityData)
|
||||
SetEntityRotation(entity, rotation.x, rotation.y, rotation.z, 2, true)
|
||||
elseif entityData.entityType == 'ped' then
|
||||
entity = CreatePed(4, model, coords.x, coords.y, coords.z, type(rotation) == 'number' and rotation or rotation.z, false, false)
|
||||
-- Apply ped specific settings from entityData.meta if needed
|
||||
elseif entityData.entityType == 'vehicle' then
|
||||
entity = CreateVehicle(model, coords.x, coords.y, coords.z, type(rotation) == 'number' and rotation or rotation.z, false, false)
|
||||
else
|
||||
|
||||
+2
-2
@@ -62,14 +62,14 @@ cLib.Cache = Cache or Require("lib/cache/shared/cache.lua")
|
||||
cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua")
|
||||
cLib.Marker = Marker or Require("lib/markers/server/server.lua")
|
||||
cLib.Particle = Particle or Require("lib/particles/server/particles.lua")
|
||||
cLib.Shell = Shells or Require("lib/shells/server/shells.lua")
|
||||
if IsDuplicityVersion() then return cLib end
|
||||
::client::
|
||||
|
||||
cLib.Gizmo = Gizmo or Require("lib/placers/client/gizmo.lua")
|
||||
cLib.Scaleform = Scaleform or Require("lib/scaleform/client/scaleform.lua")
|
||||
cLib.Placeable = Placeable or Require("lib/placers/client/object_placer.lua")
|
||||
cLib.Utility = Utility or Require("lib/utility/client/utility.lua")
|
||||
cLib.PlaceableObject = PlaceableObject or Require("lib/placers/client/placeable_object.lua")
|
||||
cLib.PlaceableObject = ObjectPlacer or Require("lib/placers/client/placeable_object.lua")
|
||||
cLib.Raycast = Raycast or Require("lib/raycast/client/raycast.lua")
|
||||
cLib.Point = Point or Require("lib/points/client/points.lua")
|
||||
cLib.Particle = Particle or Require("lib/particles/client/particles.lua")
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
local dataView = setmetatable({
|
||||
EndBig = ">",
|
||||
EndLittle = "<",
|
||||
Types = {
|
||||
Int8 = { code = "i1" },
|
||||
Uint8 = { code = "I1" },
|
||||
Int16 = { code = "i2" },
|
||||
Uint16 = { code = "I2" },
|
||||
Int32 = { code = "i4" },
|
||||
Uint32 = { code = "I4" },
|
||||
Int64 = { code = "i8" },
|
||||
Uint64 = { code = "I8" },
|
||||
Float32 = { code = "f", size = 4 }, -- a float (native size)
|
||||
Float64 = { code = "d", size = 8 }, -- a double (native size)
|
||||
|
||||
LuaInt = { code = "j" }, -- a lua_Integer
|
||||
UluaInt = { code = "J" }, -- a lua_Unsigned
|
||||
LuaNum = { code = "n" }, -- a lua_Number
|
||||
String = { code = "z", size = -1, }, -- zero terminated string
|
||||
},
|
||||
|
||||
FixedTypes = {
|
||||
String = { code = "c" }, -- a fixed-sized string with n bytes
|
||||
Int = { code = "i" }, -- a signed int with n bytes
|
||||
Uint = { code = "I" }, -- an unsigned int with n bytes
|
||||
},
|
||||
}, {
|
||||
__call = function(_, length)
|
||||
return dataView.ArrayBuffer(length)
|
||||
end
|
||||
})
|
||||
dataView.__index = dataView
|
||||
|
||||
--[[ Create an ArrayBuffer with a size in bytes --]]
|
||||
function dataView.ArrayBuffer(length)
|
||||
return setmetatable({
|
||||
blob = string.blob(length),
|
||||
length = length,
|
||||
offset = 1,
|
||||
cangrow = true,
|
||||
}, dataView)
|
||||
end
|
||||
|
||||
--[[ Wrap a non-internalized string --]]
|
||||
function dataView.Wrap(blob)
|
||||
return setmetatable({
|
||||
blob = blob,
|
||||
length = blob:len(),
|
||||
offset = 1,
|
||||
cangrow = true,
|
||||
}, dataView)
|
||||
end
|
||||
|
||||
--[[ Return the underlying bytebuffer --]]
|
||||
function dataView:Buffer() return self.blob end
|
||||
function dataView:ByteLength() return self.length end
|
||||
function dataView:ByteOffset() return self.offset end
|
||||
function dataView:SubView(offset, length)
|
||||
return setmetatable({
|
||||
blob = self.blob,
|
||||
length = length or self.length,
|
||||
offset = 1 + offset,
|
||||
cangrow = false,
|
||||
}, dataView)
|
||||
end
|
||||
|
||||
--[[ Return the Endianness format character --]]
|
||||
local function ef(big) return (big and dataView.EndBig) or dataView.EndLittle end
|
||||
|
||||
--[[ Helper function for setting fixed datatypes within a buffer --]]
|
||||
local function packblob(self, offset, value, code)
|
||||
-- If cangrow is false the dataview represents a subview, i.e., a subset
|
||||
-- of some other string view. Ensure the references are the same before
|
||||
-- updating the subview
|
||||
local packed = self.blob:blob_pack(offset, code, value)
|
||||
if self.cangrow or packed == self.blob then
|
||||
self.blob = packed
|
||||
self.length = packed:len()
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Create the API by using dataView.Types
|
||||
--]]
|
||||
for label,datatype in pairs(dataView.Types) do
|
||||
if not datatype.size then -- cache fixed encoding size
|
||||
datatype.size = string.packsize(datatype.code)
|
||||
elseif datatype.size >= 0 and string.packsize(datatype.code) ~= datatype.size then
|
||||
local msg = "Pack size of %s (%d) does not match cached length: (%d)"
|
||||
error(msg:format(label, string.packsize(datatype.code), datatype.size))
|
||||
return nil
|
||||
end
|
||||
|
||||
dataView["Get" .. label] = function(self, offset, endian)
|
||||
offset = offset or 0
|
||||
if offset >= 0 then
|
||||
local o = self.offset + offset
|
||||
local v,_ = self.blob:blob_unpack(o, ef(endian) .. datatype.code)
|
||||
return v
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
dataView["Set" .. label] = function(self, offset, value, endian)
|
||||
if offset >= 0 and value then
|
||||
local o = self.offset + offset
|
||||
local v_size = (datatype.size < 0 and value:len()) or datatype.size
|
||||
if self.cangrow or ((o + (v_size - 1)) <= self.length) then
|
||||
if not packblob(self, o, value, ef(endian) .. datatype.code) then
|
||||
error("cannot grow subview")
|
||||
end
|
||||
else
|
||||
error("cannot grow dataview")
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
end
|
||||
|
||||
for label,datatype in pairs(dataView.FixedTypes) do
|
||||
datatype.size = -1 -- Ensure cached encoding size is invalidated
|
||||
|
||||
dataView["GetFixed" .. label] = function(self, offset, typelen, endian)
|
||||
if offset >= 0 then
|
||||
local o = self.offset + offset
|
||||
if (o + (typelen - 1)) <= self.length then
|
||||
local code = ef(endian) .. "c" .. tostring(typelen)
|
||||
local v,_ = self.blob:blob_unpack(o, code)
|
||||
return v
|
||||
end
|
||||
end
|
||||
return nil -- Out of bounds
|
||||
end
|
||||
|
||||
dataView["SetFixed" .. label] = function(self, offset, typelen, value, endian)
|
||||
if offset >= 0 and value then
|
||||
local o = self.offset + offset
|
||||
if self.cangrow or ((o + (typelen - 1)) <= self.length) then
|
||||
local code = ef(endian) .. "c" .. tostring(typelen)
|
||||
if not packblob(self, o, value, code) then
|
||||
error("cannot grow subview")
|
||||
end
|
||||
else
|
||||
error("cannot grow dataview")
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
end
|
||||
|
||||
return dataView
|
||||
@@ -1,347 +0,0 @@
|
||||
|
||||
-- CREDITS
|
||||
-- Andyyy7666: https://github.com/overextended/ox_lib/pull/453
|
||||
-- AvarianKnight: https://forum.cfx.re/t/allow-drawgizmo-to-be-used-outside-of-fxdk/5091845/8?u=demi-automatic
|
||||
local dataview = Require("lib/placers/client/dataview.lua")
|
||||
local enableScale = false -- allow scaling mode. doesnt scale collisions and resets when physics are applied it seems
|
||||
local gizmoEnabled = false
|
||||
local currentMode = 'translate'
|
||||
local isRelative = false
|
||||
local currentEntity
|
||||
|
||||
-- FUNCTIONS
|
||||
|
||||
|
||||
local function normalize(x, y, z)
|
||||
local length = math.sqrt(x * x + y * y + z * z)
|
||||
if length == 0 then
|
||||
return 0, 0, 0
|
||||
end
|
||||
return x / length, y / length, z / length
|
||||
end
|
||||
|
||||
local function makeEntityMatrix(entity)
|
||||
local f, r, u, a = GetEntityMatrix(entity)
|
||||
local view = dataview.ArrayBuffer(60)
|
||||
|
||||
view:SetFloat32(0, r[1])
|
||||
:SetFloat32(4, r[2])
|
||||
:SetFloat32(8, r[3])
|
||||
:SetFloat32(12, 0)
|
||||
:SetFloat32(16, f[1])
|
||||
:SetFloat32(20, f[2])
|
||||
:SetFloat32(24, f[3])
|
||||
:SetFloat32(28, 0)
|
||||
:SetFloat32(32, u[1])
|
||||
:SetFloat32(36, u[2])
|
||||
:SetFloat32(40, u[3])
|
||||
:SetFloat32(44, 0)
|
||||
:SetFloat32(48, a[1])
|
||||
:SetFloat32(52, a[2])
|
||||
:SetFloat32(56, a[3])
|
||||
:SetFloat32(60, 1)
|
||||
|
||||
return view
|
||||
end
|
||||
|
||||
local function applyEntityMatrix(entity, view)
|
||||
local x1, y1, z1 = view:GetFloat32(16), view:GetFloat32(20), view:GetFloat32(24)
|
||||
local x2, y2, z2 = view:GetFloat32(0), view:GetFloat32(4), view:GetFloat32(8)
|
||||
local x3, y3, z3 = view:GetFloat32(32), view:GetFloat32(36), view:GetFloat32(40)
|
||||
local tx, ty, tz = view:GetFloat32(48), view:GetFloat32(52), view:GetFloat32(56)
|
||||
|
||||
if not enableScale then
|
||||
x1, y1, z1 = normalize(x1, y1, z1)
|
||||
x2, y2, z2 = normalize(x2, y2, z2)
|
||||
x3, y3, z3 = normalize(x3, y3, z3)
|
||||
end
|
||||
|
||||
SetEntityMatrix(entity,
|
||||
x1, y1, z1,
|
||||
x2, y2, z2,
|
||||
x3, y3, z3,
|
||||
tx, ty, tz
|
||||
)
|
||||
end
|
||||
|
||||
function InBoundary(pos, boundary)
|
||||
if not boundary then return false end
|
||||
local x, y, z = table.unpack(pos)
|
||||
local minX, minY, minZ = table.unpack(boundary.min)
|
||||
local maxX, maxY, maxZ = table.unpack(boundary.max)
|
||||
return x >= minX and x <= maxX and y >= minY and y <= maxY and z >= minZ and z <= maxZ
|
||||
end
|
||||
|
||||
-- LOOPS
|
||||
|
||||
function RegisterButtonHandler(button, onPressed, onReleased)
|
||||
onPressed = onPressed and type(onPressed) == 'function' and onPressed
|
||||
onReleased = onReleased and type(onReleased) == 'function' and onReleased
|
||||
DisableControlAction(0, button, true)
|
||||
local pressed = IsDisabledControlJustPressed(0, button)
|
||||
local released = IsDisabledControlJustReleased(0, button)
|
||||
return (pressed and onPressed and onPressed()) or (released and onReleased and onReleased())
|
||||
end
|
||||
|
||||
|
||||
local function gizmoLoop(entity, onConfirm, onUpdate, onCancel, settings)
|
||||
assert(entity, 'entity is required')
|
||||
entity = tonumber(entity)
|
||||
EnterCursorMode()
|
||||
settings = settings or {}
|
||||
local allowedMats = settings.allowedMats
|
||||
local maxDepth = settings.maxDepth or 10
|
||||
local outLine = false
|
||||
|
||||
if IsEntityAPed(entity) then
|
||||
SetEntityAlpha(entity, 200)
|
||||
end
|
||||
|
||||
if allowedMats or boundary then
|
||||
CreateThread(function()
|
||||
while gizmoEnabled do
|
||||
local coords = GetEntityCoords(entity)
|
||||
local destination = coords - vector3(0, 0, maxDepth)
|
||||
local hit, _, _, _, materialHash = Raycast.ToCoords(coords, destination, 1, 4)
|
||||
if hit and hit ~=1 and (allowedMats?[materialHash] or InBoundary(GetEntityCoords(entity), boundary)) then
|
||||
if not inBounds then
|
||||
inBounds = true
|
||||
SetEntityDrawOutlineColor(0, 255, 0, 255)
|
||||
SetEntityDrawOutline(entity, true)
|
||||
end
|
||||
elseif inBounds then
|
||||
inBounds = false
|
||||
SetEntityDrawOutline(entity, false)
|
||||
end
|
||||
Wait(500)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
while gizmoEnabled and DoesEntityExist(entity) do
|
||||
Wait(0)
|
||||
|
||||
DisableControlAction(0, 24, true) -- lmb
|
||||
DisableControlAction(0, 25, true) -- rmb
|
||||
DisableControlAction(0, 140, true) -- r
|
||||
DisableControlAction(0, 245, true) --t
|
||||
DisablePlayerFiring(PlayerId(), true)
|
||||
SetEntityCollision(entity, false, false)
|
||||
FreezeEntityPosition(entity, false)
|
||||
local matrixBuffer = makeEntityMatrix(entity)
|
||||
local changed = Citizen.InvokeNative(0xEB2EDCA2, matrixBuffer:Buffer(), 'Editor1', Citizen.ReturnResultAnyway())
|
||||
if changed then
|
||||
applyEntityMatrix(entity, matrixBuffer)
|
||||
local coords = GetEntityCoords(entity)
|
||||
SetEntityCoords(entity, coords.x, coords.y, coords.z, false, false, false, false)
|
||||
end
|
||||
|
||||
if onUpdate and type(onUpdate) == 'function' then onUpdate(entity, GetEntityCoords(entity), GetEntityRotation(entity)) end
|
||||
--controles
|
||||
--frontend confirm 18 [ENTER]
|
||||
RegisterButtonHandler(191, function()
|
||||
if not gizmoEnabled then return end
|
||||
gizmoEnabled = false
|
||||
if onConfirm and type(onConfirm) == 'function' then onConfirm(entity, GetEntityCoords(entity), GetEntityRotation(entity)) end
|
||||
end)
|
||||
--frontend cancel 202 [BACKSPACE]
|
||||
RegisterButtonHandler(202, function()
|
||||
if not gizmoEnabled then return end
|
||||
gizmoEnabled = false
|
||||
if onCancel and type(onCancel) == 'function' then onCancel(entity, GetEntityCoords(entity), GetEntityRotation(entity)) end
|
||||
CreateThread(function()
|
||||
local timeout = 100
|
||||
while timeout > 0 do
|
||||
DisableFrontendThisFrame()
|
||||
timeout = timeout - 1
|
||||
Wait(1)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
--register e
|
||||
RegisterButtonHandler(38, function()
|
||||
if not gizmoEnabled then return end
|
||||
gizmoEnabled = false
|
||||
local playerPos = GetEntityCoords(PlayerPedId())
|
||||
local entityPos = GetFinalRenderedCamCoord()
|
||||
local depth = #(playerPos - entityPos) -- Vector3 distance
|
||||
settings.depth = depth
|
||||
PlaceableObject.Create({spawned = entity}, nil, onConfirm, onUpdate, onCancel, settings)
|
||||
end)
|
||||
|
||||
--ctrl
|
||||
RegisterButtonHandler(36, function()
|
||||
if not gizmoEnabled then return end
|
||||
LeaveCursorMode()
|
||||
end, function()
|
||||
EnterCursorMode()
|
||||
end)
|
||||
|
||||
RegisterButtonHandler(19, function()
|
||||
if not gizmoEnabled then return end
|
||||
PlaceObjectOnGroundProperly_2(currentEntity)
|
||||
end)
|
||||
FreezeEntityPosition(entity, false)
|
||||
end
|
||||
|
||||
LeaveCursorMode()
|
||||
|
||||
if DoesEntityExist(entity) then
|
||||
if IsEntityAPed(entity) then SetEntityAlpha(entity, 255) end
|
||||
SetEntityDrawOutline(entity, false)
|
||||
end
|
||||
|
||||
gizmoEnabled = false
|
||||
currentEntity = nil
|
||||
return true
|
||||
end
|
||||
|
||||
--===================================================
|
||||
-- █▀ █ █ ▄▀▀ █▄▀ ▀▄▀ ▄▀▄ █ █ █▄ █ ██▀ █ █ ██▄
|
||||
-- █▀ ▀▄█ ▀▄▄ █ █ █ ▀▄▀ ▀▄█ █ ▀█ █▄▄ ▀▄▀▄▀ █▄█
|
||||
--===================================================
|
||||
-- .--------.
|
||||
-- | taktak |
|
||||
-- |/-------'
|
||||
-- .-. ,-.
|
||||
-- ;oo oo;
|
||||
-- / \| |/ \
|
||||
-- |. `. .' .|
|
||||
-- `;.;' `;.;'
|
||||
-- .-^-. .-^-. ko1
|
||||
|
||||
-- local function textUILoop()
|
||||
-- CreateThread(function()
|
||||
-- while gizmoEnabled do
|
||||
-- Wait(100)
|
||||
-- local scaleText = (enableScale and '[S] - Scale Mode \n') or ''
|
||||
-- lib.showTextUI(
|
||||
-- ('Current Mode: %s | %s \n'):format(currentMode, (isRelative and 'Relative') or 'World') ..
|
||||
-- '[W] - Translate Mode \n' ..
|
||||
-- '[R] - Rotate Mode \n' ..
|
||||
-- scaleText ..
|
||||
-- '[Q] - Relative/World \n' ..
|
||||
-- '[LALT] - Snap To Ground \n' ..
|
||||
-- '[ENTER] - Done Editing \n'
|
||||
-- )
|
||||
-- end
|
||||
-- lib.hideTextUI()
|
||||
-- end)
|
||||
-- end
|
||||
|
||||
-- EXPORTS
|
||||
|
||||
|
||||
local function useGizmo(entity, onConfirm, onUpdate, onCancel, settings)
|
||||
gizmoEnabled = true
|
||||
currentEntity = entity
|
||||
-- textUILoop()
|
||||
gizmoLoop(entity, onConfirm, onUpdate, onCancel, settings)
|
||||
|
||||
return {
|
||||
handle = entity,
|
||||
position = GetEntityCoords(entity),
|
||||
rotation = GetEntityRotation(entity)
|
||||
}
|
||||
end
|
||||
|
||||
exports("useGizmo", useGizmo)
|
||||
|
||||
Gizmo = {}
|
||||
local running = false
|
||||
function Gizmo.UseGizmo(obj, onConfirm, onUpdate, onCancel, settings)
|
||||
if running then return end
|
||||
running = true
|
||||
|
||||
--instructional buttons
|
||||
local scaleform = Scaleform.SetupInstructionalButtons({
|
||||
{type = "CLEAR_ALL"},
|
||||
{type = "SET_CLEAR_SPACE", int = 200},
|
||||
{type = "SET_DATA_SLOT", name = 'Translate:', keyIndex = {245}, int = 1},
|
||||
{type = "SET_DATA_SLOT", name = 'Scale:', keyIndex = {33}, int = 2},
|
||||
{type = "SET_DATA_SLOT", name = 'Rotate:', keyIndex = {45}, int = 3},
|
||||
{type = "SET_DATA_SLOT", name = 'Snap to Ground:', keyIndex = {19}, int = 4},
|
||||
{type = "SET_DATA_SLOT", name = 'Toggle Camera:', keyIndex = {36}, int = 5},
|
||||
{type = "SET_DATA_SLOT", name = 'Cancel Placement:', keyIndex = {202}, int = 6},
|
||||
{type = "SET_DATA_SLOT", name = 'Toggle Gizmo:', keyIndex = {38}, int = 7},
|
||||
{type = "DRAW_INSTRUCTIONAL_BUTTONS"},
|
||||
{type = "SET_BACKGROUND_COLOUR"},
|
||||
})
|
||||
local quit = false
|
||||
CreateThread(function()
|
||||
while not quit do
|
||||
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
|
||||
Wait(0)
|
||||
end
|
||||
running = false
|
||||
end)
|
||||
|
||||
quit = useGizmo(obj, onConfirm, onUpdate, onCancel, settings)
|
||||
running = false
|
||||
end
|
||||
exports("UseGizmo", Gizmo.UseGizmo)
|
||||
|
||||
|
||||
--got rid of the cancer
|
||||
-- lib.addKeybind({
|
||||
-- name = '_gizmoLocal',
|
||||
-- description = 'toggle gizmo to be local to the entity instead of world',
|
||||
-- defaultKey = 'Q',
|
||||
-- onPressed = function(self)
|
||||
-- if not gizmoEnabled then return end
|
||||
-- isRelative = not isRelative
|
||||
-- ExecuteCommand('+gizmoLocal')
|
||||
-- end,
|
||||
-- onReleased = function (self)
|
||||
-- ExecuteCommand('-gizmoLocal')
|
||||
-- end
|
||||
-- })
|
||||
|
||||
-- lib.addKeybind({
|
||||
-- name = 'gizmoclose',
|
||||
-- description = 'close gizmo',
|
||||
-- defaultKey = 'RETURN',
|
||||
-- onPressed = function(self)
|
||||
-- if not gizmoEnabled then return end
|
||||
-- gizmoEnabled = false
|
||||
-- end,
|
||||
-- })
|
||||
|
||||
-- lib.addKeybind({
|
||||
-- name = 'gizmoSnapToGround',
|
||||
-- description = 'snap current gizmo object to floor/surface',
|
||||
-- defaultKey = 'LMENU',
|
||||
-- onPressed = function(self)
|
||||
-- if not gizmoEnabled then return end
|
||||
-- PlaceObjectOnGroundProperly_2(currentEntity)
|
||||
-- end,
|
||||
-- })
|
||||
|
||||
-- if enableScale then
|
||||
-- lib.addKeybind({
|
||||
-- name = '_gizmoScale',
|
||||
-- description = 'Sets mode for the gizmo to scale',
|
||||
-- defaultKey = 'S',
|
||||
-- onPressed = function(self)
|
||||
-- if not gizmoEnabled then return end
|
||||
-- currentMode = 'Scale'
|
||||
-- ExecuteCommand('+gizmoScale')
|
||||
-- end,
|
||||
-- onReleased = function (self)
|
||||
-- ExecuteCommand('-gizmoScale')
|
||||
-- end
|
||||
-- })
|
||||
-- end
|
||||
|
||||
|
||||
--onreousrcestop
|
||||
|
||||
AddEventHandler('onResourceStop', function(resource)
|
||||
if resource == GetCurrentResourceName() then
|
||||
if not gizmoEnabled then return end
|
||||
gizmoEnabled = false
|
||||
LeaveCursorMode()
|
||||
end
|
||||
end)
|
||||
|
||||
return Gizmo
|
||||
@@ -1,16 +1,18 @@
|
||||
Scaleform = Scaleform or Require("lib/scaleform/client/scaleform.lua")
|
||||
Utility = Utility or Require("lib/utility/client/utility.lua")
|
||||
Gizmo = Gizmo or Require("lib/placers/client/gizmo.lua")
|
||||
Raycast = Raycast or Require("lib/raycast/client/raycast.lua")
|
||||
Language = Language or Require("modules/locales/shared.lua")
|
||||
|
||||
PlaceableObject = PlaceableObject or {}
|
||||
|
||||
local data = {
|
||||
entity = nil,
|
||||
placing = false,
|
||||
}
|
||||
-- Local variables
|
||||
local isPlacing = false
|
||||
local currentEntity = nil
|
||||
local currentMode = 'normal' -- 'normal' or 'movement'
|
||||
local currentPromise = nil -- Store the current promise
|
||||
|
||||
function PlaceableObject.Eyetrace(depth, disableSphere)
|
||||
-- Utility functions
|
||||
local function eyetrace(depth, disableSphere)
|
||||
local screenX = GetDisabledControlNormal(0, 239)
|
||||
local screenY = GetDisabledControlNormal(0, 240)
|
||||
|
||||
@@ -23,171 +25,555 @@ function PlaceableObject.Eyetrace(depth, disableSphere)
|
||||
return target
|
||||
end
|
||||
|
||||
function PlaceableObject.InBoundary(pos, boundary)
|
||||
if not boundary then return false end
|
||||
local function inBoundary(pos, boundary)
|
||||
if not boundary then return true end
|
||||
local x, y, z = table.unpack(pos)
|
||||
local minX, minY, minZ = table.unpack(boundary.min)
|
||||
local maxX, maxY, maxZ = table.unpack(boundary.max)
|
||||
return x >= minX and x <= maxX and y >= minY and y <= maxY and z >= minZ and z <= maxZ
|
||||
end
|
||||
-- Creates a placeable object in the game world.
|
||||
-- @param model (string) The model of the object to create.
|
||||
-- @param onConfirm (function) [optional] The callback function to execute when the object is confirmed.
|
||||
-- @param onUpdate (function) [optional] The callback function to execute when the object is moved.
|
||||
-- @param onCancel (function) [optional] The callback function to execute when the object is canceled.
|
||||
-- @param settings (table) [optional] Additional settings for the placeable object.
|
||||
-- - depthMin (number) The minimum depth for the object placement. Default is 2.0.
|
||||
-- - depthMax (number) The maximum depth for the object placement. Default is 10.0.
|
||||
-- - rotationStep (number) The rotation step for the object. Default is 15.0.
|
||||
-- - depthStep (number) The depth step for the object. Default is 1.0.
|
||||
function PlaceableObject.Create(data, model, onConfirm, onUpdate, onCancel, settings)
|
||||
local settings = settings or {}
|
||||
local depthMin = settings.depthMin or 2.0
|
||||
depthMax = settings.depthMax or 10.0
|
||||
rotationStep = settings.rotationStep or 15.0
|
||||
depthStep = settings.depthStep or 1.0
|
||||
disableSphere = settings.useSphere and false or true
|
||||
local depth = settings.depth or 10.0
|
||||
data.placing = true
|
||||
data.paused = false
|
||||
local initialPos = nil
|
||||
local placeOnGround = true
|
||||
local allowedMats = settings.allowedMats
|
||||
local boundary = settings.boundary
|
||||
local config = settings.config or {}
|
||||
|
||||
--scaleform
|
||||
local scaleform = Scaleform.SetupInstructionalButtons({
|
||||
{type = "CLEAR_ALL"},
|
||||
{type = "SET_CLEAR_SPACE", int = 200},
|
||||
{type = "SET_DATA_SLOT", name = config?.place_object?.name or 'Place Object:', keyIndex = config?.place_object?.key or {223}, int = 5},
|
||||
{type = "SET_DATA_SLOT", name = config?.cancel_placement?.name or 'Cancel Placement:', keyIndex = config?.cancel_placement?.key or {222}, int = 4},
|
||||
{type = "SET_DATA_SLOT", name = config?.snap_to_ground?.name or 'Snap to Ground:', keyIndex = config?.snap_to_ground?.key or {19}, int = 1},
|
||||
{type = "SET_DATA_SLOT", name = config?.rotate?.name or 'Rotate:', keyIndex = config?.rotate?.key or {14, 15}, int = 2},
|
||||
{type = "SET_DATA_SLOT", name = config?.distance?.name or 'Distance:', keyIndex = config?.distance?.key or {14,15,36}, int = 3},
|
||||
{type = "SET_DATA_SLOT", name = config?.toggle_placement?.name or 'Toggle Placement:', keyIndex = config?.toggle_placement?.key or {199}, int = 0},
|
||||
{type = "SET_DATA_SLOT", name = config?.gizmo?.name or 'Toggle Gizmo:', keyIndex = config?.gizmo?.key or {38}, int = 6},
|
||||
{type = "DRAW_INSTRUCTIONAL_BUTTONS"},
|
||||
{type = "SET_BACKGROUND_COLOUR"},
|
||||
})
|
||||
local heading = -GetEntityHeading(PlayerPedId())
|
||||
|
||||
local pos = PlaceableObject.Eyetrace(depth, disableSphere)
|
||||
if not data.spawned and model then
|
||||
--get player heading
|
||||
local obj = Utility.CreateProp(model, pos, vector3(0, 0, heading), nil)
|
||||
data.spawned = obj
|
||||
end
|
||||
assert(data.spawned, "Failed to create object")
|
||||
SetEntityCollision(data.spawned, false, false)
|
||||
SetEntityAlpha(data.spawned, 150, false)
|
||||
|
||||
SetPedConfigFlag(PlayerPedId(), 146, true)
|
||||
SetCanClimbOnEntity(data.spawned, false)
|
||||
SetEntityCompletelyDisableCollision(data.spawned, true, false)
|
||||
SetEntityNoCollisionEntity(PlayerPedId(), data.spawned, false)
|
||||
local function checkBoundaryAndMaterials(entity, settings)
|
||||
local inBounds = true
|
||||
if allowedMats or boundary then
|
||||
if settings.allowedMats or settings.boundary then
|
||||
CreateThread(function()
|
||||
while data.placing do
|
||||
local hit, _, coords, _, materialHash = Raycast.FromCamera(1, 4)
|
||||
if hit and hit ~=1 and (allowedMats?[materialHash] or PlaceableObject.InBoundary(GetEntityCoords(data.spawned), boundary)) then
|
||||
while isPlacing do
|
||||
local hit, _, coords, _, materialHash
|
||||
|
||||
if currentMode == 'movement' then
|
||||
local entityCoords = GetEntityCoords(entity)
|
||||
local destination = entityCoords - vector3(0, 0, settings.maxDepth or 10)
|
||||
hit, _, coords, _, materialHash = Raycast.ToCoords(entityCoords, destination, 1, 4)
|
||||
else
|
||||
hit, _, coords, _, materialHash = Raycast.FromCamera(1, 4)
|
||||
end
|
||||
|
||||
local validMaterial = not settings.allowedMats or settings.allowedMats[materialHash]
|
||||
local validBoundary = inBoundary(GetEntityCoords(entity), settings.boundary)
|
||||
|
||||
if hit and hit ~= 1 and validMaterial and validBoundary then
|
||||
if not inBounds then
|
||||
inBounds = true
|
||||
SetEntityDrawOutlineColor(0, 255, 0, 255)
|
||||
SetEntityDrawOutline(data.spawned, true)
|
||||
SetEntityDrawOutline(entity, true)
|
||||
end
|
||||
elseif inBounds then
|
||||
inBounds = false
|
||||
SetEntityDrawOutline(data.spawned, false)
|
||||
SetEntityDrawOutline(entity, false)
|
||||
end
|
||||
Wait(500)
|
||||
end
|
||||
SetEntityDrawOutline(entity, false)
|
||||
end)
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
while data.placing do
|
||||
if data.paused then goto continue end
|
||||
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
|
||||
DisableControlAction(0, 24, true) -- Attack
|
||||
DisableControlAction(0, 25, true) -- Aim
|
||||
DisableControlAction(0, 36, true) -- INPUT_DUCK.
|
||||
|
||||
if IsDisabledControlJustPressed(0, 223) then -- left click
|
||||
if not inBounds then
|
||||
Notify.SendNotify("You can't place this object here", "error", 5000)
|
||||
elseif onConfirm then
|
||||
onConfirm(data.spawned, pos, heading)
|
||||
data.placing = false
|
||||
end
|
||||
end
|
||||
|
||||
if IsDisabledControlJustPressed(0, 25) then -- right click
|
||||
data.placing = false
|
||||
if onCancel then
|
||||
onCancel(data.spawned, pos, heading)
|
||||
else
|
||||
DeleteEntity(data.spawned)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if IsControlJustPressed(0,19) then
|
||||
placeOnGround = not placeOnGround
|
||||
end
|
||||
|
||||
if IsControlJustPressed(0, 38) then -- TAB key to switch to gizmo
|
||||
data.placing = false
|
||||
return Gizmo.UseGizmo(data.spawned, onConfirm, onUpdate, onCancel, settings)
|
||||
end
|
||||
|
||||
if IsControlPressed(0,224) then -- left ctrl
|
||||
if IsControlJustPressed(0, 261) then -- scroll up
|
||||
depth = depth + depthStep
|
||||
if depth > depthMax then
|
||||
depth = depthMax
|
||||
end
|
||||
end
|
||||
|
||||
if IsControlJustPressed(0, 262) then -- scroll down
|
||||
depth = depth - depthStep
|
||||
if depth < depthMin then
|
||||
depth = depthMin
|
||||
end
|
||||
end
|
||||
else
|
||||
if IsControlJustPressed(0, 261) then -- scroll up
|
||||
heading = heading + rotationStep
|
||||
if heading > 360 then
|
||||
heading = 0
|
||||
end
|
||||
end
|
||||
if IsControlJustPressed(0, 262) then -- scroll down
|
||||
heading = heading - rotationStep
|
||||
if heading < 0 then
|
||||
heading = 360
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
pos = PlaceableObject.Eyetrace(depth, disableSphere)
|
||||
if data.spawned then
|
||||
SetEntityCoords(data.spawned, pos.x, pos.y, pos.z)
|
||||
SetEntityHeading(data.spawned, heading)
|
||||
if placeOnGround then
|
||||
PlaceObjectOnGroundProperly(data.spawned)
|
||||
pos = GetEntityCoords(data.spawned)
|
||||
end
|
||||
end
|
||||
if onUpdate and type(onUpdate) == 'function' then onUpdate(data.spawned, pos, heading) end
|
||||
::continue::
|
||||
if IsControlJustPressed(0, 199) then -- home
|
||||
data.paused = not data.paused
|
||||
end
|
||||
Wait(1)
|
||||
end
|
||||
end)
|
||||
return function() return inBounds end
|
||||
end
|
||||
|
||||
local function setupInstructionalButtons(settings)
|
||||
local buttons = {
|
||||
{type = "CLEAR_ALL"},
|
||||
{type = "SET_CLEAR_SPACE", int = 200},
|
||||
}
|
||||
|
||||
-- Common buttons
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.place_object?.name or 'Place Object:', keyIndex = settings.config?.place_object?.key or {223}, int = 5})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.cancel_placement?.name or 'Cancel Placement:', keyIndex = settings.config?.cancel_placement?.key or {222}, int = 4})
|
||||
|
||||
if currentMode == 'normal' then
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.snap_to_ground?.name or 'Snap to Ground:', keyIndex = settings.config?.snap_to_ground?.key or {19}, int = 1})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.rotate?.name or 'Rotate:', keyIndex = settings.config?.rotate?.key or {14, 15}, int = 2})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.distance?.name or 'Distance:', keyIndex = settings.config?.distance?.key or {14,15,36}, int = 3})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.toggle_placement?.name or 'Toggle Placement:', keyIndex = settings.config?.toggle_placement?.key or {199}, int = 0})
|
||||
|
||||
-- Add vertical controls if allowed
|
||||
if settings.allowVertical then
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Up/Down:', keyIndex = {85, 48}, int = 8})
|
||||
end
|
||||
|
||||
if settings.allowMovement then
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.movement?.name or 'Toggle Movement Mode:', keyIndex = settings.config?.movement?.key or {38}, int = 6})
|
||||
end
|
||||
elseif currentMode == 'movement' then
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Forward/Back:', keyIndex = {32, 33}, int = 1})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Left/Right:', keyIndex = {34, 35}, int = 2})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Up/Down:', keyIndex = {85, 48}, int = 3})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Rotate Left/Right:', keyIndex = {174, 175}, int = 4})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Snap to Ground:', keyIndex = {19}, int = 5})
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Confirm (Enter):', keyIndex = {191}, int = 6})
|
||||
|
||||
if settings.allowNormal then
|
||||
table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Normal Mode:', keyIndex = {38}, int = 7})
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(buttons, {type = "DRAW_INSTRUCTIONAL_BUTTONS"})
|
||||
table.insert(buttons, {type = "SET_BACKGROUND_COLOUR"})
|
||||
|
||||
return Scaleform.SetupInstructionalButtons(buttons)
|
||||
end
|
||||
|
||||
local function normalPlacementLoop(entity, settings, getBoundsStatus)
|
||||
-- Initialize or retrieve from settings to maintain state
|
||||
settings.currentDepth = settings.currentDepth or settings.depth or 10.0
|
||||
settings.currentHeading = settings.currentHeading or -GetEntityHeading(PlayerPedId())
|
||||
settings.currentHeight = settings.currentHeight or 0.0 -- Add height tracking
|
||||
settings.placeOnGround = settings.placeOnGround ~= nil and settings.placeOnGround or not settings.allowVertical -- Default based on allowVertical
|
||||
settings.paused = settings.paused or false
|
||||
|
||||
local depth = settings.currentDepth
|
||||
local heading = settings.currentHeading
|
||||
local height = settings.currentHeight
|
||||
local placeOnGround = settings.placeOnGround
|
||||
local paused = settings.paused
|
||||
local pos
|
||||
|
||||
-- Don't use while loop here, just process one frame
|
||||
if not isPlacing or currentMode ~= 'normal' then
|
||||
return
|
||||
end
|
||||
|
||||
if paused then
|
||||
if IsControlJustPressed(0, 199) then -- home
|
||||
paused = not paused
|
||||
settings.paused = paused
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Disable controls
|
||||
DisableControlAction(0, 24, true) -- Attack
|
||||
DisableControlAction(0, 25, true) -- Aim
|
||||
DisableControlAction(0, 36, true) -- INPUT_DUCK
|
||||
|
||||
-- Place object (left click)
|
||||
if IsDisabledControlJustPressed(0, 223) then
|
||||
if not getBoundsStatus() then
|
||||
print(Language.Locale("placeable_object.cant_place_here"))
|
||||
else
|
||||
pos = GetEntityCoords(entity)
|
||||
isPlacing = false
|
||||
if currentPromise then
|
||||
currentPromise:resolve({
|
||||
entity = entity,
|
||||
position = pos,
|
||||
heading = heading
|
||||
})
|
||||
currentPromise = nil
|
||||
end
|
||||
DeleteEntity(entity)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Cancel (right click)
|
||||
if IsDisabledControlJustPressed(0, 25) then
|
||||
isPlacing = false
|
||||
if currentPromise then
|
||||
currentPromise:resolve(nil) -- Return nil for cancel
|
||||
currentPromise = nil
|
||||
end
|
||||
DeleteEntity(entity)
|
||||
return
|
||||
end
|
||||
|
||||
-- Toggle snap to ground (Alt)
|
||||
if IsControlJustPressed(0, 19) then
|
||||
if settings.allowVertical then
|
||||
placeOnGround = not placeOnGround
|
||||
settings.placeOnGround = placeOnGround
|
||||
if placeOnGround then
|
||||
height = 0.0 -- Reset height when snapping to ground
|
||||
settings.currentHeight = height
|
||||
end
|
||||
else
|
||||
-- Force snap to ground if vertical movement not allowed
|
||||
PlaceObjectOnGroundProperly(entity)
|
||||
end
|
||||
end
|
||||
|
||||
-- Switch to movement mode
|
||||
if settings.allowMovement and IsControlJustPressed(0, 38) then
|
||||
currentMode = 'movement'
|
||||
return
|
||||
end
|
||||
|
||||
-- Vertical controls (only if allowVertical is enabled and not snapped to ground)
|
||||
if settings.allowVertical and not placeOnGround then
|
||||
if IsControlPressed(0, 85) then -- Q - Move up
|
||||
height = height + (settings.heightStep or 0.1)
|
||||
settings.currentHeight = height
|
||||
elseif IsControlPressed(0, 48) then -- Z - Move down
|
||||
height = height - (settings.heightStep or 0.1)
|
||||
settings.currentHeight = height
|
||||
end
|
||||
end
|
||||
|
||||
-- Depth and rotation controls
|
||||
if IsControlPressed(0, 224) then -- left ctrl
|
||||
if IsControlJustPressed(0, 15) then -- D key
|
||||
depth = math.min(depth + settings.depthStep, settings.depthMax)
|
||||
elseif IsControlJustPressed(0, 14) then -- A key
|
||||
depth = math.max(depth - settings.depthStep, settings.depthMin)
|
||||
end
|
||||
else
|
||||
if IsControlJustPressed(0, 15) then -- D key
|
||||
heading = (heading + settings.rotationStep) % 360
|
||||
elseif IsControlJustPressed(0, 14) then -- A key
|
||||
heading = (heading - settings.rotationStep) % 360
|
||||
end
|
||||
end
|
||||
|
||||
-- Update position
|
||||
pos = eyetrace(depth, settings.disableSphere)
|
||||
|
||||
-- Add height offset if not snapping to ground
|
||||
if settings.allowVertical and not placeOnGround then
|
||||
pos = pos + vector3(0, 0, height)
|
||||
end
|
||||
|
||||
if entity then
|
||||
SetEntityCoords(entity, pos.x, pos.y, pos.z)
|
||||
SetEntityHeading(entity, heading)
|
||||
if placeOnGround then
|
||||
PlaceObjectOnGroundProperly(entity)
|
||||
pos = GetEntityCoords(entity)
|
||||
end
|
||||
end
|
||||
|
||||
-- Store updated values back to settings
|
||||
settings.currentDepth = depth
|
||||
settings.currentHeading = heading
|
||||
settings.currentHeight = height
|
||||
settings.placeOnGround = placeOnGround
|
||||
end
|
||||
|
||||
local function movementPlacementLoop(entity, settings, getBoundsStatus)
|
||||
-- Don't use while loop here, just process one frame
|
||||
if not isPlacing or currentMode ~= 'movement' or not DoesEntityExist(entity) then
|
||||
return
|
||||
end
|
||||
|
||||
if IsEntityAPed(entity) then
|
||||
SetEntityAlpha(entity, 200)
|
||||
end
|
||||
|
||||
-- Disable movement controls to prevent player from moving
|
||||
DisableControlAction(0, 30, true) -- Move Left/Right
|
||||
DisableControlAction(0, 31, true) -- Move Forward/Back
|
||||
DisableControlAction(0, 36, true) -- INPUT_DUCK
|
||||
DisableControlAction(0, 21, true) -- Sprint
|
||||
DisableControlAction(0, 22, true) -- Jump
|
||||
|
||||
SetEntityCollision(entity, false, false)
|
||||
FreezeEntityPosition(entity, false)
|
||||
|
||||
-- Get current entity position and rotation
|
||||
local coords = GetEntityCoords(entity)
|
||||
local heading = GetEntityHeading(entity)
|
||||
local moved = false
|
||||
|
||||
-- Movement speed settings
|
||||
local moveSpeed = 0.1
|
||||
local fastMoveSpeed = 0.5
|
||||
local rotateSpeed = 2.0
|
||||
|
||||
-- Check if shift is held for faster movement
|
||||
local isFastMode = IsControlPressed(0, 21) -- Left Shift
|
||||
local currentMoveSpeed = isFastMode and fastMoveSpeed or moveSpeed
|
||||
|
||||
-- Get camera rotation for relative movement
|
||||
local camRot = GetGameplayCamRot(2)
|
||||
local camHeading = math.rad(camRot.z)
|
||||
|
||||
-- Calculate camera-relative directions
|
||||
local camForward = vector3(-math.sin(camHeading), math.cos(camHeading), 0)
|
||||
local camRight = vector3(math.cos(camHeading), math.sin(camHeading), 0)
|
||||
|
||||
-- WASD movement (relative to camera direction)
|
||||
if IsControlPressed(0, 32) then -- W - Move forward relative to camera
|
||||
coords = coords + camForward * currentMoveSpeed
|
||||
moved = true
|
||||
elseif IsControlPressed(0, 33) then -- S - Move backward relative to camera
|
||||
coords = coords - camForward * currentMoveSpeed
|
||||
moved = true
|
||||
end
|
||||
|
||||
if IsControlPressed(0, 34) then -- A - Move left relative to camera
|
||||
coords = coords - camRight * currentMoveSpeed
|
||||
moved = true
|
||||
elseif IsControlPressed(0, 35) then -- D - Move right relative to camera
|
||||
coords = coords + camRight * currentMoveSpeed
|
||||
moved = true
|
||||
end
|
||||
|
||||
-- Up/Down movement (always world-relative)
|
||||
if settings.allowVertical and IsControlPressed(0, 85) then -- Q - Move up
|
||||
coords = coords + vector3(0, 0, currentMoveSpeed)
|
||||
moved = true
|
||||
elseif settings.allowVertical and IsControlPressed(0, 48) then -- Z - Move down
|
||||
coords = coords + vector3(0, 0, -currentMoveSpeed)
|
||||
moved = true
|
||||
end
|
||||
|
||||
-- Rotation controls
|
||||
if IsControlPressed(0, 174) then -- Left Arrow - Rotate left
|
||||
heading = heading - rotateSpeed
|
||||
moved = true
|
||||
elseif IsControlPressed(0, 175) then -- Right Arrow - Rotate right
|
||||
heading = heading + rotateSpeed
|
||||
moved = true
|
||||
end
|
||||
|
||||
-- Alternative rotation with mouse wheel
|
||||
if IsControlJustPressed(0, 241) then -- Mouse wheel up
|
||||
heading = heading + 15.0
|
||||
moved = true
|
||||
elseif IsControlJustPressed(0, 242) then -- Mouse wheel down
|
||||
heading = heading - 15.0
|
||||
moved = true
|
||||
end
|
||||
|
||||
-- Apply movement if any occurred
|
||||
if moved then
|
||||
SetEntityCoords(entity, coords.x, coords.y, coords.z, false, false, false, false)
|
||||
SetEntityHeading(entity, heading)
|
||||
end
|
||||
|
||||
-- Confirm placement (Enter)
|
||||
if IsControlJustPressed(0, 191) then
|
||||
if not getBoundsStatus() then
|
||||
print(Language.Locale("placeable_object.cant_place_here"))
|
||||
return
|
||||
end
|
||||
isPlacing = false
|
||||
if currentPromise then
|
||||
currentPromise:resolve({
|
||||
entity = entity,
|
||||
position = GetEntityCoords(entity),
|
||||
heading = GetEntityHeading(entity),
|
||||
rotation = GetEntityRotation(entity)
|
||||
})
|
||||
currentPromise = nil
|
||||
end
|
||||
DeleteEntity(entity)
|
||||
return
|
||||
end
|
||||
|
||||
-- Cancel placement (Backspace)
|
||||
if IsControlJustPressed(0, 202) then
|
||||
isPlacing = false
|
||||
if currentPromise then
|
||||
currentPromise:resolve(nil) -- Return nil for cancel
|
||||
currentPromise = nil
|
||||
end
|
||||
DeleteEntity(entity)
|
||||
return
|
||||
end
|
||||
|
||||
-- Switch to normal mode (E)
|
||||
if settings.allowNormal and IsControlJustPressed(0, 38) then
|
||||
currentMode = 'normal'
|
||||
local playerPos = GetEntityCoords(PlayerPedId())
|
||||
local entityPos = GetEntityCoords(entity)
|
||||
local depth = #(playerPos - entityPos)
|
||||
settings.currentDepth = depth
|
||||
return
|
||||
end
|
||||
|
||||
-- Snap to ground (Alt)
|
||||
if IsControlJustPressed(0, 19) then
|
||||
PlaceObjectOnGroundProperly(entity)
|
||||
end
|
||||
|
||||
FreezeEntityPosition(entity, false)
|
||||
end
|
||||
|
||||
local function drawBoundaryBox(boundary)
|
||||
if not boundary then return end
|
||||
|
||||
local min = boundary.min
|
||||
local max = boundary.max
|
||||
|
||||
-- Define the 8 corners of the box
|
||||
local corners = {
|
||||
vector3(min.x, min.y, min.z), -- 1: bottom front left
|
||||
vector3(max.x, min.y, min.z), -- 2: bottom front right
|
||||
vector3(max.x, max.y, min.z), -- 3: bottom back right
|
||||
vector3(min.x, max.y, min.z), -- 4: bottom back left
|
||||
vector3(min.x, min.y, max.z), -- 5: top front left
|
||||
vector3(max.x, min.y, max.z), -- 6: top front right
|
||||
vector3(max.x, max.y, max.z), -- 7: top back right
|
||||
vector3(min.x, max.y, max.z), -- 8: top back left
|
||||
}
|
||||
|
||||
-- Draw the box faces as triangles (2 triangles per face)
|
||||
local alpha = 50 -- Semi-transparent
|
||||
local r, g, b = 0, 255, 0 -- Green color
|
||||
|
||||
-- Bottom face (looking up from below)
|
||||
DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[2].x, corners[2].y, corners[2].z, corners[3].x, corners[3].y, corners[3].z, r, g, b, alpha)
|
||||
DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[3].x, corners[3].y, corners[3].z, corners[4].x, corners[4].y, corners[4].z, r, g, b, alpha)
|
||||
|
||||
-- Top face (looking down from above)
|
||||
DrawPoly(corners[5].x, corners[5].y, corners[5].z, corners[7].x, corners[7].y, corners[7].z, corners[6].x, corners[6].y, corners[6].z, r, g, b, alpha)
|
||||
DrawPoly(corners[5].x, corners[5].y, corners[5].z, corners[8].x, corners[8].y, corners[8].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, alpha)
|
||||
|
||||
-- Front face (min Y)
|
||||
DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[5].x, corners[5].y, corners[5].z, corners[6].x, corners[6].y, corners[6].z, r, g, b, alpha)
|
||||
DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[6].x, corners[6].y, corners[6].z, corners[2].x, corners[2].y, corners[2].z, r, g, b, alpha)
|
||||
|
||||
-- Back face (max Y)
|
||||
DrawPoly(corners[4].x, corners[4].y, corners[4].z, corners[7].x, corners[7].y, corners[7].z, corners[8].x, corners[8].y, corners[8].z, r, g, b, alpha)
|
||||
DrawPoly(corners[4].x, corners[4].y, corners[4].z, corners[3].x, corners[3].y, corners[3].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, alpha)
|
||||
|
||||
-- Left face (min X)
|
||||
DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[4].x, corners[4].y, corners[4].z, corners[8].x, corners[8].y, corners[8].z, r, g, b, alpha)
|
||||
DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[8].x, corners[8].y, corners[8].z, corners[5].x, corners[5].y, corners[5].z, r, g, b, alpha)
|
||||
|
||||
-- Right face (max X)
|
||||
DrawPoly(corners[2].x, corners[2].y, corners[2].z, corners[6].x, corners[6].y, corners[6].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, alpha)
|
||||
DrawPoly(corners[2].x, corners[2].y, corners[2].z, corners[7].x, corners[7].y, corners[7].z, corners[3].x, corners[3].y, corners[3].z, r, g, b, alpha)
|
||||
end
|
||||
|
||||
-- Main placement function - now uses proper promise pattern
|
||||
function PlaceableObject.Create(model, settings)
|
||||
if isPlacing then
|
||||
return nil -- Already placing
|
||||
end
|
||||
|
||||
settings = settings or {}
|
||||
|
||||
-- Default settings
|
||||
local config = {
|
||||
depthMin = settings.depthMin or 2.0,
|
||||
depthMax = settings.depthMax or 10.0,
|
||||
rotationStep = settings.rotationStep or 15.0,
|
||||
depthStep = settings.depthStep or 1.0,
|
||||
heightStep = settings.heightStep or 0.1, -- New height step setting
|
||||
disableSphere = settings.useSphere and false or true,
|
||||
depth = settings.depth or 10.0,
|
||||
allowMovement = settings.allowMovement ~= false, -- default true
|
||||
allowNormal = settings.allowNormal ~= false, -- default true
|
||||
allowVertical = settings.allowVertical ~= false, -- default true - allow vertical movement in normal mode
|
||||
startMode = settings.startMode or 'normal', -- 'normal' or 'movement'
|
||||
allowedMats = settings.allowedMats,
|
||||
boundary = settings.boundary,
|
||||
config = settings.config or {},
|
||||
maxDepth = settings.maxDepth or 10,
|
||||
showInstructionalButtons = settings.showInstructionalButtons
|
||||
}
|
||||
|
||||
-- Create the promise and store it globally
|
||||
currentPromise = promise.new()
|
||||
|
||||
isPlacing = true
|
||||
currentMode = config.startMode
|
||||
|
||||
-- Create entity if model provided
|
||||
if model then
|
||||
local heading = -GetEntityHeading(PlayerPedId())
|
||||
local pos = eyetrace(config.depth, config.disableSphere)
|
||||
local obj = Utility.CreateProp(model, pos, vector3(0, 0, heading), nil)
|
||||
currentEntity = obj
|
||||
else
|
||||
currentEntity = settings.entity
|
||||
end
|
||||
|
||||
if not currentEntity then
|
||||
isPlacing = false
|
||||
if currentPromise then
|
||||
currentPromise:resolve(nil)
|
||||
currentPromise = nil
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Setup entity
|
||||
SetEntityCollision(currentEntity, false, false)
|
||||
SetEntityAlpha(currentEntity, 150, false)
|
||||
SetPedConfigFlag(PlayerPedId(), 146, true)
|
||||
SetCanClimbOnEntity(currentEntity, false)
|
||||
SetEntityCompletelyDisableCollision(currentEntity, true, false)
|
||||
SetEntityNoCollisionEntity(PlayerPedId(), currentEntity, false)
|
||||
|
||||
-- Setup boundary checking
|
||||
local getBoundsStatus = checkBoundaryAndMaterials(currentEntity, config)
|
||||
|
||||
-- Setup instructional buttons only if enabled
|
||||
local scaleform = nil
|
||||
if config.showInstructionalButtons then
|
||||
scaleform = setupInstructionalButtons(config)
|
||||
end
|
||||
|
||||
-- Main loop
|
||||
CreateThread(function()
|
||||
local lastMode = currentMode
|
||||
while isPlacing do
|
||||
-- Update instructional buttons if mode changed and buttons are enabled
|
||||
if config.showInstructionalButtons and (not lastMode or lastMode ~= currentMode) then
|
||||
scaleform = setupInstructionalButtons(config)
|
||||
lastMode = currentMode
|
||||
end
|
||||
|
||||
-- Draw instructional buttons only if enabled
|
||||
if config.showInstructionalButtons and scaleform then
|
||||
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
|
||||
end
|
||||
|
||||
-- Draw boundary box if defined
|
||||
if config.boundary then
|
||||
drawBoundaryBox(config.boundary)
|
||||
end
|
||||
|
||||
if currentMode == 'normal' and config.allowNormal then
|
||||
normalPlacementLoop(currentEntity, config, getBoundsStatus)
|
||||
elseif currentMode == 'movement' and config.allowMovement then
|
||||
movementPlacementLoop(currentEntity, config, getBoundsStatus)
|
||||
end
|
||||
|
||||
Wait(0)
|
||||
end
|
||||
|
||||
-- Cleanup
|
||||
if DoesEntityExist(currentEntity) then
|
||||
if IsEntityAPed(currentEntity) then
|
||||
SetEntityAlpha(currentEntity, 255)
|
||||
end
|
||||
SetEntityDrawOutline(currentEntity, false)
|
||||
end
|
||||
|
||||
currentEntity = nil
|
||||
end)
|
||||
|
||||
-- Return Citizen.Await on the promise
|
||||
return Citizen.Await(currentPromise)
|
||||
end
|
||||
|
||||
-- Stop placement function
|
||||
function PlaceableObject.Stop()
|
||||
if not isPlacing then return false end
|
||||
|
||||
isPlacing = false
|
||||
if currentEntity and DoesEntityExist(currentEntity) then
|
||||
DeleteEntity(currentEntity)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- Get current status
|
||||
function PlaceableObject.IsPlacing()
|
||||
return isPlacing
|
||||
end
|
||||
|
||||
function PlaceableObject.GetCurrentEntity()
|
||||
return currentEntity
|
||||
end
|
||||
|
||||
function PlaceableObject.GetCurrentMode()
|
||||
return currentMode
|
||||
end
|
||||
|
||||
|
||||
|
||||
return PlaceableObject
|
||||
@@ -35,7 +35,7 @@ function Raycast.ToCoords(startCoords, endCoords, flag, ignore)
|
||||
timeout = timeout - 1
|
||||
Wait(0)
|
||||
end
|
||||
return retval, entity, finalCoords, normals, material
|
||||
return retval, entity, finalCoords, normals, material
|
||||
end
|
||||
|
||||
function Raycast.FromCamera(flags, ignore, distance)
|
||||
@@ -44,9 +44,8 @@ function Raycast.FromCamera(flags, ignore, distance)
|
||||
local destination = coords + Raycast.GetForwardVector() * distance
|
||||
local retval, entity, finalCoords, normals, material = Raycast.ToCoords(coords, destination, flags, ignore)
|
||||
if retval ~= 1 then
|
||||
print("Raycast hit max distance, trying again", coords, dist)
|
||||
local newDest = destination - vector3(0, 0, 10)
|
||||
return Raycast.ToCoords(destination, newDest, flags, ignore)
|
||||
return Raycast.ToCoords(destination, newDest, flags, ignore)
|
||||
end
|
||||
return retval, entity, finalCoords, normals, material
|
||||
end
|
||||
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "In die Zwischenablage kopiert"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "Sie können dieses Objekt hier nicht platzieren"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Copied to clipboard"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "You can't place this object here"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Copiado al portapapeles"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "No puedes colocar este objeto aquí"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Copié dans le presse-papiers"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "Vous ne pouvez pas placer cet objet ici"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Copiato negli appunti"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "Non puoi posizionare questo oggetto qui"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Gekopieerd naar klembord"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "Je kunt dit object hier niet plaatsen"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Skopiowano do schowka"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "Nie możesz umieścić tego obiektu tutaj"
|
||||
}
|
||||
}
|
||||
@@ -43,5 +43,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Copiado para a área de transferência"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "Não pode colocar este objeto aqui"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Скопировано в буфер обмена"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "Вы не можете разместить этот объект здесь"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "คัดลอกไปยังคลิปบอร์ดแล้ว"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "คุณไม่สามารถวางวัตถุนี้ที่นี่ได้"
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,8 @@
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "已复制到剪贴板"
|
||||
},
|
||||
"placeable_object": {
|
||||
"cant_place_here": "您无法在此处放置此对象"
|
||||
}
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
local colourblind = GetResourceKvpString('colourblind') or "default"
|
||||
local QB = false
|
||||
if (BridgeClientConfig.MenuSystem == "auto" and GetResourceState("qb-menu") ~= "started") or (BridgeClientConfig.MenuSystem ~= "auto" and BridgeClientConfig.MenuSystem == "qb-menu") then
|
||||
QB = true
|
||||
end
|
||||
|
||||
Accessibility = Accessibility or {}
|
||||
|
||||
RegisterCommand(locale("accessibility.cb_command"), function()
|
||||
Accessibility.updatecolourblindness()
|
||||
end, false)
|
||||
|
||||
Accessibility.updatecolourblindness = function()
|
||||
local currentCB = locale("accessibility.cb_"..colourblind.."_title")
|
||||
local cbIcon = "fas fa-eye-low-vision"
|
||||
Menu.Open({
|
||||
id = 'colourblind_update',
|
||||
title = locale("accessibility.cb_title"),
|
||||
options = {
|
||||
{
|
||||
title = locale("accessibility.cb_title"),
|
||||
description = locale("accessibility.cb_desc"):format(currentCB),
|
||||
disabled = true,
|
||||
},
|
||||
{
|
||||
title = locale("accessibility.cb_default_title"),
|
||||
description = locale("accessibility.cb_default_desc"),
|
||||
icon = "fas fa-eye",
|
||||
onSelect = function()
|
||||
colourblind = "default"
|
||||
SetResourceKvp('colourblind', colourblind)
|
||||
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
|
||||
end
|
||||
},
|
||||
{
|
||||
title = locale("accessibility.cb_protanomaly_title"),
|
||||
description = locale("accessibility.cb_protanomaly_desc"),
|
||||
icon = cbIcon,
|
||||
onSelect = function()
|
||||
colourblind = "protanomaly"
|
||||
SetResourceKvp('colourblind', colourblind)
|
||||
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
|
||||
end
|
||||
},
|
||||
{
|
||||
title = locale("accessibility.cb_deuteranomaly_title"),
|
||||
description = locale("accessibility.cb_deuteranomaly_desc"),
|
||||
icon = cbIcon,
|
||||
onSelect = function()
|
||||
colourblind = "deuteranomaly"
|
||||
SetResourceKvp('colourblind', colourblind)
|
||||
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
|
||||
end
|
||||
},
|
||||
{
|
||||
title = locale('accessibility.cb_dual_title'),
|
||||
description = locale("accessibility.cb_dual_desc"),
|
||||
icon = cbIcon,
|
||||
onSelect = function()
|
||||
colourblind = "dual"
|
||||
SetResourceKvp('colourblind', colourblind)
|
||||
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
|
||||
end
|
||||
},
|
||||
{
|
||||
title = locale("accessibility.cb_tritanopia_title"),
|
||||
description = locale("accessibility.cb_tritanopia_desc"),
|
||||
icon = cbIcon,
|
||||
onSelect = function()
|
||||
colourblind = "tritanopia"
|
||||
SetResourceKvp('colourblind', colourblind)
|
||||
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
|
||||
end
|
||||
},
|
||||
{
|
||||
title = locale("accessibility.cb_tritanomaly_title"),
|
||||
description = locale("accessibility.cb_tritanomaly_desc"),
|
||||
icon = cbIcon,
|
||||
onSelect = function()
|
||||
colourblind = "tritanomaly"
|
||||
SetResourceKvp('colourblind', colourblind)
|
||||
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
|
||||
end
|
||||
},
|
||||
}},QB)
|
||||
end
|
||||
Accessibility.hexToRgb = function(hex)
|
||||
hex = hex:gsub("#", "")
|
||||
local r,g,b = tonumber("0x" .. hex:sub(1, 2)),tonumber("0x" .. hex:sub(3, 4)),tonumber("0x" .. hex:sub(5, 6))
|
||||
return r, g, b
|
||||
end
|
||||
|
||||
Accessibility.rgbToHex = function(r, g, b)
|
||||
return string.format("#%02x%02x%02x", r, g, b)
|
||||
end
|
||||
|
||||
Accessibility.rgbToHsl = function(r, g, b)
|
||||
r = r / 255
|
||||
g = g / 255
|
||||
b = b / 255
|
||||
local max = math.max(r, g, b)
|
||||
local min = math.min(r, g, b)
|
||||
local h, s, l = 0, 0, (max + min) / 2
|
||||
|
||||
if max == min then
|
||||
h, s = 0, 0 -- achromatic
|
||||
else
|
||||
local d = max - min
|
||||
s = l > 0.5 and d / (2 - max - min) or d / (max + min)
|
||||
if max == r then
|
||||
h = (g - b) / d + (g < b and 6 or 0)
|
||||
elseif max == g then
|
||||
h = (b - r) / d + 2
|
||||
elseif max == b then
|
||||
h = (r - g) / d + 4
|
||||
end
|
||||
h = h / 6
|
||||
end
|
||||
return h, s, l
|
||||
end
|
||||
|
||||
Accessibility.hslToRgb = function(h, s, l)
|
||||
local r, g, b
|
||||
if s == 0 then
|
||||
r, g, b = l, l, l -- achromatic
|
||||
else
|
||||
local function hue2rgb(p, q, t)
|
||||
if t < 0 then t = t + 1 end
|
||||
if t > 1 then t = t - 1 end
|
||||
if t < 1 / 6 then return p + (q - p) * 6 * t end
|
||||
if t < 1 / 2 then return q end
|
||||
if t < 2 / 3 then return p + (q - p) * (2 / 3 - t) * 6 end
|
||||
return p
|
||||
end
|
||||
|
||||
local q = l < 0.5 and l * (1 + s) or l + s - l * s
|
||||
local p = 2 * l - q
|
||||
r = hue2rgb(p, q, h + 1 / 3)
|
||||
g = hue2rgb(p, q, h)
|
||||
b = hue2rgb(p, q, h - 1 / 3)
|
||||
end
|
||||
return math.floor(r * 255), math.floor(g * 255), math.floor(b * 255)
|
||||
end
|
||||
|
||||
Accessibility.adjustColourForColourblindness = function(num, returnAsRGB)
|
||||
local r, g, b
|
||||
if type(num) ~= "table" and num:match("^#%x%x%x%x%x%x$") then
|
||||
r, g, b = Accessibility.hexToRgb(num) -- Convert hex to RGB
|
||||
else
|
||||
r, g, b = num.r, num.g, num.b -- If it's already RGB, use it directly
|
||||
end
|
||||
local h, s, l = Accessibility.rgbToHsl(r, g, b) -- Convert RGB to HSL
|
||||
-- Adjust hue values based on colourblindness type
|
||||
if colourblind == "protanomaly" then -- Red-blind
|
||||
-- Shift towards blue/cyan
|
||||
h = (h + 0.5) % 1 -- Shift by 180 degrees
|
||||
elseif colourblind == "deuteranomaly" then -- Green-blind
|
||||
-- Shift towards blue/magenta
|
||||
h = (h + 0.33) % 1 -- Shift by 120 degrees
|
||||
elseif colourblind == "dual" then -- Protanopia and Deuteranopia (Red-Green blind)
|
||||
-- More significant shift towards blue/yellow
|
||||
-- This is a more drastic shift to maximize contrast
|
||||
if h < 0.166 then -- Reddish hues
|
||||
h = 0.66 -- Shift to blue
|
||||
elseif h < 0.5 then -- Greenish hues
|
||||
h = 0.166 -- Shift to yellow
|
||||
else
|
||||
h = h -- Leave blue/purple hues alone
|
||||
end
|
||||
-- Increase saturation and lightness to make colours more distinct
|
||||
s = math.min(s * 1.5, 1)
|
||||
l = math.min(l * 1.2, 1)
|
||||
elseif colourblind == "tritanopia" then -- Blue-blind
|
||||
-- Shift towards red/yellow
|
||||
h = (h + 0.16) % 1 -- Shift by 60 degrees
|
||||
elseif colourblind == "tritanomaly" then
|
||||
h = (h + 0.08) % 1
|
||||
end
|
||||
|
||||
-- Convert back to RGB
|
||||
r, g, b = Accessibility.hslToRgb(h, s, l)
|
||||
if returnAsRGB then
|
||||
return {r = r, g = g, b = b}
|
||||
else
|
||||
-- Convert back to HEX
|
||||
local newHex = Accessibility.rgbToHex(r, g, b)
|
||||
return newHex
|
||||
end
|
||||
end
|
||||
|
||||
---@returns a colour adjusted for colourblindness in HEX if variable `returnAsRGB` is false
|
||||
---@param colourName string Colour name in HEX format or RGB format
|
||||
-- This is the trigger function for altering colours for colourblindness :D
|
||||
Accessibility.getAdjustedColour = function(colourName, returnAsRGB)
|
||||
local originalHex = colourName
|
||||
if originalHex then
|
||||
if colourblind == "default" then
|
||||
if type(colourName) == "table" and not returnAsRGB then
|
||||
return Accessibility.rgbToHex(colourName.r, colourName.g, colourName.b)
|
||||
else
|
||||
return originalHex
|
||||
end
|
||||
else
|
||||
return Accessibility.adjustColourForColourblindness(originalHex, returnAsRGB)
|
||||
end
|
||||
else
|
||||
Prints.Error("Invalid Colour Name^0] [^3"..colourName.."^0")
|
||||
return "#FFFFFF" -- Default to white if the colour name is invalid
|
||||
end
|
||||
end
|
||||
|
||||
return Accessibility
|
||||
@@ -11,28 +11,28 @@ ESX = ESX or exports['es_extended']:getSharedObject()
|
||||
--- @return table|nil The player's full appearance data or nil if not found
|
||||
function Clothing.GetFullAppearanceData(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
assert(src, "src is nil")
|
||||
local Player = ESX.GetPlayerFromId(src)
|
||||
if not Player then return end
|
||||
local citId = Player.identifier
|
||||
if not citId then return end
|
||||
|
||||
|
||||
if Clothing.Players[citId] then return Clothing.Players[citId] end
|
||||
|
||||
|
||||
local result = MySQL.query.await('SELECT skin FROM users WHERE identifier = ?', { citId})
|
||||
if result[1] == nil then return end
|
||||
|
||||
|
||||
local model = GetEntityModel(GetPlayerPed(src))
|
||||
local skinData = json.decode(result[1].skin)
|
||||
local converted = Clothing.ConvertToDefault(skinData)
|
||||
|
||||
|
||||
-- Store complete data in the cache
|
||||
Clothing.Players[citId] = {
|
||||
model = model,
|
||||
skin = skinData,
|
||||
converted = converted
|
||||
skin = skinData,
|
||||
converted = converted
|
||||
}
|
||||
|
||||
|
||||
return Clothing.Players[citId]
|
||||
end
|
||||
|
||||
@@ -81,16 +81,16 @@ function Clothing.SetAppearance(src, data, updateBackup, save)
|
||||
local model = GetEntityModel(GetPlayerPed(src))
|
||||
if not model then return end
|
||||
local converted = Clothing.ConvertFromDefault(data)
|
||||
|
||||
|
||||
-- Get full appearance data
|
||||
local currentClothing = Clothing.GetFullAppearanceData(src)
|
||||
if not currentClothing then return end
|
||||
|
||||
|
||||
local currentSkin = currentClothing.skin
|
||||
for k, v in pairs(converted) do
|
||||
currentSkin[k] = v
|
||||
end
|
||||
|
||||
|
||||
|
||||
if not Clothing.Players[citId].backup or updateBackup then
|
||||
Clothing.Players[citId].backup = currentClothing.converted
|
||||
@@ -100,7 +100,7 @@ function Clothing.SetAppearance(src, data, updateBackup, save)
|
||||
Clothing.Players[citId].skin = currentSkin
|
||||
Clothing.Players[citId].model = model
|
||||
Clothing.Players[citId].converted = Clothing.ConvertToDefault(currentSkin)
|
||||
if save then
|
||||
if save then
|
||||
local encodedSkin = json.encode(currentSkin)
|
||||
-- saving 1 sql call by adding the query here instead of calling save
|
||||
MySQL.update.await('UPDATE users SET skin = ? WHERE identifier = ?', {
|
||||
@@ -137,7 +137,7 @@ end
|
||||
|
||||
function Clothing.OpenMenu(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
assert(src, "src is nil")
|
||||
TriggerClientEvent('esx_skin:openMenu', src)
|
||||
end
|
||||
|
||||
|
||||
@@ -11,28 +11,28 @@ QBCore = QBCore or exports['qb-core']:GetCoreObject()
|
||||
--- @return table|nil The player's full appearance data or nil if not found
|
||||
function Clothing.GetFullAppearanceData(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
assert(src, "src is nil")
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if not Player then return end
|
||||
local citId = Player.PlayerData.citizenid
|
||||
if not citId then return end
|
||||
|
||||
|
||||
if Clothing.Players[citId] then return Clothing.Players[citId] end
|
||||
|
||||
|
||||
local result = MySQL.query.await('SELECT * FROM playerskins WHERE citizenid = ? AND active = ?', { citId, 1 })
|
||||
if result[1] == nil then return end
|
||||
|
||||
|
||||
local model = Player.PlayerData.model
|
||||
local skinData = json.decode(result[1].skin)
|
||||
local converted = Clothing.ConvertToDefault(skinData)
|
||||
|
||||
|
||||
-- Store complete data in the cache
|
||||
Clothing.Players[citId] = {
|
||||
model = model,
|
||||
skin = skinData,
|
||||
converted = converted
|
||||
Clothing.Players[citId] = {
|
||||
model = model,
|
||||
skin = skinData,
|
||||
converted = converted
|
||||
}
|
||||
|
||||
|
||||
return Clothing.Players[citId]
|
||||
end
|
||||
|
||||
@@ -64,16 +64,16 @@ function Clothing.SetAppearance(src, data, updateBackup, save)
|
||||
local model = GetEntityModel(GetPlayerPed(src))
|
||||
if not model then return end
|
||||
local converted = Clothing.ConvertFromDefault(data)
|
||||
|
||||
|
||||
-- Get full appearance data
|
||||
local currentClothing = Clothing.GetFullAppearanceData(src)
|
||||
if not currentClothing then return end
|
||||
|
||||
|
||||
local currentSkin = currentClothing.skin
|
||||
for k, v in pairs(converted) do
|
||||
currentSkin[k] = v
|
||||
end
|
||||
|
||||
|
||||
if not Clothing.Players[citId].backup or updateBackup then
|
||||
Clothing.Players[citId].backup = currentClothing.converted
|
||||
end
|
||||
@@ -118,7 +118,7 @@ end
|
||||
|
||||
function Clothing.OpenMenu(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
assert(src, "src is nil")
|
||||
TriggerClientEvent('qb-clothing:client:openMenu', src)
|
||||
end
|
||||
|
||||
@@ -131,7 +131,7 @@ AddEventHandler('community_bridge:Server:OnPlayerLoaded', function(src)
|
||||
if not Player then return end
|
||||
local citId = Player.PlayerData.citizenid
|
||||
if not citId then return end
|
||||
|
||||
|
||||
-- Use GetFullAppearanceData to cache the complete appearance
|
||||
Clothing.GetFullAppearanceData(src)
|
||||
end)
|
||||
@@ -208,6 +208,32 @@ RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
|
||||
end, false)
|
||||
|
||||
|
||||
RegisterCommand('clothing:crowley', function(source, args, rawCommand)
|
||||
local src = source
|
||||
end, false)
|
||||
-- RegisterCommand('clothing:crowley', function(source, args, rawCommand)
|
||||
-- local src = source
|
||||
-- Clothing.SetAppearance(src, {
|
||||
-- components = {
|
||||
-- {drawable = 0, texture = 0, component_id = 0},
|
||||
-- {drawable = 0, texture = 0, component_id = 1},
|
||||
-- {drawable = 19, texture = 0, component_id = 2},
|
||||
-- {drawable = 6, texture = 0, component_id = 3},
|
||||
-- {drawable = 0, texture = 0, component_id = 4},
|
||||
-- {drawable = 0, texture = 0, component_id = 5},
|
||||
-- {drawable = 0, texture = 0, component_id = 6},
|
||||
-- {drawable = 0, texture = 0, component_id = 7},
|
||||
-- {drawable = 23, texture = 0, component_id = 8},
|
||||
-- {drawable = 0, texture = 0, component_id = 9},
|
||||
-- {drawable = 0, texture = 0, component_id = 10},
|
||||
-- {drawable = 4, texture = 2, component_id = 11}
|
||||
-- },
|
||||
-- props = {
|
||||
-- {drawable = 27, prop_id = 0, texture = 0},
|
||||
-- {drawable = 0, prop_id = 1, texture = 0},
|
||||
-- {drawable = 0, prop_id = 2, texture = 0},
|
||||
-- {drawable = 0, prop_id = 3, texture = 0},
|
||||
-- {drawable = 0, prop_id = 4, texture = 0},
|
||||
-- {drawable = 0, prop_id = 5, texture = 0},
|
||||
-- -- {drawable = 0, prop_id = 6, texture = 0},
|
||||
-- -- {drawable = 0, prop_id = 7, texture = 0},
|
||||
-- }
|
||||
-- }, false, true)
|
||||
-- end, false)
|
||||
@@ -58,7 +58,7 @@ Target.AddGlobalVehicle = function(options)
|
||||
ox_target:addGlobalVehicle(options)
|
||||
end
|
||||
|
||||
---This will remove target options from all vehicles.
|
||||
---This will remove target options from all vehicles.
|
||||
---@param options table
|
||||
Target.RemoveGlobalVehicle = function(options)
|
||||
local assembledLables = {}
|
||||
@@ -96,6 +96,18 @@ Target.RemoveModel = function(model)
|
||||
ox_target:removeModel(model)
|
||||
end
|
||||
|
||||
-- Target.DisableTargeting = function(bool)
|
||||
-- ox_target:disableTargeting(bool)
|
||||
-- end
|
||||
|
||||
-- Target.Refresh = function()
|
||||
-- ox_target:disableTargeting(true)
|
||||
-- Wait(10)
|
||||
-- ox_target:disableTargeting(false)
|
||||
-- end
|
||||
|
||||
|
||||
|
||||
---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area.
|
||||
---@param name string
|
||||
---@param coords table
|
||||
@@ -104,6 +116,7 @@ end
|
||||
---@param options table
|
||||
Target.AddBoxZone = function(name, coords, size, heading, options, debug)
|
||||
options = Target.FixOptions(options or {})
|
||||
if not next(options) then return end
|
||||
local target = ox_target:addBoxZone({
|
||||
coords = coords,
|
||||
size = size,
|
||||
|
||||
@@ -110,6 +110,17 @@ Target.RemoveModel = function(model)
|
||||
qb_target:RemoveTargetModel(model)
|
||||
end
|
||||
|
||||
-- Target.DisableTargeting = function(bool)
|
||||
-- qb_target:AllowTargeting(bool)
|
||||
-- end
|
||||
|
||||
-- Target.Refresh = function()
|
||||
-- qb_target:AllowTargeting(false)
|
||||
-- Wait(10)
|
||||
-- qb_target:AllowTargeting(true)
|
||||
-- end
|
||||
|
||||
|
||||
---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area.
|
||||
---@param name string
|
||||
---@param coords table
|
||||
@@ -118,6 +129,7 @@ end
|
||||
---@param options table
|
||||
Target.AddBoxZone = function(name, coords, size, heading, options, debug)
|
||||
options = Target.FixOptions(options)
|
||||
if not next(options) then return end
|
||||
qb_target:AddBoxZone(name, coords, size.x, size.y, {
|
||||
name = name,
|
||||
debugPoly = debug or targetDebug,
|
||||
|
||||
@@ -127,6 +127,17 @@ Target.RemoveZone = function(name)
|
||||
end
|
||||
end
|
||||
|
||||
-- Target.DisableTargeting = function(bool)
|
||||
-- sleepless_interact:disableInteract(bool)
|
||||
-- end
|
||||
|
||||
-- Target.Refresh = function()
|
||||
-- sleepless_interact:disableInteract(false)
|
||||
-- Wait(10)
|
||||
-- sleepless_interact:disableInteract(true)
|
||||
-- end
|
||||
|
||||
|
||||
AddEventHandler('onResourceStop', function(resource)
|
||||
if resource == GetCurrentResourceName() then
|
||||
for _, target in pairs(targetZones) do
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
local isPlacing = false
|
||||
RegisterCommand('startplacer', function(source, args, rawCommand)
|
||||
if Bridge.PlaceableObject.IsPlacing() then
|
||||
print("Already placing an object.")
|
||||
return
|
||||
end
|
||||
|
||||
local model = args[1] or 'prop_barrel_01a' -- Default model if none provided
|
||||
local position = GetEntityCoords(PlayerPedId())
|
||||
local result = Bridge.PlaceableObject.Create(model, {
|
||||
allowMovement = true, -- Enable movement mode
|
||||
allowNormal = true, -- Enable normal mode
|
||||
allowVertical = false, -- Allow vertical movement in normal mode
|
||||
startMode = 'normal', -- Start in normal mode
|
||||
depthMin = 2.0,
|
||||
depthMax = 15.0,
|
||||
heightStep = 0.2, -- Height adjustment step
|
||||
boundary = {min = vector3(position.x - 5, position.y - 5, position.z - 1.5), max = vector3(position.x + 5, position.y + 5, position.z + 10)},
|
||||
showInstructionalButtons = true, -- Show instructional buttons
|
||||
})
|
||||
|
||||
if result then
|
||||
print("Object placed!")
|
||||
print("Position:", result.position)
|
||||
print("Heading:", result.heading)
|
||||
else
|
||||
print("Placement cancelled")
|
||||
end
|
||||
end)
|
||||
Reference in new issue
Block a user