forked from bulva2/strin_jobform
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient.lua
More file actions
137 lines (111 loc) · 3.58 KB
/
client.lua
File metadata and controls
137 lines (111 loc) · 3.58 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
local QBCore = exports['qb-core']:GetCoreObject()
display = false
maxLength = 800
minLength = 30
Citizen.CreateThread(function()
while QBCore.Functions.GetPlayerData().job == nil do
Citizen.Wait(1000)
end
QBCore.PlayerData = QBCore.Functions.GetPlayerData()
Citizen.Wait(1000)
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function(xPlayer)
QBCore.PlayerData = xPlayer
end)
RegisterNetEvent('QBCore:Client:OnJobUptade')
AddEventHandler('QBCore:Client:OnJobUptade', function(job)
QBCore.PlayerData.job = job
end)
Citizen.CreateThread(function()
local Player = QBCore.Functions.GetPlayerData(source)
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local coords = GetEntityCoords(ped)
local distanceToForm = 30000
for k, v in pairs(FORMS) do
local distance = #(coords - v.pos)
if distance < distanceToForm then
distanceToForm = distance
end
if not display then
if distance < 1.0 then
DrawText3D(v.pos, '~g~[E]~w~ '..v.label)
if IsControlJustReleased(0, 38) then
SetDisplay(true, k, v.label)
end
end
end
end
if distanceToForm > LOAD_DISTANCE then
Citizen.Wait(2000)
end
end
end)
RegisterNUICallback("send_form", function(data)
SetDisplay(false)
if data ~= nil then
local wayjocLength = string.len(data.wayjoc)
local tuabyLength = string.len(data.tuaby)
if (wayjocLength < minLength) or (tuabyLength < minLength) then
QBCore.Functions.Notify('Your form is too short'..minLength..' min. characters!', "error")
else
if (wayjocLength > maxLength) or (tuabyLength > maxLength) then
QBCore.Functions.Notify('Your form is too long - '..maxLength..' max. characters!', "error")
else
sendForm(data)
QBCore.Functions.Notify('Your form has been sent to - '..data.job)
end
end
else
QBCore.Functions.Notify('Your form is empty!', "error")
end
end)
RegisterNUICallback("exit_form", function(data)
if data.error ~= nil then
QBCore.Functions.Notify(data.error)
end
SetDisplay(false)
end)
function SetDisplay(bool, form_job, form_label)
display = bool
SetNuiFocus(bool, bool)
local Player = QBCore.Functions.GetPlayerData()
Citizen.Wait(10)
local firstname = Player.charinfo.firstname
local lastname = Player.charinfo.lastname
local phone = Player.charinfo.phone
while phone == nil do
Citizen.Wait(100)
end
SendNUIMessage({
type = "ui",
status = bool,
job = form_job,
label = form_label,
player = {
firstname = firstname,
lastname = lastname,
phone = phone
}
})
end
function sendForm(data)
TriggerServerEvent('strin_jobform:sendWebhook', data)
end
function DrawText3D(coords, text)
local onScreen,_x,_y=World3dToScreen2d(coords.x,coords.y,coords.z)
SetTextScale(DRAW_TEXT_SCALE.x, DRAW_TEXT_SCALE.y)
SetTextFont(DRAW_TEXT_FONT)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
DrawText(_x,_y)
if DRAW_RECT then
local factor = (string.len(text)) / 200
DrawRect(_x,_y+0.0105, 0.015+ factor, 0.035, 44, 44, 44, 100)
end
end