2025-02-05 17:42:50 -06:00
Placeable = Placeable or {}
2025-03-30 21:06:58 -05:00
Utility = Utility or Require ( "lib/utility/client/utility.lua" )
2025-01-10 16:36:20 -05:00
local activePlacementProp = nil
lib.locale ()
-- Object placer --
local placementText = {
2025-06-09 00:15:27 -04:00
locale ( 'placeable_object.place_object_place' ),
locale ( 'placeable_object.place_object_cancel' ),
locale ( 'placeable_object.place_object_scroll_up' ),
locale ( 'placeable_object.place_object_scroll_down' )
2025-01-10 16:36:20 -05:00
}
local function finishPlacing ()
2025-01-14 10:55:14 -06:00
Bridge.Notify . HideHelpText ()
2025-01-10 16:36:20 -05:00
if activePlacementProp == nil then return end
DeleteObject ( activePlacementProp )
activePlacementProp = nil
end
2025-02-15 06:12:14 -05:00
--[[
RegisterCommand('testplacement', function()
Placeable.PlaceObject("prop_cs_cardbox_01", 10, true, nil, 0.0)
end, false)
--]]
2025-02-05 17:42:50 -06:00
Placeable.PlaceObject = function ( object , distance , snapToGround , allowedMats , offset )
2025-02-15 06:12:14 -05:00
distance = tonumber ( distance or 10.0 )
2025-01-10 16:36:20 -05:00
if activePlacementProp then return end
2025-06-09 00:15:27 -04:00
if not object then Prints.Error ( 'placeable_object.no_prop_defined' ) end
2025-01-10 16:36:20 -05:00
local propObject = type ( object ) == 'string' and joaat ( object ) or object
local heading = 0.0
local checkDist = distance or 10.0
2025-07-28 01:37:52 -04:00
local ped = PlayerPedId ()
2025-01-10 16:36:20 -05:00
Utility.LoadModel ( propObject )
activePlacementProp = CreateObject ( propObject , 1.0 , 1.0 , 1.0 , false , true , true )
SetModelAsNoLongerNeeded ( propObject )
SetEntityAlpha ( activePlacementProp , 150 , false )
SetEntityCollision ( activePlacementProp , false , false )
SetEntityInvincible ( activePlacementProp , true )
FreezeEntityPosition ( activePlacementProp , true )
2025-02-15 06:12:14 -05:00
Bridge.Notify . ShowHelpText ( type ( placementText ) == 'table' and table.concat ( placementText ))
2025-01-10 16:36:20 -05:00
local outLine = false
while activePlacementProp do
--local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4)
--local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4, nil)
local hit , _ , coords , _ , materialHash = lib.raycast . fromCamera ( 1 , 4 )
if hit then
if offset then
coords += offset
end
SetEntityCoords ( activePlacementProp , coords.x , coords.y , coords.z , false , false , false , false )
2025-07-28 01:37:52 -04:00
local distCheck = # ( GetEntityCoords ( ped ) - coords )
2025-01-10 16:36:20 -05:00
SetEntityHeading ( activePlacementProp , heading )
if snapToGround then
PlaceObjectOnGroundProperly ( activePlacementProp )
end
if outLine then
outLine = false
SetEntityDrawOutline ( activePlacementProp , false )
end
if ( allowedMats and not allowedMats [ materialHash ]) or distCheck >= checkDist then
if not outLine then
outLine = true
SetEntityDrawOutline ( activePlacementProp , true )
end
end
if IsControlJustReleased ( 0 , 38 ) then
if not outLine and ( not allowedMats or allowedMats [ materialHash ]) and distCheck < checkDist then
finishPlacing ()
return coords , heading
end
end
if IsControlJustReleased ( 0 , 73 ) then
finishPlacing ()
return nil , nil
end
if IsControlJustReleased ( 0 , 14 ) then
heading = heading + 5
if heading > 360 then heading = 0.0 end
end
if IsControlJustReleased ( 0 , 15 ) then
heading = heading - 5
if heading < 0 then
heading = 360.0
end
end
end
end
end
2025-02-05 17:42:50 -06:00
Placeable.StopPlacing = function ()
2025-01-10 16:36:20 -05:00
if not activePlacementProp then return end
finishPlacing ()
end
2025-02-05 17:42:50 -06:00
return Placeable
2025-01-10 16:36:20 -05:00
-- This is derrived and slightly altered from its creator and licensed under GPL-3.0 license Author:Zoo, the original is located here https://github.com/Renewed-Scripts/Renewed-Lib/tree/main