From abbda17e5d1500890b0fcaf3de17c3a1f79d4612 Mon Sep 17 00:00:00 2001 From: Hellss Date: Sat, 4 Jun 2022 01:41:41 +0300 Subject: [PATCH 1/3] Added ulx.getroutes, ulx.getsigroutes --- lua/ulx/modules/sh/metrostroi.lua | 77 ++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/lua/ulx/modules/sh/metrostroi.lua b/lua/ulx/modules/sh/metrostroi.lua index 9a81600..c881fcd 100644 --- a/lua/ulx/modules/sh/metrostroi.lua +++ b/lua/ulx/modules/sh/metrostroi.lua @@ -321,7 +321,7 @@ function ulx.changecab( calling_ply ) if not IsValid(calling_ply) then return end local Wagon = calling_ply:GetTrain() if not IsValid(Wagon) then - ULib.tsayError( calling_ply, "You ,ust sit in train",true) + ULib.tsayError( calling_ply, "You must sit in train",true) return end @@ -505,6 +505,81 @@ tps:addParam{ type=ULib.cmds.StringArg, hint="Station or station number", ULib.c tps:defaultAccess( ULib.ACCESS_ALL ) tps:help( "Teleport between stations." ) + +function ulx.getroutes( calling_ply ) + if not IsValid(calling_ply) then return end + local Train = calling_ply:GetTrain() + if not IsValid(Train) then + ULib.tsayError( calling_ply, "You must sit in train",true) + return + end + + local signal + -- Get train position + local pos = Metrostroi.TrainPositions[Train] + if pos then pos = pos[1] end + -- Get previous ARS section + if pos then + signal = Metrostroi.GetARSJoint(pos.node1,pos.x,Metrostroi.TrainDirections[Train], Train) + end + + if signal then + local found = false + for k,v in pairs(signal.Routes or {}) do + if v.RouteName != "" then + found = true + break + end + end + if not found then + ULib.tsayError( calling_ply, "Signal routes not found", true) + return + end + ulx.fancyLog("Routes of signal #s:", signal.Name) + for k,v in pairs(signal.Routes) do + if v.RouteName != "" then + ulx.fancyLog("#s", v.RouteName) + end + end + else + ULib.tsayError( calling_ply, "Signal not found", true) + end +end +local getroutes = ulx.command( CATEGORY_NAME, "ulx getroutes", ulx.getroutes, "!getroutes" ) +getroutes:defaultAccess( ULib.ACCESS_ALL ) +getroutes:help( "Print routes of next signal" ) + +function ulx.getsigroutes( calling_ply, sig ) + if not IsValid(calling_ply) then return end + local signal = Metrostroi.GetSignalByName(sig) + if not signal then + ULib.tsayError( calling_ply, "Signal not found", true) + return + end + + local found = false + for k,v in pairs(signal.Routes or {}) do + if v.RouteName != "" then + found = true + break + end + end + if not found then + ULib.tsayError( calling_ply, "Signal routes not found", true) + return + end + ulx.fancyLog("Routes of signal #s:", signal.Name) + for k,v in pairs(signal.Routes) do + if v.RouteName != "" then + ulx.fancyLog("#s", v.RouteName) + end + end +end +local getsigroutes = ulx.command( CATEGORY_NAME, "ulx getsigroutes", ulx.getsigroutes, "!getsigroutes" ) +getsigroutes:addParam{ type=ULib.cmds.StringArg, hint="Signal", ULib.cmds.takeRestOfLine } +getsigroutes:defaultAccess( ULib.ACCESS_ALL ) +getsigroutes:help( "Print routes of signal" ) + --Костылииии function ulx.sopen( calling_ply, arg ) MSignalSayHook(calling_ply,"!sopen "..arg, true) From 25ce24649640230caeb0dc672ee6ff1f186542ac Mon Sep 17 00:00:00 2001 From: Hellss Date: Tue, 12 Jul 2022 01:38:36 +0300 Subject: [PATCH 2/3] sroutes --- lua/ulx/modules/sh/metrostroi.lua | 94 ++++++++++++++----------------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/lua/ulx/modules/sh/metrostroi.lua b/lua/ulx/modules/sh/metrostroi.lua index c881fcd..a8bf160 100644 --- a/lua/ulx/modules/sh/metrostroi.lua +++ b/lua/ulx/modules/sh/metrostroi.lua @@ -506,24 +506,47 @@ tps:defaultAccess( ULib.ACCESS_ALL ) tps:help( "Teleport between stations." ) -function ulx.getroutes( calling_ply ) +function ulx.sroutes( calling_ply, signal ) if not IsValid(calling_ply) then return end local Train = calling_ply:GetTrain() - if not IsValid(Train) then - ULib.tsayError( calling_ply, "You must sit in train",true) - return - end - - local signal - -- Get train position - local pos = Metrostroi.TrainPositions[Train] - if pos then pos = pos[1] end - -- Get previous ARS section - if pos then - signal = Metrostroi.GetARSJoint(pos.node1,pos.x,Metrostroi.TrainDirections[Train], Train) - end + if IsValid(Train) then + local signal + -- Get train position + local pos = Metrostroi.TrainPositions[Train] + if pos then pos = pos[1] end + -- Get previous ARS section + if pos then + signal = Metrostroi.GetARSJoint(pos.node1,pos.x,Metrostroi.TrainDirections[Train], Train) + end + + if signal then + local found = false + for k,v in pairs(signal.Routes or {}) do + if v.RouteName != "" then + found = true + break + end + end + if not found then + ULib.tsayError( calling_ply, "Signal routes not found", true) + return + end + ulx.fancyLog("Routes of signal #s:", signal.Name) + for k,v in pairs(signal.Routes) do + if v.RouteName != "" then + ulx.fancyLog("#s", v.RouteName) + end + end + else + ULib.tsayError( calling_ply, "Signal not found", true) + end + else + local signal = Metrostroi.GetSignalByName(sig) + if not signal then + ULib.tsayError( calling_ply, "Signal not found", true) + return + end - if signal then local found = false for k,v in pairs(signal.Routes or {}) do if v.RouteName != "" then @@ -540,45 +563,14 @@ function ulx.getroutes( calling_ply ) if v.RouteName != "" then ulx.fancyLog("#s", v.RouteName) end - end - else - ULib.tsayError( calling_ply, "Signal not found", true) + end end end -local getroutes = ulx.command( CATEGORY_NAME, "ulx getroutes", ulx.getroutes, "!getroutes" ) -getroutes:defaultAccess( ULib.ACCESS_ALL ) -getroutes:help( "Print routes of next signal" ) +local sroutes = ulx.command( CATEGORY_NAME, "ulx sroutes", ulx.sroutes, "!sroutes" ) +sroutes:addParam{ type=ULib.cmds.StringArg, hint="Signal", ULib.cmds.takeRestOfLine } +sroutes:defaultAccess( ULib.ACCESS_ALL ) +sroutes:help( "Print routes of next signal" ) -function ulx.getsigroutes( calling_ply, sig ) - if not IsValid(calling_ply) then return end - local signal = Metrostroi.GetSignalByName(sig) - if not signal then - ULib.tsayError( calling_ply, "Signal not found", true) - return - end - - local found = false - for k,v in pairs(signal.Routes or {}) do - if v.RouteName != "" then - found = true - break - end - end - if not found then - ULib.tsayError( calling_ply, "Signal routes not found", true) - return - end - ulx.fancyLog("Routes of signal #s:", signal.Name) - for k,v in pairs(signal.Routes) do - if v.RouteName != "" then - ulx.fancyLog("#s", v.RouteName) - end - end -end -local getsigroutes = ulx.command( CATEGORY_NAME, "ulx getsigroutes", ulx.getsigroutes, "!getsigroutes" ) -getsigroutes:addParam{ type=ULib.cmds.StringArg, hint="Signal", ULib.cmds.takeRestOfLine } -getsigroutes:defaultAccess( ULib.ACCESS_ALL ) -getsigroutes:help( "Print routes of signal" ) --Костылииии function ulx.sopen( calling_ply, arg ) From 6dd740e82f67ff4390c9dcf314ea6c969973897c Mon Sep 17 00:00:00 2001 From: Hellss Date: Tue, 12 Jul 2022 01:45:18 +0300 Subject: [PATCH 3/3] fix param Signal --- lua/ulx/modules/sh/metrostroi.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/ulx/modules/sh/metrostroi.lua b/lua/ulx/modules/sh/metrostroi.lua index a8bf160..3e6da25 100644 --- a/lua/ulx/modules/sh/metrostroi.lua +++ b/lua/ulx/modules/sh/metrostroi.lua @@ -506,10 +506,10 @@ tps:defaultAccess( ULib.ACCESS_ALL ) tps:help( "Teleport between stations." ) -function ulx.sroutes( calling_ply, signal ) +function ulx.sroutes( calling_ply, sig ) if not IsValid(calling_ply) then return end local Train = calling_ply:GetTrain() - if IsValid(Train) then + if IsValid(Train) and (not sig or sig == "") then local signal -- Get train position local pos = Metrostroi.TrainPositions[Train] @@ -518,7 +518,6 @@ function ulx.sroutes( calling_ply, signal ) if pos then signal = Metrostroi.GetARSJoint(pos.node1,pos.x,Metrostroi.TrainDirections[Train], Train) end - if signal then local found = false for k,v in pairs(signal.Routes or {}) do @@ -542,6 +541,9 @@ function ulx.sroutes( calling_ply, signal ) end else local signal = Metrostroi.GetSignalByName(sig) + if not signal and sig then + signal = Metrostroi.GetSignalByName(sig:upper()) + end if not signal then ULib.tsayError( calling_ply, "Signal not found", true) return @@ -567,7 +569,7 @@ function ulx.sroutes( calling_ply, signal ) end end local sroutes = ulx.command( CATEGORY_NAME, "ulx sroutes", ulx.sroutes, "!sroutes" ) -sroutes:addParam{ type=ULib.cmds.StringArg, hint="Signal", ULib.cmds.takeRestOfLine } +sroutes:addParam{ type=ULib.cmds.StringArg, hint="Signal", ULib.cmds.optional } sroutes:defaultAccess( ULib.ACCESS_ALL ) sroutes:help( "Print routes of next signal" )