Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
GhzGarage authored Jun 25, 2024
2 parents 3fbed1c + 2a079e9 commit ba68ac0
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 116 deletions.
210 changes: 110 additions & 100 deletions client/decorate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ ObjectList = {}
local DecoMode = false
local MainCamera = nil
local curPos
local speeds = { 0.01, 0.05, 0.1, 0.2, 0.4, 0.5 }
local curSpeed = 1
local speeds = 0.01
local rotationSpeed = 0.1
local cursorEnabled = false
local SelectedObj = nil
local SelObjHash = {}
Expand All @@ -15,7 +15,6 @@ local rotateActive = false
local peanut = false
local previewObj = nil

-- Functions

local function openDecorateUI()
SetNuiFocus(true, true)
Expand All @@ -35,22 +34,12 @@ local function closeDecorateUI()
})
end

local function CreateEditCamera()
local rot = GetEntityRotation(PlayerPedId())
local pos = GetEntityCoords(PlayerPedId(), true)
MainCamera = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, 60.00, false, 0)
SetCamActive(MainCamera, true)
RenderScriptCams(true, false, 1, true, true)
end

local function EnableEditMode()
local pos = GetEntityCoords(PlayerPedId(), true)
curPos = { x = pos.x, y = pos.y, z = pos.z }
SetEntityVisible(PlayerPedId(), false)
FreezeEntityPosition(PlayerPedId(), true)
SetEntityCollision(PlayerPedId(), false, false)
CreateEditCamera()
DecoMode = true
exports['qb-target']:AllowTargeting(false)
LocalPlayer.state:set('inv_busy', true, true)
TriggerEvent('qb-anticheat:client:ToggleDecorate', true)
end

Expand All @@ -75,31 +64,22 @@ local function SaveDecorations()
end
end

local function SetDefaultCamera()
RenderScriptCams(false, true, 500, true, true)
SetCamActive(MainCamera, false)
DestroyCam(MainCamera, true)
DestroyAllCams(true)
end

local function DisableEditMode()
SaveDecorations()
SetEntityVisible(PlayerPedId(), true)
FreezeEntityPosition(PlayerPedId(), false)
SetEntityCollision(PlayerPedId(), true, true)
SetDefaultCamera()
EnableAllControlActions(0)
ObjectList = nil
SelectedObj = nil
peanut = false
DecoMode = false
exports['qb-target']:AllowTargeting(true)
LocalPlayer.state:set('inv_busy', false, true)
TriggerEvent('qb-anticheat:client:ToggleDecorate', false)
end

local function CheckObjMovementInput()
local xVect = speeds[curSpeed]
local yVect = speeds[curSpeed]
local zVect = speeds[curSpeed]
local xVect = speeds
local yVect = speeds
local zVect = speeds

if IsControlPressed(1, 27) or IsDisabledControlPressed(1, 27) then -- Up Arrow
SelObjPos = GetOffsetFromEntityInWorldCoords(SelectedObj, 0, -yVect, 0)
Expand Down Expand Up @@ -129,9 +109,9 @@ local function CheckObjMovementInput()
end

local function CheckObjRotationInput()
local xVect = speeds[curSpeed] * 5.5
local yVect = speeds[curSpeed] * 5.5
local zVect = speeds[curSpeed] * 5.5
local xVect = rotationSpeed * 5.5
local yVect = rotationSpeed * 5.5
local zVect = rotationSpeed * 5.5

if IsControlPressed(1, 27) or IsDisabledControlPressed(1, 27) then -- Up Arrow
SelObjRot.x = SelObjRot.x + xVect
Expand Down Expand Up @@ -160,16 +140,16 @@ local function CheckObjRotationInput()
SetEntityRotation(SelectedObj, SelObjRot.x, SelObjRot.y, SelObjRot.z)
end

