1+ local creationLaser = false
2+ local editingScene = false
3+ local scenes = {}
4+ local sceneData = {}
5+ local closestScenes = {}
6+
7+ lib .requestStreamedTextureDict (" commonmenu" )
8+ lib .requestStreamedTextureDict (" scenes" )
9+
10+ local function toggleNuiFrame (shouldShow )
11+ SetNuiFocus (shouldShow , shouldShow )
12+ SendReactMessage (' setVisible' , shouldShow )
13+ end
14+
15+ RegisterNUICallback (' hideFrame' , function (_ , cb )
16+ toggleNuiFrame (false )
17+ editingScene = false
18+ cb ({})
19+ end )
20+
21+ RegisterNUICallback (' CreateScene' , function (data , cb )
22+ toggleNuiFrame (false )
23+ editingScene = false
24+ TriggerServerEvent (' fivem-scenes:server:createScene' , sceneData )
25+ cb ({})
26+ end )
27+
28+ RegisterNUICallback (' UpdateScene' , function (data , cb )
29+ data .coords = sceneData .coords
30+ sceneData = data
31+ cb ({})
32+ end )
33+
34+ RegisterCommand (' createScene' , function ()
35+ ToggleCreationLaser ()
36+ end , false )
37+
38+ RegisterNetEvent (' fivem-scenes:client:newScene' , function (data )
39+ scenes [# scenes + 1 ] = data
40+ end )
41+
42+ CreateThread (function ()
43+ local data = lib .callback .await (" fivem-scenes:server:getScenes" )
44+ scenes = data
45+ end )
46+
47+ CreateThread (function ()
48+ while true do
49+ closestScenes = {}
50+ for i = 1 , # scenes do
51+ local currentScene = scenes [i ]
52+ local plyPosition = GetEntityCoords (PlayerPedId ())
53+ local distance = # (plyPosition - currentScene .coords )
54+ if distance < Config .MaxPlacementDistance then
55+ closestScenes [# closestScenes + 1 ] = currentScene
56+ end
57+ end
58+ Wait (1000 )
59+ end
60+ end )
61+
62+ CreateThread (function ()
63+ while true do
64+ local wait = 1000
65+ if # closestScenes > 0 then
66+ wait = 0
67+ for i = 1 , # closestScenes do
68+ DrawScene (closestScenes [i ])
69+ end
70+ end
71+ Wait (wait )
72+ end
73+ end )
74+
75+ function ToggleCreationLaser ()
76+ creationLaser = true
77+ if creationLaser then
78+ CreateThread (function ()
79+ while creationLaser do
80+ local hit , coords = DrawLaser (' PRESS ~g~E~w~ TO CREATE SCENE' , {r = 2 , g = 241 , b = 181 , a = 200 })
81+
82+ sceneData .coords = coords
83+ if IsControlJustReleased (0 , 38 ) then
84+ if hit then
85+ creationLaser = false
86+ EditingScene ()
87+ toggleNuiFrame (true )
88+ else
89+ lib .notify ({description = " Laser did not hit anything." , type = " error" })
90+ end
91+ end
92+ Wait (0 )
93+ end
94+ end )
95+ end
96+ end
97+
98+ function EditingScene ()
99+ editingScene = true
100+ if editingScene then
101+ CreateThread (function ()
102+ while editingScene do
103+ DrawScene (sceneData )
104+ Wait (0 )
105+ end
106+ end )
107+ end
108+ end
109+
110+ function DrawLaser (message , color )
111+ local hit , coords = RayCastGamePlayCamera (Config .MaxPlacementDistance )
112+ Draw2DText (message , 4 , {255 , 255 , 255 }, 0.4 , 0.43 , 0.888 + 0.025 )
113+
114+ if hit then
115+ local position = GetEntityCoords (PlayerPedId ())
116+ DrawLine (position .x , position .y , position .z , coords .x , coords .y , coords .z , color .r , color .g , color .b , color .a )
117+ DrawMarker (28 , coords .x , coords .y , coords .z , 0.0 , 0.0 , 0.0 , 0.0 , 180.0 , 0.0 , 0.1 , 0.1 , 0.1 , color .r , color .g , color .b , color .a , false , true , 2 , nil , nil , false )
118+ end
119+
120+ return hit , coords
121+ end
122+
123+ function DrawScene (currentScene )
124+ local onScreen , screenX , screenY = GetScreenCoordFromWorldCoord (currentScene .coords .x , currentScene .coords .y , currentScene .coords .z )
125+ if onScreen then
126+ local camCoords = GetFinalRenderedCamCoord ()
127+ local distance = # (currentScene .coords - camCoords )
128+ local fov = (1 / GetGameplayCamFov ()) * 75
129+ local scale = (1 / distance ) * (4 ) * fov * (currentScene .fontSize or 1 )
130+ local r ,g ,b = rgbToHex (currentScene .colour or " #ffffff" )
131+ local text = currentScene .text
132+ SetTextScale (0.0 , scale )
133+ SetTextFont (currentScene .font or 0 )
134+ SetTextColour (r , g , b , 255 )
135+ SetTextProportional (true )
136+ SetTextWrap (0.0 , 1.0 )
137+ SetTextCentre (true )
138+ if currentScene .shadow then
139+ SetTextDropshadow (1 , 255 , 255 , 255 , 0 )
140+ end
141+ if currentScene .outline then
142+ SetTextOutline ()
143+ end
144+ BeginTextCommandGetWidth (" STRING" )
145+ AddTextComponentString (text ~= " " and text or " Example Text" )
146+ local H = GetRenderedCharacterHeight (scale , currentScene .font )+ 0.0030
147+ local W = EndTextCommandGetWidth (currentScene .font )+ 0.005
148+ BeginTextCommandDisplayText (" STRING" )
149+ AddTextComponentString (text ~= " " and text or " Example Text" )
150+ EndTextCommandDisplayText (screenX , screenY )
151+
152+ if currentScene .background and currentScene .background ~= " none" then
153+ local br , bg , bb = rgbToHex (currentScene .backgroundColour )
154+ DrawSprite (" scenes" , currentScene .background , screenX + currentScene .backgroundX * scale , screenY + currentScene .backgroundY * scale , W + currentScene .backgroundWidth * scale , H + currentScene .backgroundHeight * scale , 0 , br ,bg ,bb , currentScene .backgroundAlpha )
155+ end
156+ end
157+ end
0 commit comments