-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.lua
120 lines (116 loc) · 3.04 KB
/
utils.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
convertTable = {
{
gta = '~s~',
fivem = '^0',
html = 'white'
},
{
gta = '~r~',
fivem = '^1',
html = 'red'
},
{
gta = '~g~',
fivem = '^2',
html = 'green'
},
{
gta = '~y~',
fivem = '^3',
html = 'yellow'
},
{
gta = '~b~',
fivem = '^4',
html = 'blue'
},
{
gta = '~HUD_COLOUR_BLUELIGHT~',
fivem = '^5',
html = 'lightblue'
},
{
gta = '~p~',
fivem = '^6',
html = 'Purple'
},
{
gta = '~w~',
fivem = '^7',
html = 'white'
},
{
gta = '~o~',
fivem = '^8',
html = 'orange'
},
{
gta = '~c~',
fivem = '^9',
html = 'Grey'
},
{
gta = '~u~',
fivem = '^10',
html = 'black'
}
}
--- Convert color from one type to another
---@param message string message to be converted
---@param patternFrom string pattern to be replaced with patternTo : gta | fivem
---@param patternTo string pattern to get replaced with patternFrom : gta | fivem | html
function ConvertColor(message, patternFrom, patternTo)
-- this is one of the most scuffed scripts i wrote to this day -_-
if message then
local constMessage = message
if patternFrom then
if patternFrom ~= 'html' then
toHtmlData = {}
for i=1, #convertTable do
local colorsMetaData = convertTable[i]
if patternTo ~= 'html' then
-- look for GTA pattern ~r~
if string.find(message, colorsMetaData[patternFrom]) then
message = string.gsub(message, colorsMetaData[patternFrom], colorsMetaData[patternTo] or '')
end
-- look for Fivem pattern with escape or it will not work ^1
if string.find(message, '%'..colorsMetaData[patternFrom]) then
message = string.gsub(message, '%'..colorsMetaData[patternFrom], colorsMetaData[patternTo] or '')
end
else
-- look for GTA pattern ~r~
if string.find(message, colorsMetaData[patternFrom]) then
local first, last = message:find(colorsMetaData[patternFrom])
toHtmlData[#toHtmlData+1] = {startAt = first, endAt = last, color = colorsMetaData[patternTo]}
end
-- look for Fivem pattern with escape or it will not work ^1
--if string.find(message, '%'..colorsMetaData[patternFrom]) then
-- message = string.gsub(message, '%'..colorsMetaData[patternFrom], colorsMetaData[patternTo] or '')
--end
end
end
if #toHtmlData > 0 then
message = ''
for i=1, #toHtmlData do
local text = constMessage:sub(toHtmlData[i].endAt + 1, toHtmlData[i + 1] and (toHtmlData[i + 1].startAt -1) or constMessage:len())
local finalText = "<span style='color:"..toHtmlData[i].color..";'>"..text.."</span>"
message = message .. finalText
end
end
end
end
end
return message
end
function Draw2DText(content, x, y, font, colour, scale)
font = font or 0
colour = colour or {255, 255, 255}
scale = scale or .6
SetTextFont(font)
SetTextScale(scale, scale)
SetTextColour(colour[1], colour[2], colour[3], 255)
BeginTextCommandDisplayText('STRING')
SetTextOutline()
AddTextComponentSubstringPlayerName(content)
EndTextCommandDisplayText(x, y)
end