-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.lua
345 lines (308 loc) · 9.89 KB
/
client.lua
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
local menu = MenuV:CreateMenu('Prop & Animation Menu', 'BagusCodeStudio', 'topright', 255, 0, 0, 'size-100', 'default', 'menuv', 'animation_menu', 'native')
local find = string.find
local nuiOpen = false
local index, searching, currentProp, currentBone, xpos, ypos, zpos, xrot, yrot, zrot = 1, false, '', 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
local searchingString = ""
local spawnedProp = nil
function SendNotification(text)
BeginTextCommandThefeedPost('STRING')
AddTextComponentString(text)
EndTextCommandThefeedPostTicker(true, true)
end
RotationToDirection = function(rotation)
-- https://github.com/Risky-Shot/new_banking/blob/main/new_banking/client/client.lua
local adjustedRotation =
{
x = (math.pi / 180) * rotation.x,
y = (math.pi / 180) * rotation.y,
z = (math.pi / 180) * rotation.z
}
local direction =
{
x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
z = math.sin(adjustedRotation.x)
}
return direction
end
RayCastGamePlayCamera = function(distance)
-- https://github.com/Risky-Shot/new_banking/blob/main/new_banking/client/client.lua
local cameraRotation = GetGameplayCamRot()
local cameraCoord = GetGameplayCamCoord()
local direction = RotationToDirection(cameraRotation)
local destination =
{
x = cameraCoord.x + direction.x * distance,
y = cameraCoord.y + direction.y * distance,
z = cameraCoord.z + direction.z * distance
}
local a, b, c, d, e = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, PlayerPedId(), 0))
return b, c, e
end
function DrawText3D(x, y, z, text, scale, r, g, b, a)
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
local pX, pY, pZ = table.unpack(GetGameplayCamCoords())
local dist = #(vector3(pX,pY,pZ) - vector3(x,y,z))
local scale = (1/dist)*2
local fov = (1/GetGameplayCamFov())*100
local scale = scale * fov
if onScreen then
SetTextScale(0.0*scale, 0.50*scale)
SetTextFont(0)
SetTextProportional(1)
SetTextEntry("STRING")
SetTextCentre(true)
SetTextOutline()
SetTextColour(r, g, b, a)
AddTextComponentString(text)
DrawText(_x, _y)
end
end
local function GoUpInAnimations(deepness)
deepness = deepness or 1
if index == 1 then
index = #Animations
else
index = index - 1
end
if deepness <= #Animations then
if searching then
if not find(Animations[index][1]..Animations[index][2], searchingString) then
GoUpInAnimations(deepness + 1)
end
end
else
SendNotification("~r~~h~ERROR ~h~~w~: No results found. Your research parameter got deleted.")
searching = false
searchingString = ""
end
end
local function GoDownInAnimations(deepness)
deepness = deepness or 1
if index == #Animations then
index = 1
else
index = index + 1
end
if deepness <= #Animations then
if searching then
if not find(Animations[index][1]..Animations[index][2], searchingString) then
GoDownInAnimations(deepness + 1)
end
end
else
SendNotification("~r~~h~ERROR ~h~~w~: No results found. Your research parameters got deleted.")
searching = false
searchingString = ""
end
end
local function PlayAnimation()
local playerPed = PlayerPedId()
RequestAnimDict(Animations[index][1])
local j = 0
while not HasAnimDictLoaded(Animations[index][1]) and j <= 50 do
Citizen.Wait(100)
j = j + 1
end
if j >= 50 then
SendNotification("~r~~h~ERROR ~h~~w~: The animation dictionnary took too long to load.")
else
TaskPlayAnim(playerPed, Animations[index][1], Animations[index][2], 8.0, 1.0, -1, 1)
RemoveAnimDict(Animations[index][1])
end
end
local function SearchAnimation()
local data = exports.ox_inventory:Keyboard("Animation", {"Search string"})
if data then
searchingString = data[1]:lower()
searching = searchingString ~= "" and searchingString ~= nil
end
end
local function CancelAnimation()
ClearPedTasksImmediately(PlayerPedId())
end
function CopyClipboard()
local text = "local playerPed = PlayerPedId()\nlocal prop = GetHashKey('"..currentProp.."')\n"
text = text..'RequestModel(prop)\n'
text = text..'while not HasModelLoaded(prop) do\n'
text = text..'\tWait(100)\nRequestModel(prop)\nend\n'
text = text..'local spawnedProp = CreateObject(prop, GetEntityCoords(playerPed), true, true, true)\n'
text = text..'AttachEntityToEntity(spawnedProp, playerPed, GetPedBoneIndex(playerPed, '..currentBone..'), '..xpos..', '..ypos..', '..zpos..', '..xrot..', '..yrot..', '..zrot..', true, true, true, false, 1, true)\n'
text = text..'RequestAnimDict("'..Animations[index][1]..'")\n'
text = text..'while not HasAnimDictLoaded("'..Animations[index][1]..'") do\n'
text = text..'Wait(100)\nend\n'
text = text..'TaskPlayAnim(playerPed, "'..Animations[index][1]..'", "'..Animations[index][2]..'", 8.0, 1.0, -1, 49)\n'
text = text..'RemoveAnimDict("'..Animations[index][1]..'")'
SetNuiFocus(true, true)
SendNUIMessage({
action="copyClipboard",
data = {
text=text
}
})
Wait(150)
SetNuiFocus(false, false)
end
RegisterNUICallback('hideFrame', function(data, cb)
nuiOpen = false
SetNuiFocus(false, false)
cb(1)
end)
RegisterNUICallback('setPropData', function(data, cb)
currentProp = data.prop
currentBone = tonumber(data.bone)
xpos = tonumber(data.xpos)
ypos = tonumber(data.ypos)
zpos = tonumber(data.zpos)
xrot = tonumber(data.xrot)
yrot = tonumber(data.yrot)
zrot = tonumber(data.zrot)
if spawnedProp then
AttachEntityToEntity(spawnedProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), currentBone), xpos, ypos, zpos, xrot, yrot, zrot, true, true, true, false, 1, true)
end
UpdateInfoText()
cb(1)
end)
RegisterCommand('propstuck', function()
for k, v in pairs(GetGamePool('CObject')) do
if IsEntityAttachedToEntity(PlayerPedId(), v) then
SetEntityAsMissionEntity(v, true, true)
DeleteObject(v)
DeleteEntity(v)
end
end
end)
RegisterNUICallback('deleteProp', function(data, cb)
spawnedProp = nil
for k, v in pairs(GetGamePool('CObject')) do
if IsEntityAttachedToEntity(PlayerPedId(), v) then
SetEntityAsMissionEntity(v, true, true)
DeleteObject(v)
DeleteEntity(v)
end
end
cb(1)
end)
RegisterNUICallback('spawnProp', function(data,cb)
cb(1)
local prop = GetHashKey(data.prop)
RequestModel(prop)
while not HasModelLoaded(prop) do
Citizen.Wait(100)
RequestModel(prop)
end
spawnedProp = CreateObject(prop, GetEntityCoords(GetPlayerPed(-1)), true, true, true)
AttachEntityToEntity(spawnedProp, GetPlayerPed(-1), GetPedBoneIndex(GetPlayerPed(-1), currentBone), xpos, ypos, zpos, xrot, yrot, zrot, true, true, true, false, 1, true)
end)
RegisterNUICallback('setBone', function(data, cb)
currentBone = data.bone
cb(1)
end)
function toggleNUI()
if nuiOpen then
SetNuiFocus(false, false)
else
SetNuiFocus(true, true)
end
nuiOpen = not nuiOpen
end
RegisterCommand('propmenu', toggleNUI)
RegisterNUICallback('toggleNui', function(data,cb)
toggleNUI()
cb(1)
end)
RegisterNUICallback('getCurrentProp', function(data, cb)
cb({
prop=currentProp,
bone=currentBone,
xpos = tonumber(xpos),
ypos = tonumber(ypos),
zpos = tonumber(zpos),
xrot = tonumber(xrot),
yrot = tonumber(yrot),
zrot = tonumber(zrot),
})
end)
function UpdateInfoText()
SendNUIMessage({
action='setAnimPropData',
data={
animindex="Animation n°" .. index .. " :",
anim=Animations[index][1] .. " / " .. Animations[index][2],
prop=currentProp,
bone=currentBone
}
})
end
CreateThread(function()
while true do
InvalidateIdleCam()
InvalidateVehicleIdleCam()
Wait(5000)
end
end)
RegisterCommand('propanimation', function()
menu:ClearItems()
local propmenu = menu:AddButton({label='Prop Menu', description='Open Prop menu'})
local up = menu:AddButton({label= "Up", description="Go up in animations"})
local down = menu:AddButton({label= "Down", description="Go down in animations"})
local play = menu:AddButton({label= "Play Animation", description="Play animation"})
local search = menu:AddButton({label= "Search animation", description="Search for an animation"})
local cancel = menu:AddButton({label= "Cancel animation", description="Cancel or stop current animation"})
local copyinfo = menu:AddButton({label= "Copy Codes", description="Copy current animation and prop to clipboard"})
local closeinfo = menu:AddButton({label= "Close Info", description='Closes text information on screen'})
closeinfo:On('select', function()
SendNUIMessage({
action='displayInfo',
data=false
})
end)
propmenu:On('select', function()
SetNuiFocus(true, true)
nuiOpen = true
SendNUIMessage({
action='displayFrame',
data=true
})
menu:Close()
end)
up:On('select', function() GoUpInAnimations() UpdateInfoText() end)
down:On('select', function() GoDownInAnimations() UpdateInfoText() end)
play:On('select', function() PlayAnimation() end)
search:On('select', function() SearchAnimation() end)
cancel:On('select', function() CancelAnimation() end)
copyinfo:On('select', function()
CopyClipboard()
end)
menu:Open()
SendNUIMessage({
action='displayInfo',
data=true
})
menu:On('close', function()
isOpen = false
end)
end)
RegisterCommand('raycastView', function()
casting = true
exports['hud']:displayHelp('Tekan E untuk berhenti raycast')
while casting do
local _ped = PlayerPedId()
local _coords = GetEntityCoords(_ped)
local hit, coords, entity = RayCastGamePlayCamera(1000.0)
DrawLine(_coords, coords, 255, 0, 0, 255)
local text = 'x:'..coords.x..'\ny:'..coords.y..'\nz:'..coords.z
if hit == 1 and GetEntityType(entity) ~= 0 and IsEntityAnObject(entity) then
entity = GetEntityModel(entity)
end
text = text..'\nentity:'..entity
DrawText3D(coords.x, coords.y, coords.z, text, 0.10, 255, 255, 255, 255)
if IsControlJustReleased(0, 38) then
exports['hud']:closeHelp()
casting = false
elseif IsControlJustReleased(0,73) then
print(text)
end
Wait(5)
end
end)