From fdaa83fd14330e7dcd9e42788cc38b34ac044c48 Mon Sep 17 00:00:00 2001 From: rubin Date: Sat, 10 Dec 2022 23:22:28 +0300 Subject: [PATCH] add visual message load/unload --- TruckHUD.lua | 146 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 122 insertions(+), 24 deletions(-) diff --git a/TruckHUD.lua b/TruckHUD.lua index 833c60e..e005a54 100755 --- a/TruckHUD.lua +++ b/TruckHUD.lua @@ -2,6 +2,8 @@ script_name("TruckHUD") script_author("Serhiy_Rubin") script_version("2209011") +local inspect = require("inspect") + local inicfg = require "inicfg" local dlstatus = require("moonloader").download_status local vkeys = require "lib.vkeys" @@ -140,6 +142,17 @@ location_pos = { ["Порт СФ"] = {x = -1731.5022, y = 118.8936, z = 3.5547}, ["Аренда"] = {x = 2239.8333, y = 2779.6016, z = 10.8203} } +location_keys = { + ["n1"] = {x = 256.02127075195, y = 1414.8492431641, z = 10.232398033142, }, + ["y1"] = {x = 832.10766601563, y = 864.03668212891, z = 11.643839836121}, + ["l1"] = {x = -448.91455078125, y = -65.951385498047, z = 58.959014892578}, + ["n2"] = {x = -1046.7521972656, y = -670.66937255859, z = 31.885597229004}, + ["y2"] = {x = -2913.8544921875, y = -1377.0952148438, z = 10.762256622314}, + ["l2"] = {x = -1978.8649902344, y = -2434.9421386719, z = 30.192840576172}, + ["ls"] = {x = 2507.02, y = -2234.05, z = 13.55}, + ["sf"] = {x = -1731.5022, y = 118.8936, z = 3.5547} +} +cargo_replace = { "n", "y", "l" } binder_mode_sms = false @@ -2780,23 +2793,25 @@ function loadEvents() end function sampev.onRemove3DTextLabel(Cid) -- f3d2 - if id_3D_text == Cid then - id_3D_text = msk_timestamp - load_location = false - unload_location = false - current_warehouse = "none" - end - say("remove 3d text "..Cid) - local result, key = isTruck3dTextDefined(Cid) - if result then - for i = 1, #key do - --prices_3dtext_id[key[i]] = -1 - prices_3dtext_id[key[i]] = nil - prices_3dtext[key[i]] = 0 - - say("Удалено "..key[i]) - end - end + lua_thread.create(function(Cid) + if id_3D_text == Cid then + id_3D_text = msk_timestamp + load_location = false + unload_location = false + current_warehouse = "none" + end + say("remove 3d text "..Cid) + local result, key = isTruck3dTextDefined(Cid) + if result then + for i = 1, #key do + --prices_3dtext_id[key[i]] = -1 + prices_3dtext_id[key[i]] = nil + prices_3dtext[key[i]] = 0 + + say("Удалено "..key[i]) + end + end + end, Cid) end end @@ -3288,7 +3303,8 @@ function clearSoloMessage() solo_message_send = { name = "", id = -1, - cargo = 0, + action = "", + cargo = "", time = 0 } end @@ -3296,7 +3312,21 @@ end function transponder() new_pair = {} error_array = {} + solo_data_antiflood = {} clearSoloMessage() + sampRegisterChatCommand("send",function(param) + if param:find("(.+_.+) (%d+) (.+) (.+)") then + local name, id, action, cargo = param:match("(.+_.+) (%d+) (.+) (.+)") + -- /send name id action cargo + solo_message_send = { + name = name, + id = tonumber(id), + action = action, + cargo = cargo, + time = os.time() + } + end + end) while true do wait(0) if script_run and inifiles.Settings.transponder then @@ -3376,7 +3406,13 @@ function transponder() if f then local fileText = f:read("*a") if fileText ~= nil and #fileText > 0 then - info = decodeJson(fileText) + try(function() + info = decodeJson(fileText) + end, function(e) + sampfuncsLog(fileText) + sampAddChatMessage("[TruckHUD]: Ошибочный ответ сервера!",-1) + info = nil + end) if info == nil then print("{ff0000}[" .. string.upper(thisScript().name) .. "]: Был получен некорректный ответ от сервера.") else @@ -3385,6 +3421,9 @@ function transponder() transponder_delay = info.delay response_timestamp = info.timestamp if info.base ~= nil then + transponder_solo_message(info) + + base = info.base error_message('2', '') local minKD = 1000000 @@ -3477,6 +3516,40 @@ function transponder() end end +function transponder_solo_message(info) + if info.solo_data ~= nil then + for sender, solo_data in pairs(info.solo_data) do + if info.timestamp - solo_data.time < 5 and getNameById(tonumber(solo_data.id)) == solo_data.name then + if solo_data_antiflood[sender] == nil then + solo_data_antiflood[sender] = {} + end + local result_find = false -- Отклонить показ сообщения + local check_label = { "id", "name", "action", "cargo" } + for i = 1, #solo_data_antiflood[sender] do -- Поиск дубликата + local counter = 0 + for s = 1, #check_label do + if solo_data[s] == solo_data_antiflood[sender][i][s] then + counter = counter + 1 + end + end + if counter == 4 and solo_data["time"] - solo_data_antiflood[sender][i]["time"] < 10 then + result_find = true + break + end + end + if not result_find then + if texts_of_reports[solo_data["cargo"]] ~= nil then + local text = string.format("[TruckHUD]: %s[%s] %s %s", solo_data.name, solo_data.id, (solo_data.action == "load" and "загрузился на" or "разгрузил"), texts_of_reports[solo_data["cargo"]]) + sampAddChatMessage(text,-1) + end + end + solo_data_antiflood[sender][#solo_data_antiflood[sender]+1] = solo_data + end + end + end +end + + function error_message(key, text) if text ~= '' then if error_array[key] == nil then @@ -4146,11 +4219,17 @@ function luChecker.checkerLoad(playerId, data, position) -- local dist_trucker_storage = getDistanceBetweenCoords3d(trucker_x, trucker_y, trucker_z, x, y, z) if dist_localPlayer_storage <= 120.0 and dist_trucker_storage <= 50.0 then + local key = getKeysPoint(trucker_x, trucker_y, trucker_z) + if key == "ls" or key == "sf" then + if inifiles.Settings.luCheckerCargo >= 1 and inifiles.Settings.luCheckerCargo <= 3 then + key = key..cargo_replace[inifiles.Settings.luCheckerCargo] + end + end solo_message_send = { name = getNameById(playerId), id = playerId, - action = "load" - cargo = inifiles.Settings.luCheckerCargo, + action = "load", + cargo = key, time = os.time() } sampAddChatMessage("игрок получил груз "..playerId.." "..dist_localPlayer_storage.." "..dist_trucker_storage.." +++ "..luChecker.truckers[playerId]["trailerData"]["trailerId"].." ++++ "..data["trailerId"],-1) @@ -4196,11 +4275,17 @@ function luChecker.checker() if getLocalPlayerId() ~= playerId then local dist = getDistanceBetweenCoords3d(position_3dtext.x,position_3dtext.y,position_3dtext.z,position_trailer.x,position_trailer.y,position_trailer.z) if dist < 50 then + local key = getKeysPoint(position_trailer.x,position_trailer.y,position_trailer.z) + if key == "ls" or key == "sf" then + if inifiles.Settings.luCheckerCargo >= 1 and inifiles.Settings.luCheckerCargo <= 3 then + key = key..cargo_replace[inifiles.Settings.luCheckerCargo] + end + end solo_message_send = { name = getNameById(playerId), id = playerId, - action = "unload" - cargo = inifiles.Settings.luCheckerCargo, + action = "unload", + cargo = key, time = os.time() } local text = string.format("игрок %s %s %s %s", playerId, (type == "load" and "загрузил" or "разгрузил"), inifiles.Settings.luCheckerCargo, dist ) @@ -4221,7 +4306,7 @@ end function getNameById(i) local name = "" if sampIsPlayerConnected(i) or i == select(2,sampGetPlayerIdByCharHandle(PLAYER_PED)) then - local name = sampGetPlayerNickname(i) + name = sampGetPlayerNickname(i) end return name end @@ -4239,6 +4324,19 @@ function clear_old_value(key) end end +function getKeysPoint(x, y, z) + local minDist, minResult = 1000000, "" + for name, cord in pairs(location_keys) do + local distance = getDistanceBetweenCoords3d(x, y, z, cord.x, cord.y, cord.z) + if distance < minDist then + minDist = distance + minResult = name + end + end + return minResult +end + + --- luCheckerCargo --[[