local function CheckRotationInput()
local rightAxisX = GetDisabledControlNormal(0, 220)
local rightAxisY = GetDisabledControlNormal(0, 221)
local rotation = GetCamRot(MainCamera, 2)
if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
local new_z = rotation.z + rightAxisX * -1.0 * (2.0) * (4.0 + 0.1)
local new_x = math.max(math.min(20.0, rotation.x + rightAxisY * -1.0 * (2.0) * (4.0 + 0.1)), -20.5)
SetCamRot(MainCamera, new_x, 0.0, new_z, 2)
end
end
--local function CheckRotationInput()
-- local rightAxisX = GetDisabledControlNormal(0, 220)
-- local rightAxisY = GetDisabledControlNormal(0, 221)
-- local rotation = GetCamRot(MainCamera, 2)
-- if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
-- local new_z = rotation.z + rightAxisX * -1.0 * (2.0) * (4.0 + 0.1)
-- local new_x = math.max(math.min(20.0, rotation.x + rightAxisY * -1.0 * (2.0) * (4.0 + 0.1)), -20.5)
-- SetCamRot(MainCamera, new_x, 0.0, new_z, 2)
-- end
--end

local function getTableLength(T)
local count = 0
Expand All @@ -183,35 +163,54 @@ local function degToRad(degs)
return degs * 3.141592653589793 / 180
end

local function CheckMovementInput()
local rotation = GetCamRot(MainCamera, 2)

if IsControlJustReleased(0, 21) then -- Left Shift
curSpeed = curSpeed + 1
if curSpeed > getTableLength(speeds) then
curSpeed = 1
end
QBCore.Functions.Notify(Lang:t('info.speed') .. tostring(speeds[curSpeed]))
end

local xVect = speeds[curSpeed] * math.sin(degToRad(rotation.z)) * -1.0
local yVect = speeds[curSpeed] * math.cos(degToRad(rotation.z))
local zVect = speeds[curSpeed] * math.tan(degToRad(rotation.x) - degToRad(rotation.y))
-- Raycast function

local function RayCastGamePlayCamera(distance, ignoreEntity)
local cameraRotation = GetGameplayCamRot()
local cameraCoord = GetGameplayCamCoord()
local direction = vector3(
math.sin(degToRad(cameraRotation.z)) * -1.0,
math.cos(degToRad(cameraRotation.z)),
math.tan(degToRad(cameraRotation.x))
)
local destination = cameraCoord + direction * distance
local rayHandle = StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, 17, ignoreEntity, 0)
local _, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(rayHandle)
return hit, endCoords, surfaceNormal, entityHit
end

if IsControlPressed(1, 32) or IsDisabledControlPressed(1, 32) then -- W
curPos.x = curPos.x + xVect
curPos.y = curPos.y + yVect
curPos.z = curPos.z + zVect
end

if IsControlPressed(1, 33) or IsDisabledControlPressed(1, 33) then -- S
curPos.x = curPos.x - xVect
curPos.y = curPos.y - yVect
curPos.z = curPos.z - zVect
end

SetCamCoord(MainCamera, curPos.x, curPos.y, curPos.z)
end
--local function CheckMovementInput()
-- local rotation = GetCamRot(MainCamera, 2)
--
-- if IsControlJustReleased(0, 21) then -- Left Shift
-- curSpeed = curSpeed + 1
-- if curSpeed > getTableLength(speeds) then
-- curSpeed = 1
-- end
-- QBCore.Functions.Notify(Lang:t('info.speed') .. tostring(speeds[curSpeed]))
-- end
--
-- local xVect = speeds[curSpeed] * math.sin(degToRad(rotation.z)) * -1.0
-- local yVect = speeds[curSpeed] * math.cos(degToRad(rotation.z))
-- local zVect = speeds[curSpeed] * math.tan(degToRad(rotation.x) - degToRad(rotation.y))
--
-- if IsControlPressed(1, 32) or IsDisabledControlPressed(1, 32) then -- W
-- curPos.x = curPos.x + xVect
-- curPos.y = curPos.y + yVect
-- curPos.z = curPos.z + zVect
-- end
--
-- if IsControlPressed(1, 33) or IsDisabledControlPressed(1, 33) then -- S
-- curPos.x = curPos.x - xVect
-- curPos.y = curPos.y - yVect
-- curPos.z = curPos.z - zVect
-- end
--
-- SetCamCoord(MainCamera, curPos.x, curPos.y, curPos.z)
--end

