From cbdd5adbb6f4971262dfc44fb3a2de8a13df4748 Mon Sep 17 00:00:00 2001 From: Alexell Date: Sun, 1 May 2022 11:49:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D1=81=D0=BE=D0=B2=D0=BF=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D1=8E=D1=89=D0=B8=D0=B5=20=E2=84=96=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=80=D1=88=D1=80=D1=83=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Agent Smith <89154459+angelus1637@users.noreply.github.com> --- lua/autorun/mscoreboard_updater.lua | 43 +++++++++++++++++++++--- lua/metrostroi_scoreboard/player_row.lua | 12 +------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/lua/autorun/mscoreboard_updater.lua b/lua/autorun/mscoreboard_updater.lua index 66614c1..c4b9c59 100644 --- a/lua/autorun/mscoreboard_updater.lua +++ b/lua/autorun/mscoreboard_updater.lua @@ -9,6 +9,16 @@ if SERVER then util.AddNetworkString("MScoreBoard.ClientInfo") + local function FixedRoute(class,route) + local result = "-" + if (class ~= "-" and route ~= "-") then + local rnum = tonumber(route) + if table.HasValue({"gmod_subway_em508","gmod_subway_81-702","gmod_subway_81-703","gmod_subway_81-705_old","gmod_subway_ezh","gmod_subway_ezh3","gmod_subway_ezh3ru1","gmod_subway_81-717_mvm","gmod_subway_81-718","gmod_subway_81-720","gmod_subway_81-720_1","gmod_subway_81-720a","gmod_subway_81-717_freight","gmod_subway_81-717_5a"},class) then rnum = rnum / 10 end + result = rnum + end + return result + end + local TrainList = {} timer.Simple(1.5,function() for _,class in pairs(Metrostroi.TrainClasses) do @@ -138,28 +148,51 @@ if SERVER then return line_str..station_str end + timer.Create("MScoreBoard.RouteNumbersChecker",60,0,function() + local tbl = {} + for k, v in pairs(player.GetAll()) do + local rnumber = tonumber(v:GetNW2String("MSRoute","1000")) or 1000 + table.insert(tbl, {v, rnumber}) + end + for k, v in pairs(tbl) do + for k2, v2 in pairs(tbl) do + if k2 > k and v[1] != v2[1] and v[2] == v2[2] and (v[2] != 1000 and v2[2] != 1000) then + if not v[1]:GetNW2Bool("MSGuestDriving") and not v2[1]:GetNW2Bool("MSGuestDriving") then + ULib.tsayColor(nil,false,Color(222, 0, 0), "У игроков "..v[1]:Nick().." и "..v2[1]:Nick().." совпадают номера маршрутов!") + ULib.tsayColor(nil,false,Color(222, 0, 0), "Пожалуйста, поменяйте номер маршрута.") + end + end + end + end + end) + timer.Create("MScoreBoard.ServerUpdate",3,0,function() local route + local class local owner local driver for train in pairs(Metrostroi.SpawnedTrains) do if not IsValid(train) then continue end - if not table.HasValue(TrainList,train:GetClass()) then continue end + class = train:GetClass() + if not table.HasValue(TrainList,class) then continue end owner = train.Owner if not IsValid(owner) then continue end route = 0 - if train:GetClass() == "gmod_subway_81-722" or train:GetClass() == "gmod_subway_81-722_3" or train:GetClass() == "gmod_subway_81-722_new" or train:GetClass() == "gmod_subway_81-7175p" then + + if class == "gmod_subway_81-722" or class == "gmod_subway_81-722_3" or class == "gmod_subway_81-722_new" or class == "gmod_subway_81-7175p" then route = train.RouteNumberSys.CurrentRouteNumber - elseif train:GetClass() == "gmod_subway_81-717_6" or train:GetClass() == "gmod_subway_81-740_4" then + elseif class == "gmod_subway_81-717_6" or class == "gmod_subway_81-740_4" then route = train.ASNP.RouteNumber else if train.RouteNumber then route = train.RouteNumber.RouteNumber end end + route = FixedRoute(class,route) + -- owner:SetNW2String("MSTrainClass",train:GetClass()) -- костыль для грузового, т.к. у него сзади спавнится номерной мвм - if(owner:GetNW2String("MSTrainClass") ~= "gmod_subway_81-717_freight") then owner:SetNW2String("MSTrainClass",train:GetClass()) end + if(owner:GetNW2String("MSTrainClass") ~= "gmod_subway_81-717_freight") then owner:SetNW2String("MSTrainClass",class) end owner:SetNW2String("MSStation",BuildStationInfo(train,owner:GetNWString("MSLanguage"))) owner:SetNW2String("MSRoute",tostring(route)) owner:SetNW2String("MSWagons",#train.WagonList) @@ -168,7 +201,7 @@ if SERVER then if driver != owner then driver:SetNW2Bool("MSGuestDriving",true) driver:SetNW2String("MSHostDriver", owner:Nick()) - if driver:GetNW2String("MSTrainClass") != "gmod_subway_81-717_freight" then driver:SetNW2String("MSTrainClass",train:GetClass()) end + if driver:GetNW2String("MSTrainClass") != "gmod_subway_81-717_freight" then driver:SetNW2String("MSTrainClass",class) end driver:SetNW2String("MSStation",BuildStationInfo(train,owner:GetNWString("MSLanguage"))) driver:SetNW2String("MSRoute",tostring(route)) end diff --git a/lua/metrostroi_scoreboard/player_row.lua b/lua/metrostroi_scoreboard/player_row.lua index 9553f82..1aafd8c 100644 --- a/lua/metrostroi_scoreboard/player_row.lua +++ b/lua/metrostroi_scoreboard/player_row.lua @@ -25,16 +25,6 @@ local function GetTrainName(class) return result end -local function FixedRoute(class,route) - local result = "-" - if (class ~= "-" and route ~= "-") then - local rnum = tonumber(route) - if table.HasValue({"gmod_subway_em508","gmod_subway_81-702","gmod_subway_81-703","gmod_subway_81-705_old","gmod_subway_ezh","gmod_subway_ezh3","gmod_subway_ezh3ru1","gmod_subway_81-717_mvm","gmod_subway_81-718","gmod_subway_81-720","gmod_subway_81-720_1","gmod_subway_81-720a","gmod_subway_81-717_freight","gmod_subway_81-717_5a"},class) then rnum = rnum / 10 end - result = rnum - end - return result -end - function PlayerRow:Init() self.Height = 38 self.NeedHeight = 38 @@ -184,7 +174,7 @@ function PlayerRow:UpdatePlayerData() if not IsValid(ply) then MScoreBoard.Panel:InvalidateLayout() return end self.Nick:SetText(ply:Nick()) self.Team:SetText(team.GetName(ply:Team())) - self.Route:SetText(FixedRoute(ply:GetNW2String("MSTrainClass","-"),ply:GetNW2String("MSRoute","-"))) + self.Route:SetText(ply:GetNW2String("MSRoute","-")) self.Wags:SetText(ply:GetNW2String("MSWagons","-")) self.Train:SetText(GetTrainName(ply:GetNW2String("MSTrainClass","-"))) self.Station:SetText(string.format(ply:GetNW2String("MSStation","-"),T("MScoreBoard.Line")))