-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclient.lua
More file actions
223 lines (141 loc) · 5.32 KB
/
Copy pathclient.lua
File metadata and controls
223 lines (141 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
local _PlayerPedId, inWork, listening, write, cam
local buffer = ''
local params = {}
Citizen.CreateThread(function()
_PlayerPedId = PlayerPedId()
local x, y, z, coord, camX, camY, camZ
local forward = {}
local hfov, vfov = 90.0, 50.0
local camZDist, camDist1, camDist2, headingMod
params = {
xDistance = 7.5,
yDistance = 5.0,
xLine = 5,
yLine = 3,
heading = GetEntityHeading(_PlayerPedId)
}
while true do
Citizen.Wait(0)
if inWork then
coord = GetEntityCoords(_PlayerPedId)
forward.x = math.sin(math.rad(params.heading))
forward.y = math.cos(math.rad(params.heading))
camX = coord.x - forward.x * params.xDistance * (params.xLine - 1) / 2 + forward.y * params.yDistance * (params.yLine - 1) / 2
camY = coord.y + forward.y * params.xDistance * (params.xLine - 1) / 2 + forward.x * params.yDistance * (params.yLine - 1) / 2
if params.xDistance * params.xLine > params.yDistance * params.yLine then
camDist1 = params.xLine / 2 * params.xDistance / math.tan(math.rad(hfov / 2))
camDist2 = params.yLine / 2 * params.yDistance / math.tan(math.rad(vfov / 2))
headingMod = 90.0
else
camDist1 = params.xLine / 2 * params.xDistance / math.tan(math.rad(vfov / 2))
camDist2 = params.yLine / 2 * params.yDistance / math.tan(math.rad(hfov / 2))
headingMod = 0.0
end
camZDist = camDist1 > camDist2 and camDist1 or camDist2
if camZDist < 2.0 then camZDist = 2.0 end
if cam then
SetCamCoord(cam, camX, camY, camZ + camZDist )
SetCamRot(cam, -90.0, 0.0, params.heading + headingMod, 2)
end
camZ = 0
for i = 1, params.xLine do
x = coord.x - forward.x * (i - 1) * params.xDistance
y = coord.y + forward.y * (i - 1) * params.xDistance
for j = 1, params.yLine do
_, z = GetGroundZFor_3dCoord_2(x, y, coord.z + 20.0, 0)
if camZ < z then camZ = z end
if write then
buffer = buffer .. ("vector3(%s, %s, %s),\n"):format(FormatCoord(x), FormatCoord(y), FormatCoord(z + 1))
end
DrawMarker(28, x, y, z + 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 255, 255, 0, 255, false, false, 2, false, false, false, false)
x = x + forward.y * params.yDistance
y = y + forward.x * params.yDistance
end
end
if write then
TriggerServerEvent('sowing:saveCoord', buffer)
SendNUIMessage({
subject = 'SAVE_TO_CLIPBOARD',
data = buffer
})
write = nil
buffer = ''
end
else
Citizen.Wait(1000)
end
end
end)
RegisterCommand('sowing', function(source, args, raw)
_PlayerPedId = PlayerPedId()
if inWork then
inWork = false
listening = false
SetNuiFocus(false, false)
SendNUIMessage({
subject = 'CLOSE'
})
else
inWork = true
listening = true
SendNUIMessage({
subject = 'OPEN',
data = params
})
TriggerEvent("eco_sowing:listening")
end
end)
AddEventHandler('eco_sowing:control', function()
_PlayerPedId = PlayerPedId()
inWork = true
SetNuiFocus(true, true)
SendNUIMessage({
subject = 'OPEN',
data = params
})
if not cam then
local curCam = GetRenderingCam()
local camPos = GetCamCoord(curCam)
cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camPos.x, camPos.y, camPos.z + 100.0, -90.0, 0.0, params.heading, 60.00, false, 0)
SetCamActive(cam, true)
RenderScriptCams(true, 1, 1000, 1, 1);
SetCamActiveWithInterp(curCam, cam, 1, 1000, 1)
end
end)
AddEventHandler('eco_sowing:listening', function()
Citizen.CreateThread(function()
while listening do
Citizen.Wait(0)
if IsControlJustPressed(0, 36) then -- LEFT CTRL
TriggerEvent("eco_sowing:control")
listening = false
end
end
end)
end)
RegisterNUICallback('paramSet', function(data, cb)
params[data.key] = tonumber(data.value) + 0.0
cb('ok')
end)
RegisterNUICallback('saveCoords', function(data, cb)
write = true
cb('ok')
end)
RegisterNUICallback('exit', function(data, cb)
SetCamActive(cam, false)
DestroyCam(cam, true)
RenderScriptCams(false, 1, 1000, 1, 1);
cam = nil
SetNuiFocus(false, false)
if data.inWork == 'off' then
inWork = false
else
listening = true
TriggerEvent("eco_sowing:listening")
end
cb('ok')
end)
FormatCoord = function(coord)
if coord == nil then return "unknown" end
return tonumber(string.format("%.2f", coord))
end