From 0e32990d75736502523079c89a32c688abb51aec Mon Sep 17 00:00:00 2001 From: rubin Date: Wed, 19 Oct 2022 23:26:57 +0300 Subject: [PATCH] add checker 3d text on changed price --- TruckHUD.lua | 98 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 9 deletions(-) diff --git a/TruckHUD.lua b/TruckHUD.lua index 377b6c8..9cb0e57 100755 --- a/TruckHUD.lua +++ b/TruckHUD.lua @@ -75,6 +75,8 @@ local my_nick, server, timer_min, timer_sec, workload = "", "", 0, 0, 0 local mon_life, mon_time, mon_ctime = 0, 0, 0 +local prices_3dtext_pos = {} +local prices_3dtext_id = {} local prices_3dtext = { n1 = 0, n2 = 0, y1 = 0, y2 = 0, l1 = 0, l2 = 0, lsn = 0, lsy = 0, lsl = 0, sfn = 0, sfy = 0, sfl = 0 } local prices_mon = { n1 = 0, n2 = 0, y1 = 0, y2 = 0, l1 = 0, l2 = 0, lsn = 0, lsy = 0, lsl = 0, sfn = 0, sfy = 0, sfl = 0 } local prices_smon = { n1 = 0, n2 = 0, y1 = 0, y2 = 0, l1 = 0, l2 = 0, lsn = 0, lsy = 0, lsl = 0, sfn = 0, sfy = 0, sfl = 0 } @@ -269,7 +271,8 @@ function settings_load() stats_text = defaultMon, renderTruck = true, AutoClear = true, - NewPairMSG = true + NewPairMSG = true, + luCheckerCargo = 0 }, Render = { FontName = "Segoe UI", @@ -2669,6 +2672,7 @@ function loadEvents() lua_thread.create( function(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, textt) for k, v in pairs(find_3dText) do + if string.find(text, v) then if (msk_timestamp - id_3D_text) > 1 then wait_auto = msk_timestamp @@ -2676,9 +2680,11 @@ function loadEvents() id_3D_text = id if text:find("Порт") then unload_location = true - prices_3dtext[k .. "n"], prices_3dtext[k .. "y"], prices_3dtext[k .. "l"] = - string.match(text, v) - say(prices_3dtext[k .. "n"]) + local cargoN, cargoY, cargoL = string.match(text, v) + luChecker.set3Dtext("Порт", {prices_3dtext[k .. "n"], prices_3dtext[k .. "y"], prices_3dtext[k .. "l"]}, {cargoN, cargoY, cargoL}) + prices_3dtext[k .. "n"], prices_3dtext[k .. "y"], prices_3dtext[k .. "l"] = cargoN, cargoY, cargoL + prices_3dtext_id[k .. "n"], prices_3dtext_id[k .. "y"], prices_3dtext_id[k .. "l"] = id, id, id + prices_3dtext_pos[k .. "n"], prices_3dtext_pos[k .. "y"], prices_3dtext_pos[k .. "l"] = position, position, position for k, v in pairs(prices_3dtext) do if string.find(tostring(prices_3dtext[k]), "99") then prices_3dtext[k] = tonumber(prices_3dtext[k]) + 1 @@ -2723,7 +2729,11 @@ function loadEvents() attachedVehicleId ) else - prices_3dtext[k] = string.match(text, v) + local cargo_save = string.match(text, v) + luChecker.set3Dtext("Склад", {prices_3dtext[k], k}, {cargo_save, k}) + prices_3dtext[k] = cargo_save + prices_3dtext_id[k] = id + prices_3dtext_pos[k] = position load_location = true current_warehouse = k end @@ -2748,9 +2758,34 @@ function loadEvents() unload_location = false current_warehouse = "none" end + local result, key = isTruck3dTextDefined(Cid) + if result then + for i = 1, #key do + prices_3dtext_id[key[i]] = -1 + prices_3dtext[key[i]] = 0 + + say("Удалено "..key[i]) + end + end end end +function isTruck3dTextDefined(id) + local result = false + local delete = {} + local x, y, z = getCharCoordinates(PLAYER_PED) + for k,v in pairs(prices_3dtext_id) do + local dist = getDistanceBetweenCoords3d(x, y, z, prices_3dtext_pos[k].x, prices_3dtext_pos[k].y, prices_3dtext_pos[k].z) + say(dist) + if id == v and v ~= -1 and dist > 20 then + result = true + say(k) + delete[#delete+1] = k + end + end + return result, delete +end + function say(text) sampAddChatMessage(tostring(text),-1) end @@ -3959,9 +3994,18 @@ end luChecker = { vehicles = {}, truckers = {}, -- Игроки не в скрипте - + event = {} } +--[[ + + разгрузил эвент + сменился 3д текст эвент + разгрузил эвент + сменился 3д текст эвент + +]] + function isPlayerHaveTruckHUD(playerId) local result = false for k,v in pairs(base) do @@ -3978,7 +4022,7 @@ function isVehicleTruckersDelete(table, vehicleId) local playerId = -1 local isTrailer = false for k,v in pairs(table) do - if v["trailerData"].trailerId == vehicleId then + if v["trailerData"] ~= nil and v["trailerData"].trailerId == vehicleId then result = true playerId = k isTrailer = true @@ -4024,8 +4068,44 @@ function luChecker.vehicleSync(playerId, vehicleId, data) end end -function luChecker.trailerSync(playerId, data) +function luChecker.trailerSync(playerId, data_old, data) if not isPlayerHaveTruckHUD(playerId) and luChecker.truckers[playerId] ~= nil then luChecker.truckers[playerId]["trailerData"] = data end -end \ No newline at end of file +end + +function luChecker.set3Dtext(type, data_old, data) + inifiles.Settings.luCheckerCargo = 1 + if type == "Порт" then + local key = inifiles.Settings.luCheckerCargo + say(string.format("%s %s", data_old[key], data[key])) + if tonumber(data_old[key]) ~= 0 and not (tonumber(data_old[key]) == tonumber(data[1])) then + if tonumber(data_old[key]) > tonumber(data[key]) then + say("Разгрузка в порту рядом "..inifiles.Settings.luCheckerCargo) + else + say("в другом порту кто то разгрузился "..inifiles.Settings.luCheckerCargo) + end + end + elseif type == "Склад" then + local cargoName = data[2] + local cargoId = (cargoName:find("n") and 1 or (cargoName:find("y") and 2 or (cargoName:find("l") and 3 or 0))) + if cargoId == inifiles.Settings.luCheckerCargo and tonumber(data_old[1]) ~= 0 and not (tonumber(data_old[1]) == tonumber(data[1])) then + if tonumber(data_old[1]) < tonumber(data[1]) then + say("Загрузка на складе рядом "..inifiles.Settings.luCheckerCargo) + else + say("на другом складе кто то закупился "..inifiles.Settings.luCheckerCargo) + end + end + end +end + + +--- luCheckerCargo +--[[ + + +settings_save() + +inifiles.Settings.luCheckerCargo + +]] \ No newline at end of file