mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-02 00:42:29 +00:00
Оптимизация обработки команд сигналики из чата
This commit is contained in:
@@ -77,14 +77,29 @@ function ENT:CloseRoute(route)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cmds = {
|
||||||
|
["!sactiv"] = {1,9},
|
||||||
|
["!sdeactiv"] = {2,11},
|
||||||
|
["!sclose"] = {3,9},
|
||||||
|
["!sopen"] = {4,8},
|
||||||
|
["!sopps"] = {5,8},
|
||||||
|
["!sclps"] = {6,8},
|
||||||
|
["!senao"] = {7,8},
|
||||||
|
["!sdisao"] = {8,9}
|
||||||
|
}
|
||||||
|
|
||||||
function MSignalSayHook(ply, comm, fromULX)
|
function MSignalSayHook(ply, comm, fromULX)
|
||||||
if ulx and not fromULX then return end
|
if ulx and not fromULX then return end
|
||||||
for i,sig in pairs(ents.FindByClass("gmod_track_signal")) do
|
local argv = string.Explode(" ",comm)
|
||||||
local comm = comm
|
local cmdInfo = cmds[argv[1]]
|
||||||
if comm:sub(1,8) == "!sactiv " then
|
|
||||||
comm = comm:sub(9,-1):upper()
|
|
||||||
|
|
||||||
comm = string.Explode(":",comm)
|
if not cmdInfo or #argv < 2 then return end
|
||||||
|
|
||||||
|
local cmd = cmdInfo[1]
|
||||||
|
local comm = string.Explode(":",comm:sub(cmdInfo[2],-1):upper())
|
||||||
|
|
||||||
|
for sig in pairs(Metrostroi.SignalEntityPositions) do
|
||||||
|
if cmd == 1 then -- !sactiv
|
||||||
if sig.Routes then
|
if sig.Routes then
|
||||||
for k,v in pairs(sig.Routes) do
|
for k,v in pairs(sig.Routes) do
|
||||||
if (v.RouteName and v.RouteName:upper() == comm[1] or comm[1] == "*") and v.Emer then
|
if (v.RouteName and v.RouteName:upper() == comm[1] or comm[1] == "*") and v.Emer then
|
||||||
@@ -94,10 +109,7 @@ function MSignalSayHook(ply, comm, fromULX)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif comm:sub(1,10) == "!sdeactiv " then
|
elseif cmd == 2 then -- !sdeactiv
|
||||||
comm = comm:sub(11,-1):upper()
|
|
||||||
|
|
||||||
comm = string.Explode(":",comm)
|
|
||||||
if sig.Routes then
|
if sig.Routes then
|
||||||
for k,v in pairs(sig.Routes) do
|
for k,v in pairs(sig.Routes) do
|
||||||
if (v.RouteName and v.RouteName:upper() == comm[1] or comm[1] == "*") and v.Emer then
|
if (v.RouteName and v.RouteName:upper() == comm[1] or comm[1] == "*") and v.Emer then
|
||||||
@@ -106,10 +118,7 @@ function MSignalSayHook(ply, comm, fromULX)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif comm:sub(1,8) == "!sclose " then
|
elseif cmd == 3 then -- !sclose
|
||||||
comm = comm:sub(9,-1):upper()
|
|
||||||
|
|
||||||
comm = string.Explode(":",comm)
|
|
||||||
if comm[1] == sig.Name then
|
if comm[1] == sig.Name then
|
||||||
if sig.Routes[1] and sig.Routes[1].Manual then
|
if sig.Routes[1] and sig.Routes[1].Manual then
|
||||||
sig:CloseRoute(1)
|
sig:CloseRoute(1)
|
||||||
@@ -134,9 +143,7 @@ function MSignalSayHook(ply, comm, fromULX)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif comm:sub(1,7) == "!sopen " then
|
elseif cmd == 4 then -- !sopen
|
||||||
comm = comm:sub(8,-1):upper()
|
|
||||||
comm = string.Explode(":",comm)
|
|
||||||
if comm[1] == sig.Name then
|
if comm[1] == sig.Name then
|
||||||
if comm[2] then
|
if comm[2] then
|
||||||
if sig.NextSignals[comm[2]] then
|
if sig.NextSignals[comm[2]] then
|
||||||
@@ -161,27 +168,19 @@ function MSignalSayHook(ply, comm, fromULX)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif comm:sub(1,7) == "!sopps " then
|
elseif cmd == 5 then -- !sopps
|
||||||
comm = comm:sub(8,-1):upper()
|
|
||||||
comm = string.Explode(":",comm)
|
|
||||||
if comm[1] == sig.Name then
|
if comm[1] == sig.Name then
|
||||||
sig.InvationSignal = true
|
sig.InvationSignal = true
|
||||||
end
|
end
|
||||||
elseif comm:sub(1,7) == "!sclps " then
|
elseif cmd == 6 then -- !sclps
|
||||||
comm = comm:sub(8,-1):upper()
|
|
||||||
comm = string.Explode(":",comm)
|
|
||||||
if comm[1] == sig.Name then
|
if comm[1] == sig.Name then
|
||||||
sig.InvationSignal = false
|
sig.InvationSignal = false
|
||||||
end
|
end
|
||||||
elseif comm:sub(1,7) == "!senao " then
|
elseif cmd == 7 then -- !senao
|
||||||
comm = comm:sub(8,-1):upper()
|
|
||||||
comm = string.Explode(":",comm)
|
|
||||||
if comm[1] == sig.Name then
|
if comm[1] == sig.Name then
|
||||||
if sig.AODisabled then sig.AODisabled = false end
|
if sig.AODisabled then sig.AODisabled = false end
|
||||||
end
|
end
|
||||||
elseif comm:sub(1,8) == "!sdisao " then
|
elseif cmd == 8 then -- !sdisao
|
||||||
comm = comm:sub(9,-1):upper()
|
|
||||||
comm = string.Explode(":",comm)
|
|
||||||
if comm[1] == sig.Name then
|
if comm[1] == sig.Name then
|
||||||
if sig.ARSSpeedLimit == 2 then sig.AODisabled = true end
|
if sig.ARSSpeedLimit == 2 then sig.AODisabled = true end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user