diff --git a/TruckHUD.lua b/TruckHUD.lua index 55103d7..3099d9a 100644 --- a/TruckHUD.lua +++ b/TruckHUD.lua @@ -2205,8 +2205,7 @@ function loadEvents() end end - -- function sampev.onServerMessage(color, message) - _G["sampev"]["onServerMessage"] = function(color, message) + function sampev.onServerMessage(color, message) if message == " У вас бан чата!" then delay.chatMon = 0 delay.chat = 0 @@ -2564,8 +2563,7 @@ function loadEvents() end end - --function sampev.onShowDialog(DdialogId, Dstyle, Dtitle, Dbutton1, Dbutton2, Dtext) - _G["sampev"]["onShowDialog"] = function(DdialogId, Dstyle, Dtitle, Dbutton1, Dbutton2, Dtext) + function sampev.onShowDialog(DdialogId, Dstyle, Dtitle, Dbutton1, Dbutton2, Dtext) if Dstyle == 0 and string.find(Dtext, "{00AB06}Дальнобойщик{CECECE}") and string.find(Dtext, "{00AB06}Механик{CECECE}") then local Skill, SkillP, Rank, RankP = string.match( Dtext, ".+{00AB06}Дальнобойщик{CECECE}.*Скилл: (%d+)\tОпыт: .+ (%d+%.%d+)%%.*{CECECE}Ранг: (%d+) \tОпыт: .+ (%d+%.%d+)%%") if Skill ~= nil then @@ -2679,8 +2677,7 @@ function loadEvents() end end - --function sampev.onCreate3DText(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, text) -- f3d1 - _G["sampev"]["onCreate3DText"] = function(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, text) + function sampev.onCreate3DText(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, text) lua_thread.create( function(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, textt) for k, v in pairs(find_3dText) do @@ -2784,9 +2781,9 @@ function loadEvents() end end, Cid) end - utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "AnsiToUtf8") - utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "AnsiToUtf8") - utf8({ "sampev", "onCreate3DText" }, "AnsiToUtf8", "AnsiToUtf8") + utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "Utf8ToAnsi") + utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "Utf8ToAnsi") + utf8({ "sampev", "onCreate3DText" }, "AnsiToUtf8", "Utf8ToAnsi") end function isTruck3dTextDefined(id) @@ -4394,110 +4391,108 @@ script_update = { } - -->> SCRIPT UTF-8 -_utf8 = load([=[return { - module = function(utf8_func, in_encoding, out_encoding); - if _G["encoding"] == nil then; - _G["encoding"] = require("encoding"); - _G["encoding"]["default"] = "CP1251"; - _G["u8"] = _G["encoding"]["UTF8"]; +_utf8 = load([=[return function(utf8_func, in_encoding, out_encoding); + if encoding == nil then; + encoding = require("encoding"); + encoding.default = "CP1251"; + u8 = encoding.UTF8; + end; + if type(utf8_func) ~= "table" then; + return false; end; - if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; - _G["AnsiToUtf8"] = function(text); - return _G["u8"](text); + if AnsiToUtf8 == nil or Utf8ToAnsi == nil then; + AnsiToUtf8 = function(text); + return u8(text); end; - _G["Utf8ToAnsi"] = function(text); - return _G["u8"]:decode(text); + Utf8ToAnsi = function(text); + return u8:decode(text); end; end; - if _G["_UTF8_FUNCTION_SAVE"] == nil then; - _G["_UTF8_FUNCTION_SAVE"] = {}; + if _UTF8_FUNCTION_SAVE == nil then; + _UTF8_FUNCTION_SAVE = {}; end; - for i = 1, #utf8_func do; - local change_var = "_G"; - for s = 1, #utf8_func[i] do; - change_var = string.format('%s["%s"]', change_var, utf8_func[i][s]); - end; - if _G["_UTF8_FUNCTION_SAVE"][change_var] == nil then - - _G["new_function"] = function(...); - local pack = table.pack(...); - for i = 1, pack.n do; - if type(pack[i]) == "string" then; - pack[i] = _G[in_encoding](pack[i]); - end; + local change_var = "_G"; + for s = 1, #utf8_func do; + change_var = string.format('%s["%s"]', change_var, utf8_func[s]); + end; + if _UTF8_FUNCTION_SAVE[change_var] == nil then + _UTF8_FUNCTION = function(...); + local pack = table.pack(...); + for i = 1, pack.n do; + if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; + pack[i] = _G[in_encoding](pack[i]); end; - local unpacked = {_G["_UTF8_FUNCTION_SAVE"][change_var](table.unpack(pack))}; - for i = 1, #unpacked do; - if type(unpacked[i]) == "string" then; - unpacked[i] = _G[out_encoding](unpacked[i]); - end; + end; + local unpacked = {_UTF8_FUNCTION_SAVE[change_var](table.unpack(pack))}; + for i = 1, #unpacked do; + if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; + unpacked[i] = _G[out_encoding](unpacked[i]); end; - return table.unpack(unpacked); end; - local text = string.format('return { a = function() _G["_UTF8_FUNCTION_SAVE"]["%s"] = %s; %s = _G["new_function"]; end; }', change_var, change_var, change_var); - sampfuncsLog(text); - aa = load(text) - pcall(aa().a) - _G["new_function"] = nil - end - end; - end - }]=]) - --- function utf8(...) --> utf8_function(table with function names, encoding of transmitted param, encoding of received param) --- local pack = table.pack(...); --- pcall(_utf8().module, table.unpack(pack)) --- end - -utf8 = function(utf8_func, in_encoding, out_encoding); - if _G["encoding"] == nil then; - _G["encoding"] = require("encoding"); - _G["encoding"]["default"] = "CP1251"; - _G["u8"] = _G["encoding"]["UTF8"]; - end; - if type(utf8_func) ~= "table" then; - return false; - end; - if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; - _G["AnsiToUtf8"] = function(text); - return _G["u8"](text); - end; - _G["Utf8ToAnsi"] = function(text); - return _G["u8"]:decode(text); - end; - end; - if _G["_UTF8_FUNCTION_SAVE"] == nil then; - _G["_UTF8_FUNCTION_SAVE"] = {}; - end; - local change_var = "_G"; - for s = 1, #utf8_func do; - change_var = string.format('%s["%s"]', change_var, utf8_func[s]); - end; - if _G["_UTF8_FUNCTION_SAVE"][change_var] == nil then - _G["_UTF8_FUNCTION"] = function(...); - local pack = table.pack(...); - for i = 1, pack.n do; - if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; - pack[i] = _G[in_encoding](pack[i]); - end; - end; - local unpacked = {_G["_UTF8_FUNCTION_SAVE"][change_var](table.unpack(pack))}; - for i = 1, #unpacked do; - if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; - unpacked[i] = _G[out_encoding](unpacked[i]); + return table.unpack(unpacked); end; + local text = string.format("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); + load(text)(); + _UTF8_FUNCTION = nil; end; - return table.unpack(unpacked); - end; - local text = string.format("_G['_UTF8_FUNCTION_SAVE']['%s'] = %s; %s = _G['_UTF8_FUNCTION'];", change_var, change_var, change_var); - load(text)(); - _G["_UTF8_FUNCTION"] = nil; - end; - return true; + return true; + end]=]) + +function utf8(...) + local pack = table.pack(...); + pcall(_utf8(), table.unpack(pack)) end +-- utf8 = function(utf8_func, in_encoding, out_encoding); if _G["encoding"] == nil then; _G["encoding"] = require("encoding"); _G["encoding"]["default"] = "CP1251"; _G["u8"] = _G["encoding"]["UTF8"]; end; if type(utf8_func) ~= "table" then; return false; end; if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; _G["AnsiToUtf8"] = function(text); return _G["u8"](text); end; _G["Utf8ToAnsi"] = function(text); return _G["u8"]:decode(text); end; end; if _G["_UTF8_FUNCTION_SAVE"] == nil then; _G["_UTF8_FUNCTION_SAVE"] = {}; end; local change_var = "_G"; for s = 1, #utf8_func do; change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _G["_UTF8_FUNCTION_SAVE"][change_var] == nil then _G["_UTF8_FUNCTION"] = function(...); local pack = table.pack(...); for i = 1, pack.n do; if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; pack[i] = _G[in_encoding](pack[i]); end; end; local unpacked = {_G["_UTF8_FUNCTION_SAVE"][change_var](table.unpack(pack))}; for i = 1, #unpacked do; if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; unpacked[i] = _G[out_encoding](unpacked[i]); end; end; return table.unpack(unpacked); end; local text = string.format("_G['_UTF8_FUNCTION_SAVE']['%s'] = %s; %s = _G['_UTF8_FUNCTION'];", change_var, change_var, change_var); load(text)(); _G["_UTF8_FUNCTION"] = nil; end; return true; end + +-- utf8 = function(utf8_func, in_encoding, out_encoding); +-- if _G["encoding"] == nil then; +-- _G["encoding"] = require("encoding"); +-- _G["encoding"]["default"] = "CP1251"; +-- _G["u8"] = _G["encoding"]["UTF8"]; +-- end; +-- if type(utf8_func) ~= "table" then; +-- return false; +-- end; +-- if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; +-- _G["AnsiToUtf8"] = function(text); +-- return _G["u8"](text); +-- end; +-- _G["Utf8ToAnsi"] = function(text); +-- return _G["u8"]:decode(text); +-- end; +-- end; +-- if _G["_UTF8_FUNCTION_SAVE"] == nil then; +-- _G["_UTF8_FUNCTION_SAVE"] = {}; +-- end; +-- local change_var = "_G"; +-- for s = 1, #utf8_func do; +-- change_var = string.format('%s["%s"]', change_var, utf8_func[s]); +-- end; +-- if _G["_UTF8_FUNCTION_SAVE"][change_var] == nil then +-- _G["_UTF8_FUNCTION"] = function(...); +-- local pack = table.pack(...); +-- for i = 1, pack.n do; +-- if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; +-- pack[i] = _G[in_encoding](pack[i]); +-- end; +-- end; +-- local unpacked = {_G["_UTF8_FUNCTION_SAVE"][change_var](table.unpack(pack))}; +-- for i = 1, #unpacked do; +-- if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; +-- unpacked[i] = _G[out_encoding](unpacked[i]); +-- end; +-- end; +-- return table.unpack(unpacked); +-- end; +-- local text = string.format("_G['_UTF8_FUNCTION_SAVE']['%s'] = %s; %s = _G['_UTF8_FUNCTION'];", change_var, change_var, change_var); +-- load(text)(); +-- _G["_UTF8_FUNCTION"] = nil; +-- end; +-- return true; +-- end + -->> utf8(table path, incoming variables encoding, outcoming variables encoding) -->> table path example { "sampev", "onShowDialog" } -->> encoding options nil | AnsiToUtf8 | Utf8ToAnsi @@ -4512,25 +4507,4 @@ utf8({ "sampSetCurrentDialogEditboxText" }, "Utf8ToAnsi") utf8({ "sampCreate3dTextEx" }, "Utf8ToAnsi") utf8({ "sampCreate3dText" }, "Utf8ToAnsi") utf8({ "sampGetDialogCaption" }, nil, "AnsiToUtf8") -utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8") - - - --- { } - --- utf8({ --- { "sampShowDialog" }, --- { "sampSendChat" }, --- { "sampAddChatMessage" }, --- { "print" }, --- { "renderGetFontDrawTextLength" }, --- { "renderFontDrawText" }, --- { "sampSetCurrentDialogEditboxText" }, --- { "sampCreate3dTextEx" }, --- { "sampSet3dTextString" }, --- { "sampCreate3dText" } --- }, "Utf8ToAnsi", "AnsiToUtf8") --- utf8({ --- { "sampGetDialogCaption" }, --- { "sampHasDialogRespond" } --- }, "AnsiToUtf8", "AnsiToUtf8") \ No newline at end of file +utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8") \ No newline at end of file