-- Events

Expand Down Expand Up @@ -372,17 +371,18 @@ RegisterNUICallback('spawnobject', function(data, cb)
while not HasModelLoaded(modelHash) do
Wait(1000)
end
local rotation = GetCamRot(MainCamera, 2)
local xVect = 2.5 * math.sin(degToRad(rotation.z)) * -1.0
local yVect = 2.5 * math.cos(degToRad(rotation.z))
SelectedObj = CreateObject(modelHash, curPos.x + xVect, curPos.y + yVect, curPos.z, false, false, false)
local rotation = 90
local hit, castPos, _, _ = RayCastGamePlayCamera(50.0, PlayerPedId())
curPos = castPos

SelectedObj = CreateObject(modelHash, curPos.x, curPos.y, curPos.z, false, false, false)
local pos = GetEntityCoords(SelectedObj, true)
local rot = GetEntityRotation(SelectedObj)
SelObjRot = { x = rot.x, y = rot.y, z = rot.z }
SelObjPos = { x = pos.x, y = pos.y, z = pos.z }
SelObjHash = data.object
PlaceObjectOnGroundProperly(SelectedObj)
SetEntityCompletelyDisableCollision(SelectedObj, true) -- Prevents crazy physics when collidin with other entitys
SetEntityCompletelyDisableCollision(SelectedObj, true, false) -- Prevents crazy physics when collidin with other entitys
peanut = true
cb('ok')
end)
Expand All @@ -409,10 +409,10 @@ RegisterNUICallback('chooseobject', function(data, cb)
type = 'objectLoaded',
})

