[Lua] royal-source

  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
require("moonloader")
local hash = require("md5")
local imgui = require("imgui")
local encoding = require("encoding")
local sampev = require("lib.samp.events")
script_version("1.0")
script_version_number(1)
script_name("Royal Assistant")
script_authors("CodeX Company")
script_url("https://vk.com/royal_codex")
script_description("Royal Assistant - вспомогательна¤ программа, предназначенна¤ дл¤ игроков Diamond Role Play.")
-- Ќастройка кодировок
local u8 = encoding.UTF8
encoding.default = "CP1251"
local start = 1
local width, heigth = getScreenResolution()
local cards =
{
[1] =
{
["name"] = "-",
[1] = 0,
[2] = 0,
[3] = 0,
[4] = 0,
[5] = 0
},
[2] =
{
["name"] = "-",
[1] = 0,
[2] = 0,
[3] = 0,
[4] = 0,
[5] = 0
}
}
function hash.md5(text)
text = hash.sum(text)
return (string.gsub(text, ".", function (c)
return string.format("%02x", string.byte(c))
end))
end
function main()
LoadStyles()
if not isSampLoaded() or not isSampfuncsLoaded() then error("Royal Assistant needs SA:MP and SAMPFUNCS!") end
while not isSampAvailable() or sampGetGamestate() ~= 3 do wait(0) end
sampAddChatMessage("• {FFD700}[Royal Assistant] {FFFFFF}Script loaded | Official site: {CCCCCC}vk.com/royal_codex", -1)
local file = io.open("moonloader\\Royal Assistant")
if file and file:read("*a") == GetPlayerHash() then
sampAddChatMessage("• {FFD700}[Royal Assistant] {FFFFFF}Активация прошла успешно, приятного пользования", -1)
my_nick = sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
my_server = string.format("%s:%i", sampGetCurrentServerAddress())
imgui.Process = true
io.close(file)
else
sampAddChatMessage("• {FFD700}[Royal Assistant] {FFFFFF}Используйте команду /access для активации", -1)
sampRegisterChatCommand("access", function(params)
if params:len() > 0 then
if GetPlayerHash() == params then
local file = io.open("moonloader\\Royal Assistant", "w")
if file then
sampAddChatMessage("• {FFD700}[Royal Assistant] {FFFFFF}Активация прошла успешно, приятного пользования", -1)
my_nick = sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
my_server = string.format("%s:%i", sampGetCurrentServerAddress())
sampUnregisterChatCommand("access")
imgui.Process = true
file:write(params)
io.close(file)
else sampAddChatMessage("• {F31D2F}[Ошибка] {FFFFFF}Произошла ошибка при попытке активировать, обратитесь в службу поддержки", -1) end
else sampAddChatMessage("• {F31D2F}[Ошибка] {FFFFFF}Данный ключ активации недействителен", -1) end
else sampAddChatMessage("• {EEE657}[Подсказка] {FFFFFF}Используйте: /access [ключ активации]", -1) end
end)
end
while true do
wait(0)
if imgui.Process and my_nick ~= sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))) then
sampAddChatMessage("• {FFD700}[Royal Assistant] {FFFFFF}Происходит прекращение работы из-за смены игрового ника", -1)
thisScript():unload()
elseif imgui.Process and my_server ~= string.format("%s:%i", sampGetCurrentServerAddress()) then
sampAddChatMessage("• {FFD700}[Royal Assistant] {FFFFFF}Происходит прекращение работы из-за смены сервера", -1)
thisScript():unload()
end
end
end
function sampev.onShowTextDraw(id, data)
if imgui.Process and IsPlayerInCasino() then
if data.text:find("^Market$") then start = id end
if id >= start + 10 and id <= start + 14 then cards[1][id - start - 9] = GetCardValue(data.text:gsub("LD_Card:cd", ""))
elseif id >= start + 15 and id <= start + 19 then cards[2][id - start - 14] = GetCardValue(data.text:gsub("LD_Card:cd", ""))
elseif id == start + 1 then cards[1]["name"] = data.text
elseif id == start + 2 then cards[2]["name"] = data.text end
end
end
function imgui.OnDrawFrame()
imgui.ShowCursor = false
imgui.SetMouseCursor(-1)
if IsPlayerInCasino() then
imgui.SetNextWindowSize(imgui.ImVec2(300, 250), imgui.Cond.FirstUseEver)
imgui.SetNextWindowPos(imgui.ImVec2(width - 310, heigth / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0, 0.5))
imgui.Begin("Royal Assistant", _, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize)
imgui.Columns(2)
local score = {0, 0}
imgui.SetCursorPosX((imgui.GetColumnWidth(-1) - imgui.CalcTextSize(u8(cards[1]["name"])).x) / 2)
imgui.Text(u8(cards[1]["name"]))
imgui.NextColumn()
imgui.SetCursorPosX(imgui.GetColumnWidth(-1) + (imgui.GetColumnWidth(-1) - imgui.CalcTextSize(u8(cards[2]["name"])).x) / 2)
imgui.Text(u8(cards[2]["name"]))
imgui.Separator()
imgui.NextColumn()
for k, v in ipairs(cards[1]) do
imgui.SetCursorPosX((imgui.GetColumnWidth(-1) - imgui.CalcTextSize(tostring(v)).x) / 2)
score[1] = score[1] + v
imgui.Text(tostring(v))
end
imgui.NextColumn()
for k, v in ipairs(cards[2]) do
imgui.SetCursorPosX(imgui.GetColumnWidth(-1) + (imgui.GetColumnWidth(-1) - imgui.CalcTextSize(tostring(v)).x) / 2)
score[2] = score[2] + v
imgui.Text(tostring(v))
end
imgui.Separator()
imgui.Columns()
imgui.SetCursorPosX(133.5)
imgui.Text(u8"Итого")
imgui.Separator()
imgui.Columns(2)
imgui.SetCursorPosX((imgui.GetColumnWidth(-1) - imgui.CalcTextSize(tostring(score[1])).x) / 2)
imgui.Text(tostring(score[1]))
imgui.NextColumn()
imgui.SetCursorPosX(imgui.GetColumnWidth(-1) + (imgui.GetColumnWidth(-1) - imgui.CalcTextSize(tostring(score[2])).x) / 2)
imgui.Text(tostring(score[2]))
imgui.Separator()
imgui.Columns()
imgui.SetCursorPosX(85)
imgui.Text(u8"Шанс успешной карты")
imgui.Separator()
imgui.Columns(2)
imgui.SetCursorPosX((imgui.GetColumnWidth(-1) - imgui.CalcTextSize(string.format("%.1f%s", GetChanceVictory(score[1]), "%")).x) / 2)
imgui.Text(string.format("%.1f%s", GetChanceVictory(score[1]), "%"))
imgui.NextColumn()
imgui.SetCursorPosX(imgui.GetColumnWidth(-1) + (imgui.GetColumnWidth(-1) - imgui.CalcTextSize(string.format("%.1f%s", GetChanceVictory(score[2]), "%")).x) / 2)
imgui.Text(string.format("%.1f%s", GetChanceVictory(score[2]), "%"))
imgui.Columns()
imgui.End()
end
end
function GetPlayerHash()
local hash = hash.md5(string.format("%s:%s:%i", sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))), sampGetCurrentServerAddress())):reverse()
return string.format("%s-%s-%s-%s", hash:sub(0, 4), hash:sub(9, 12), hash:sub(17, 20), hash:sub(25, 28)):upper()
end
function IsPlayerInCasino()
return isCharInArea2d(PLAYER_PED, 1122.2897, 88.4730, 1102.9799, 127.3168) and getActiveInterior() == 10
end
function GetCardValue(text)
if text:find("^%d+") then
local number = tonumber(text:match("^(%d+)"))
if number == 11 then number = 2
elseif number == 12 then number = 3
elseif number == 13 then number = 4
elseif number == 1 then number = 11 end
return number
else return 0 end
end
function GetChanceVictory(value)
local result = 1
if value <= 10 then result = 0
elseif value <= 17 then result = 4 * (value - 10) / 52
elseif value <= 20 then result = (4 * (value - 10) + 4 * (value - 17)) / 52 end
return (1 - result) * 100
end
function LoadStyles()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
style.GrabMinSize = 8
style.GrabRounding = 1
style.FrameRounding = 2
style.ScrollbarSize = 13
style.WindowRounding = 10
style.ScrollbarRounding = 0
style.ChildWindowRounding = 2
style.ItemSpacing = imgui.ImVec2(5, 5)
style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
colors[imgui.Col.Text] = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
colors[imgui.Col.TextDisabled] = imgui.ImVec4(0.50, 0.50, 0.50, 1.00)
colors[imgui.Col.WindowBg] = imgui.ImVec4(0.06, 0.06, 0.06, 0.75)
colors[imgui.Col.ChildWindowBg] = imgui.ImVec4(1.00, 1.00, 1.00, 0.00)
colors[imgui.Col.PopupBg] = imgui.ImVec4(0.08, 0.08, 0.08, 0.94)
colors[imgui.Col.ComboBg] = imgui.ImVec4(0.08, 0.08, 0.08, 0.94)
colors[imgui.Col.Border] = imgui.ImVec4(0.43, 0.43, 0.50, 0.50)
colors[imgui.Col.BorderShadow] = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
colors[imgui.Col.FrameBg] = imgui.ImVec4(0.16, 0.29, 0.48, 0.54)
colors[imgui.Col.FrameBgHovered] = imgui.ImVec4(0.26, 0.59, 0.98, 0.40)
colors[imgui.Col.FrameBgActive] = imgui.ImVec4(0.26, 0.59, 0.98, 0.67)
colors[imgui.Col.TitleBg] = imgui.ImVec4(0.80, 0.60, 0.00, 0.80)
colors[imgui.Col.TitleBgActive] = imgui.ImVec4(0.80, 0.60, 0.00, 0.80)
colors[imgui.Col.TitleBgCollapsed] = imgui.ImVec4(0.80, 0.60, 0.00, 0.80)
colors[imgui.Col.MenuBarBg] = imgui.ImVec4(0.14, 0.14, 0.14, 1.00)
colors[imgui.Col.ScrollbarBg] = imgui.ImVec4(0.02, 0.02, 0.02, 0.53)
colors[imgui.Col.ScrollbarGrab] = imgui.ImVec4(0.31, 0.31, 0.31, 1.00)
colors[imgui.Col.ScrollbarGrabHovered] = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
colors[imgui.Col.ScrollbarGrabActive] = imgui.ImVec4(0.51, 0.51, 0.51, 1.00)
colors[imgui.Col.CheckMark] = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
colors[imgui.Col.SliderGrab] = imgui.ImVec4(0.24, 0.52, 0.88, 1.00)
colors[imgui.Col.SliderGrabActive] = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
colors[imgui.Col.Button] = imgui.ImVec4(0.26, 0.59, 0.98, 0.40)
colors[imgui.Col.ButtonHovered] = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
colors[imgui.Col.ButtonActive] = imgui.ImVec4(0.06, 0.53, 0.98, 1.00)
colors[imgui.Col.Header] = imgui.ImVec4(0.26, 0.59, 0.98, 0.31)
colors[imgui.Col.HeaderHovered] = imgui.ImVec4(0.26, 0.59, 0.98, 0.80)
colors[imgui.Col.HeaderActive] = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
colors[imgui.Col.Separator] = imgui.ImVec4(0.43, 0.43, 0.50, 0.50)
colors[imgui.Col.SeparatorHovered] = imgui.ImVec4(0.26, 0.59, 0.98, 0.78)
colors[imgui.Col.SeparatorActive] = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
colors[imgui.Col.ResizeGrip] = imgui.ImVec4(0.26, 0.59, 0.98, 0.25)
colors[imgui.Col.ResizeGripHovered] = imgui.ImVec4(0.26, 0.59, 0.98, 0.67)
colors[imgui.Col.ResizeGripActive] = imgui.ImVec4(0.26, 0.59, 0.98, 0.95)
colors[imgui.Col.CloseButton] = imgui.ImVec4(0.41, 0.41, 0.41, 0.50)
colors[imgui.Col.CloseButtonHovered] = imgui.ImVec4(0.98, 0.39, 0.36, 1.00)
colors[imgui.Col.CloseButtonActive] = imgui.ImVec4(0.98, 0.39, 0.36, 1.00)
colors[imgui.Col.PlotLines] = imgui.ImVec4(0.61, 0.61, 0.61, 1.00)
colors[imgui.Col.PlotLinesHovered] = imgui.ImVec4(1.00, 0.43, 0.35, 1.00)
colors[imgui.Col.PlotHistogram] = imgui.ImVec4(0.90, 0.70, 0.00, 1.00)
colors[imgui.Col.PlotHistogramHovered] = imgui.ImVec4(1.00, 0.60, 0.00, 1.00)
colors[imgui.Col.TextSelectedBg] = imgui.ImVec4(0.26, 0.59, 0.98, 0.35)
colors[imgui.Col.ModalWindowDarkening] = imgui.ImVec4(0.80, 0.80, 0.80, 0.35)
end