@@ -2,8 +2,8 @@ ObjectList = {}
2
2
local DecoMode = false
3
3
local MainCamera = nil
4
4
local curPos
5
- local speeds = { 0.01 , 0.05 , 0.1 , 0.2 , 0.4 , 0.5 }
6
- local curSpeed = 1
5
+ local speeds = 0.01
6
+ local rotationSpeed = 0. 1
7
7
local cursorEnabled = false
8
8
local SelectedObj = nil
9
9
local SelObjHash = {}
@@ -15,7 +15,6 @@ local rotateActive = false
15
15
local peanut = false
16
16
local previewObj = nil
17
17
18
- -- Functions
19
18
20
19
local function openDecorateUI ()
21
20
SetNuiFocus (true , true )
@@ -35,22 +34,12 @@ local function closeDecorateUI()
35
34
})
36
35
end
37
36
38
- local function CreateEditCamera ()
39
- local rot = GetEntityRotation (PlayerPedId ())
40
- local pos = GetEntityCoords (PlayerPedId (), true )
41
- MainCamera = CreateCamWithParams (' DEFAULT_SCRIPTED_CAMERA' , pos .x , pos .y , pos .z , rot .x , rot .y , rot .z , 60.00 , false , 0 )
42
- SetCamActive (MainCamera , true )
43
- RenderScriptCams (true , false , 1 , true , true )
44
- end
45
-
46
37
local function EnableEditMode ()
47
38
local pos = GetEntityCoords (PlayerPedId (), true )
48
39
curPos = { x = pos .x , y = pos .y , z = pos .z }
49
- SetEntityVisible (PlayerPedId (), false )
50
- FreezeEntityPosition (PlayerPedId (), true )
51
- SetEntityCollision (PlayerPedId (), false , false )
52
- CreateEditCamera ()
53
40
DecoMode = true
41
+ exports [' qb-target' ]:AllowTargeting (false )
42
+ LocalPlayer .state :set (' inv_busy' , true , true )
54
43
TriggerEvent (' qb-anticheat:client:ToggleDecorate' , true )
55
44
end
56
45
@@ -75,31 +64,22 @@ local function SaveDecorations()
75
64
end
76
65
end
77
66
78
- local function SetDefaultCamera ()
79
- RenderScriptCams (false , true , 500 , true , true )
80
- SetCamActive (MainCamera , false )
81
- DestroyCam (MainCamera , true )
82
- DestroyAllCams (true )
83
- end
84
-
85
67
local function DisableEditMode ()
86
68
SaveDecorations ()
87
- SetEntityVisible (PlayerPedId (), true )
88
- FreezeEntityPosition (PlayerPedId (), false )
89
- SetEntityCollision (PlayerPedId (), true , true )
90
- SetDefaultCamera ()
91
69
EnableAllControlActions (0 )
92
70
ObjectList = nil
93
71
SelectedObj = nil
94
72
peanut = false
95
73
DecoMode = false
74
+ exports [' qb-target' ]:AllowTargeting (true )
75
+ LocalPlayer .state :set (' inv_busy' , false , true )
96
76
TriggerEvent (' qb-anticheat:client:ToggleDecorate' , false )
97
77
end
98
78
99
79
local function CheckObjMovementInput ()
100
- local xVect = speeds [ curSpeed ]
101
- local yVect = speeds [ curSpeed ]
102
- local zVect = speeds [ curSpeed ]
80
+ local xVect = speeds
81
+ local yVect = speeds
82
+ local zVect = speeds
103
83
104
84
if IsControlPressed (1 , 27 ) or IsDisabledControlPressed (1 , 27 ) then -- Up Arrow
105
85
SelObjPos = GetOffsetFromEntityInWorldCoords (SelectedObj , 0 , - yVect , 0 )
@@ -129,9 +109,9 @@ local function CheckObjMovementInput()
129
109
end
130
110
131
111
local function CheckObjRotationInput ()
132
- local xVect = speeds [ curSpeed ] * 5.5
133
- local yVect = speeds [ curSpeed ] * 5.5
134
- local zVect = speeds [ curSpeed ] * 5.5
112
+ local xVect = rotationSpeed * 5.5
113
+ local yVect = rotationSpeed * 5.5
114
+ local zVect = rotationSpeed * 5.5
135
115
136
116
if IsControlPressed (1 , 27 ) or IsDisabledControlPressed (1 , 27 ) then -- Up Arrow
137
117
SelObjRot .x = SelObjRot .x + xVect
@@ -160,16 +140,16 @@ local function CheckObjRotationInput()
160
140
SetEntityRotation (SelectedObj , SelObjRot .x , SelObjRot .y , SelObjRot .z )
161
141
end
162
142
163
- local function CheckRotationInput ()
164
- local rightAxisX = GetDisabledControlNormal (0 , 220 )
165
- local rightAxisY = GetDisabledControlNormal (0 , 221 )
166
- local rotation = GetCamRot (MainCamera , 2 )
167
- if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
168
- local new_z = rotation .z + rightAxisX * - 1.0 * (2.0 ) * (4.0 + 0.1 )
169
- local new_x = math.max (math.min (20.0 , rotation .x + rightAxisY * - 1.0 * (2.0 ) * (4.0 + 0.1 )), - 20.5 )
170
- SetCamRot (MainCamera , new_x , 0.0 , new_z , 2 )
171
- end
172
- end
143
+ -- local function CheckRotationInput()
144
+ -- local rightAxisX = GetDisabledControlNormal(0, 220)
145
+ -- local rightAxisY = GetDisabledControlNormal(0, 221)
146
+ -- local rotation = GetCamRot(MainCamera, 2)
147
+ -- if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
148
+ -- local new_z = rotation.z + rightAxisX * -1.0 * (2.0) * (4.0 + 0.1)
149
+ -- local new_x = math.max(math.min(20.0, rotation.x + rightAxisY * -1.0 * (2.0) * (4.0 + 0.1)), -20.5)
150
+ -- SetCamRot(MainCamera, new_x, 0.0, new_z, 2)
151
+ -- end
152
+ -- end
173
153
174
154
local function getTableLength (T )
175
155
local count = 0
@@ -183,35 +163,54 @@ local function degToRad(degs)
183
163
return degs * 3.141592653589793 / 180
184
164
end
185
165
186
- local function CheckMovementInput ()
187
- local rotation = GetCamRot (MainCamera , 2 )
188
-
189
- if IsControlJustReleased (0 , 21 ) then -- Left Shift
190
- curSpeed = curSpeed + 1
191
- if curSpeed > getTableLength (speeds ) then
192
- curSpeed = 1
193
- end
194
- QBCore .Functions .Notify (Lang :t (' info.speed' ) .. tostring (speeds [curSpeed ]))
195
- end
196
166
197
- local xVect = speeds [curSpeed ] * math.sin (degToRad (rotation .z )) * - 1.0
198
- local yVect = speeds [curSpeed ] * math.cos (degToRad (rotation .z ))
199
- local zVect = speeds [curSpeed ] * math.tan (degToRad (rotation .x ) - degToRad (rotation .y ))
167
+ -- Raycast function
168
+
169
+ local function RayCastGamePlayCamera (distance , ignoreEntity )
170
+ local cameraRotation = GetGameplayCamRot ()
171
+ local cameraCoord = GetGameplayCamCoord ()
172
+ local direction = vector3 (
173
+ math.sin (degToRad (cameraRotation .z )) * - 1.0 ,
174
+ math.cos (degToRad (cameraRotation .z )),
175
+ math.tan (degToRad (cameraRotation .x ))
176
+ )
177
+ local destination = cameraCoord + direction * distance
178
+ local rayHandle = StartShapeTestRay (cameraCoord .x , cameraCoord .y , cameraCoord .z , destination .x , destination .y , destination .z , 17 , ignoreEntity , 0 )
179
+ local _ , hit , endCoords , surfaceNormal , entityHit = GetShapeTestResult (rayHandle )
180
+ return hit , endCoords , surfaceNormal , entityHit
181
+ end
200
182
201
- if IsControlPressed (1 , 32 ) or IsDisabledControlPressed (1 , 32 ) then -- W
202
- curPos .x = curPos .x + xVect
203
- curPos .y = curPos .y + yVect
204
- curPos .z = curPos .z + zVect
205
- end
206
183
207
- if IsControlPressed (1 , 33 ) or IsDisabledControlPressed (1 , 33 ) then -- S
208
- curPos .x = curPos .x - xVect
209
- curPos .y = curPos .y - yVect
210
- curPos .z = curPos .z - zVect
211
- end
212
184
213
- SetCamCoord (MainCamera , curPos .x , curPos .y , curPos .z )
214
- end
185
+ -- local function CheckMovementInput()
186
+ -- local rotation = GetCamRot(MainCamera, 2)
187
+ --
188
+ -- if IsControlJustReleased(0, 21) then -- Left Shift
189
+ -- curSpeed = curSpeed + 1
190
+ -- if curSpeed > getTableLength(speeds) then
191
+ -- curSpeed = 1
192
+ -- end
193
+ -- QBCore.Functions.Notify(Lang:t('info.speed') .. tostring(speeds[curSpeed]))
194
+ -- end
195
+ --
196
+ -- local xVect = speeds[curSpeed] * math.sin(degToRad(rotation.z)) * -1.0
197
+ -- local yVect = speeds[curSpeed] * math.cos(degToRad(rotation.z))
198
+ -- local zVect = speeds[curSpeed] * math.tan(degToRad(rotation.x) - degToRad(rotation.y))
199
+ --
200
+ -- if IsControlPressed(1, 32) or IsDisabledControlPressed(1, 32) then -- W
201
+ -- curPos.x = curPos.x + xVect
202
+ -- curPos.y = curPos.y + yVect
203
+ -- curPos.z = curPos.z + zVect
204
+ -- end
205
+ --
206
+ -- if IsControlPressed(1, 33) or IsDisabledControlPressed(1, 33) then -- S
207
+ -- curPos.x = curPos.x - xVect
208
+ -- curPos.y = curPos.y - yVect
209
+ -- curPos.z = curPos.z - zVect
210
+ -- end
211
+ --
212
+ -- SetCamCoord(MainCamera, curPos.x, curPos.y, curPos.z)
213
+ -- end
215
214
216
215
-- Events
217
216
@@ -372,17 +371,18 @@ RegisterNUICallback('spawnobject', function(data, cb)
372
371
while not HasModelLoaded (modelHash ) do
373
372
Wait (1000 )
374
373
end
375
- local rotation = GetCamRot (MainCamera , 2 )
376
- local xVect = 2.5 * math.sin (degToRad (rotation .z )) * - 1.0
377
- local yVect = 2.5 * math.cos (degToRad (rotation .z ))
378
- SelectedObj = CreateObject (modelHash , curPos .x + xVect , curPos .y + yVect , curPos .z , false , false , false )
374
+ local rotation = 90
375
+ local hit , castPos , _ , _ = RayCastGamePlayCamera (50.0 , PlayerPedId ())
376
+ curPos = castPos
377
+
378
+ SelectedObj = CreateObject (modelHash , curPos .x , curPos .y , curPos .z , false , false , false )
379
379
local pos = GetEntityCoords (SelectedObj , true )
380
380
local rot = GetEntityRotation (SelectedObj )
381
381
SelObjRot = { x = rot .x , y = rot .y , z = rot .z }
382
382
SelObjPos = { x = pos .x , y = pos .y , z = pos .z }
383
383
SelObjHash = data .object
384
384
PlaceObjectOnGroundProperly (SelectedObj )
385
- SetEntityCompletelyDisableCollision (SelectedObj , true ) -- Prevents crazy physics when collidin with other entitys
385
+ SetEntityCompletelyDisableCollision (SelectedObj , true , false ) -- Prevents crazy physics when collidin with other entitys
386
386
peanut = true
387
387
cb (' ok' )
388
388
end )
@@ -409,10 +409,10 @@ RegisterNUICallback('chooseobject', function(data, cb)
409
409
type = ' objectLoaded' ,
410
410
})
411
411
412
- local rotation = GetCamRot ( MainCamera , 2 )
413
- local xVect = 2.5 * math.sin ( degToRad ( rotation . z )) * - 1.0
414
- local yVect = 2.5 * math.cos ( degToRad ( rotation . z ))
415
- previewObj = CreateObject (modelHash , curPos .x + xVect , curPos .y + yVect , curPos .z , false , false , false )
412
+ local rotation = 90 -- rotation
413
+ local hit , castPos , _ , _ = RayCastGamePlayCamera ( 50.0 , PlayerPedId ())
414
+ curPos = castPos
415
+ previewObj = CreateObject (modelHash , curPos .x , curPos .y , curPos .z , false , false , false )
416
416
PlaceObjectOnGroundProperly (previewObj )
417
417
cb (' ok' )
418
418
end )
@@ -423,7 +423,9 @@ CreateThread(function()
423
423
while true do
424
424
Wait (7 )
425
425
if DecoMode then
426
- DisableAllControlActions (0 )
426
+
427
+
428
+ -- DisableAllControlActions(0)
427
429
EnableControlAction (0 , 32 , true ) -- W
428
430
EnableControlAction (0 , 33 , true ) -- S
429
431
EnableControlAction (0 , 245 , true ) -- T
@@ -440,29 +442,40 @@ CreateThread(function()
440
442
EnableControlAction (0 , 10 , true ) -- Page Up
441
443
EnableControlAction (0 , 11 , true ) -- Page Down
442
444
EnableControlAction (0 , 194 , true ) -- Backspace
443
-
444
445
DisplayRadar (false )
445
446
446
- CheckRotationInput ()
447
- CheckMovementInput ()
447
+ if IsControlJustReleased (0 , 166 ) then -- F5
448
+
449
+ if not cursorEnabled then
450
+ SetNuiFocus (true , true )
451
+ cursorEnabled = true
452
+ else
453
+ SetNuiFocus (false , false )
454
+ cursorEnabled = false
455
+ end
456
+
457
+ end
458
+
459
+
448
460
449
461
if SelectedObj and peanut then
450
- SetEntityDrawOutline (SelectedObj )
451
- SetEntityDrawOutlineColor (116 , 189 , 252 , 100 )
452
- 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 )
453
- if rotateActive then
462
+ FreezeEntityPosition (SelectedObj , true )
463
+ SetEntityDrawOutline (SelectedObj , true )
464
+ SetEntityDrawOutlineColor (255 , 150 , 150 , 200 )
465
+
466
+ if IsControlPressed (0 , 21 ) then -- left shft
454
467
CheckObjRotationInput ()
455
468
else
456
469
CheckObjMovementInput ()
457
470
end
458
- if IsControlJustReleased (0 , 170 ) then -- F3
459
- rotateActive = not rotateActive
460
- end
461
- if IsControlJustReleased (0 , 19 ) then -- Left Alt
462
- PlaceObjectOnGroundProperly (SelectedObj )
463
- local groundPos = GetEntityCoords (SelectedObj )
464
- SelObjPos = groundPos
471
+ if IsControlPressed (0 , 19 ) then -- Left Alt
472
+ local hit , pos , _ , _ = RayCastGamePlayCamera (50.0 , SelectedObj )
473
+ if hit then
474
+ SetEntityCoords (SelectedObj , pos .x , pos .y , pos .z )
475
+ SelObjPos = pos
476
+ end
465
477
end
478
+
466
479
if IsControlJustReleased (0 , 191 ) then -- Enter
467
480
SetNuiFocus (true , true )
468
481
cursorEnabled = true
@@ -478,16 +491,13 @@ CreateThread(function()
478
491
SelObjId = 0
479
492
peanut = false
480
493
isEdit = false
481
- end
482
- end
483
- else
484
- if IsControlJustPressed (0 , 166 ) then -- F5
485
- if not cursorEnabled then
486
- SetNuiFocus (true , true )
487
- cursorEnabled = true
494
+ SetEntityDrawOutline (SelectedObj , false )
488
495
end
489
496
end
490
497
end
498
+
499
+
500
+
491
501
end
492
502
end
493
503
end )
@@ -497,8 +507,8 @@ CreateThread(function()
497
507
while true do
498
508
Wait (7 )
499
509
if DecoMode then
500
- local camPos = GetCamCoord ( MainCamera )
501
- 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 ))
510
+ local Pos = GetEntityCoords ( PlayerPedId () )
511
+ 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 ))
502
512
if dist > 50.0 then
503
513
DisableEditMode ()
504
514
closeDecorateUI ()
0 commit comments