local rotation = GetCamRot(MainCamera, 2)
local xVect = 2.5 * math.sin(degToRad(rotation.z)) * -1.0
local yVect = 2.5 * math.cos(degToRad(rotation.z))
previewObj = CreateObject(modelHash, curPos.x + xVect, curPos.y + yVect, curPos.z, false, false, false)
local rotation = 90 -- rotation
local hit, castPos, _, _ = RayCastGamePlayCamera(50.0, PlayerPedId())
curPos = castPos
previewObj = CreateObject(modelHash, curPos.x, curPos.y, curPos.z, false, false, false)
PlaceObjectOnGroundProperly(previewObj)
cb('ok')
end)
Expand All @@ -423,7 +423,9 @@ CreateThread(function()
while true do
Wait(7)
if DecoMode then
DisableAllControlActions(0)


--DisableAllControlActions(0)
EnableControlAction(0, 32, true) -- W
EnableControlAction(0, 33, true) -- S
EnableControlAction(0, 245, true) -- T
Expand All @@ -440,29 +442,40 @@ CreateThread(function()
EnableControlAction(0, 10, true) -- Page Up
EnableControlAction(0, 11, true) -- Page Down
EnableControlAction(0, 194, true) -- Backspace

DisplayRadar(false)

CheckRotationInput()
CheckMovementInput()
if IsControlJustReleased(0, 166) then -- F5

if not cursorEnabled then
SetNuiFocus(true, true)
cursorEnabled = true
else
SetNuiFocus(false, false)
cursorEnabled = false
end

end



if SelectedObj and peanut then
SetEntityDrawOutline(SelectedObj)
SetEntityDrawOutlineColor(116, 189, 252, 100)
DrawMarker(21, SelObjPos.x, SelObjPos.y, SelObjPos.z + 1.28, 0.0, 0.0, 0.0, 180.0, 0.0, 0.0, 0.6, 0.6, 0.6, 28, 149, 255, 100, true, true, 2, false, false, false, false)
if rotateActive then
FreezeEntityPosition(SelectedObj, true)
SetEntityDrawOutline(SelectedObj, true)
SetEntityDrawOutlineColor(255, 150, 150, 200)

if IsControlPressed(0, 21) then --left shft
CheckObjRotationInput()
else
CheckObjMovementInput()
end
if IsControlJustReleased(0, 170) then -- F3
rotateActive = not rotateActive
end
if IsControlJustReleased(0, 19) then -- Left Alt
PlaceObjectOnGroundProperly(SelectedObj)
local groundPos = GetEntityCoords(SelectedObj)
SelObjPos = groundPos
if IsControlPressed(0, 19) then -- Left Alt
local hit, pos, _, _ = RayCastGamePlayCamera(50.0, SelectedObj)
if hit then
SetEntityCoords(SelectedObj, pos.x, pos.y, pos.z)
SelObjPos = pos
end
end

if IsControlJustReleased(0, 191) then -- Enter
SetNuiFocus(true, true)
cursorEnabled = true
Expand All @@ -478,16 +491,13 @@ CreateThread(function()
SelObjId = 0
peanut = false
isEdit = false
end
end
else
if IsControlJustPressed(0, 166) then -- F5
if not cursorEnabled then
SetNuiFocus(true, true)
cursorEnabled = true
SetEntityDrawOutline(SelectedObj, false)
end
end
end



end
end
end)
Expand All @@ -497,8 +507,8 @@ CreateThread(function()
while true do
Wait(7)
if DecoMode then
local camPos = GetCamCoord(MainCamera)
local dist = #(vector3(camPos.x, camPos.y, camPos.z) - vector3(Config.Houses[ClosestHouse].coords.enter.x, Config.Houses[ClosestHouse].coords.enter.y, Config.Houses[ClosestHouse].coords.enter.z))
local Pos = GetEntityCoords(PlayerPedId())
local dist = #(vector3(Pos.x, Pos.y, Pos.z) - vector3(Config.Houses[ClosestHouse].coords.enter.x, Config.Houses[ClosestHouse].coords.enter.y, Config.Houses[ClosestHouse].coords.enter.z))
if dist > 50.0 then
DisableEditMode()
closeDecorateUI()
Expand Down
9 changes: 1 addition & 8 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1006,14 +1006,8 @@ local function openHouseStash()
if not CurrentHouse then return end
local stashLoc = vector3(stashLocation.x, stashLocation.y, stashLocation.z)
if CheckDistance(stashLoc, 1.5) then
local houseTier = tonumber(Config.Houses[CurrentHouse].tier)
if Config.StashWeights[houseTier] and tonumber(Config.StashWeights[houseTier].maxweight) and tonumber(Config.StashWeights[houseTier].slots) then
TriggerServerEvent('inventory:server:OpenInventory', 'stash', CurrentHouse, Config.StashWeights[houseTier])
else
TriggerServerEvent('inventory:server:OpenInventory', 'stash', CurrentHouse)
end
TriggerEvent('inventory:client:SetCurrentStash', CurrentHouse)
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'StashOpen', 0.4)
TriggerServerEvent('qb-houses:server:openStash', CurrentHouse)
end
end

Expand Down Expand Up @@ -1386,7 +1380,6 @@ RegisterNetEvent('qb-houses:client:HomeInvasion', function()
if dist < 1 then
if Config.Houses[ClosestHouse].locked then
if not Config.Houses[ClosestHouse].IsRaming then

local success = exports['qb-minigames']:Skillbar('medium') -- calling like this will just change difficulty and still use 1234
if success then
DoRamAnimation(true)
Expand Down
8 changes: 3 additions & 5 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@
</div>
<div class="decorate-keys">
<ul id="decorate-keys" style="list-style-type:disc;">
<li>WASD/Mouse to move the camera.</li>
<li>Arrow Keys to Move Object.</li>
<li>PAGE UP/DOWN To move object up and down.</li>
<li>LEFTALT To place object on the ground></object>.</li>
<li>F3 To switch to turn and move.</li>
<li>HOLD Left Shift to Rotate to rotate</li>
<li>LEFTALT To place object where you'r looking at.</li>
<li>ENTER to buy and place the object.</li>
<li>F5 to turn mouse on / off to turn mouse on / off to turn mouse on / off.</li>
<li>F5 switch between menu and placement mode</li>
<li>ESC to disable Decoration mode.</li>
</ul>
</div>
Expand Down
Loading

0 comments on commit ba68ac0

Please sign in to comment.