forked from R1CKY6/Ricky-VinewoodSign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
131 lines (120 loc) · 3.84 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
local ESX = nil
local QBCore = nil
local FrameworkFound = nil
local nuiOpen = false
local modelCreated = {}
LoadFramework = function()
if Config.Framework == 'esx' then
ESX = exports['es_extended']:getSharedObject()
FrameworkFound = 'esx'
elseif Config.Framework == 'qbcore' then
QBCore = exports["qb-core"]:GetCoreObject()
FrameworkFound = 'qbcore'
elseif Config.Framework == 'autodetect' then
if GetResourceState('es_extended') == 'started' then
ESX = exports['es_extended']:getSharedObject()
FrameworkFound = 'esx'
elseif GetResourceState('qb-core') == 'started' then
QBCore = exports["qb-core"]:GetCoreObject()
FrameworkFound = 'qbcore'
else
FrameworkFound = 'standalone'
end
elseif Config.Framework == 'standalone' then
FrameworkFound = 'standalone'
end
end
Citizen.CreateThread(function()
LoadFramework()
TriggerServerEvent('ricky-vinewood:loadText')
end)
RegisterNetEvent('ricky-vinewood:openNui')
AddEventHandler('ricky-vinewood:openNui', function(text, color)
nuiOpen = true
SetNuiFocus(true, true)
SendNUIMessage({
type = "SET_LOCALES",
locales = Config.Locales
})
SendNUIMessage({
type = "OPEN",
text = text,
color = color
})
end)
RegisterNUICallback('saveText', function(data)
TriggerServerEvent('ricky-vinewood:saveText', data)
end)
RegisterNUICallback('close', function(data)
nuiOpen = false
SetNuiFocus(false, false)
end)
RegisterNetEvent('ricky-vinewood:saveText')
AddEventHandler('ricky-vinewood:saveText', function(data)
UpdateMap(data)
if nuiOpen then
SendNUIMessage({
type = "UPDATE",
text = data[1],
color = data[2]
})
end
end)
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
for k, v in pairs(modelCreated) do
DeleteEntity(v)
end
end
end)
hexToRgb = function(hex)
hex = hex:gsub("#","")
return {
r = tonumber("0x"..hex:sub(1,2)),
g = tonumber("0x"..hex:sub(3,4)),
b = tonumber("0x"..hex:sub(5,6))
}
end
UpdateMap = function(data)
for k, v in pairs(modelCreated) do
DeleteEntity(v)
end
modelCreated = {}
if not data then return end
local completeText = data[1]
if not completeText then return end
for i=1, #completeText, 1 do
if i > 8 then
return
end
local string = completeText:sub(i, i)
local model = string
local coords = Config.Coords[i].coordinate
local heading = Config.Coords[i].heading
model = model
if model ~= " " then
RequestModel(model)
while not HasModelLoaded(model) do
Wait(1)
end
local obj = CreateObject(model, coords, false, false, false)
SetEntityHeading(obj, heading)
table.insert(modelCreated, obj)
SetColorModel(model, "techdevontop", hexToRgb(data[2]))
end
end
end
SetColorModel = function(model, textureName, colorRgb)
local txd = 'txd_vinewood_sign'
local txn = 'txn_vinewood_sign'
local dict = CreateRuntimeTxd(txd)
local texture = CreateRuntimeTexture(dict, txn, 4, 4)
local resolution = GetTextureResolution(txd, txn)
if(colorRgb.r == 255 and colorRgb.g == 255 and colorRgb.b == 255) then
RemoveReplaceTexture("mainTexture", textureName)
else
SetRuntimeTexturePixel(texture, 0, 0, colorRgb.r, colorRgb.g, colorRgb.b, 255)
CommitRuntimeTexture(texture)
AddReplaceTexture("mainTexture", textureName, txd, txn)
end
end