-
Notifications
You must be signed in to change notification settings - Fork 15
/
client.lua
80 lines (64 loc) · 1.74 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
local open = false
local object = nil
local anim = Config.AnimDict
local prop = Config.Prop
local bone = Config.Bone
-- Utils
local function LoadDict(dict)
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Wait(100)
end
end
local function LoadProp(model)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(100)
end
end
-- Toggle tablet & animation
local function ToggleTablet(state)
local ped = PlayerPedId()
open = state
if state then
LoadDict(anim)
if not object then
LoadProp(prop)
local coords = GetEntityCoords(ped)
local hand = GetPedBoneIndex(ped, bone)
object = CreateObject(GetHashKey(prop), coords, 1, 1, 1)
AttachEntityToEntity(object, ped, hand, 0.0, 0.0, 0.03, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1)
end
if not IsEntityPlayingAnim(ped, anim, 'base', 3) then
TaskPlayAnim(ped, anim, 'base', 8.0, 1.0, -1, 49, 1.0, 0, 0, 0)
end
SetNuiFocus(state, state)
SendNUIMessage({
action = 'open'
})
else
DeleteEntity(object)
DetachEntity(object, 1, 1)
ClearPedTasks(ped)
SetNuiFocus(state, state)
SendNUIMessage({
action = 'close'
})
end
end
-- Event for server-side
RegisterNetEvent('redutzu-tablet:client:open', function()
ToggleTablet(true)
end)
-- Close
RegisterNUICallback('close', function(data, cb)
ToggleTablet(false)
cb('ok')
end)
-- Command / Keybind
RegisterCommand(Config.Command, function()
ToggleTablet(true)
end, false)
if Config.Keybind then
RegisterKeyMapping(Config.Command, Config.CommandDescription, 'KEYBOARD', Config.OpenKey)
end