1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-02 00:42:29 +00:00

Merge pull request #287 from metrostroi-repo/#263

#263
This commit is contained in:
HellReach
2021-12-28 20:29:59 +03:00
committed by GitHub
2 changed files with 28 additions and 10 deletions

View File

@@ -249,6 +249,7 @@ function ENT:Initialize()
-- Overrides for train wire values from wiremod interface and special concommand -- Overrides for train wire values from wiremod interface and special concommand
self.TrainWireOverrides = {} self.TrainWireOverrides = {}
self.TrainWireOutside = {} self.TrainWireOutside = {}
self.TrainWireOutsideFrom = {}
-- Is this train 'odd' or 'even' in coupled set -- Is this train 'odd' or 'even' in coupled set
@@ -798,7 +799,9 @@ end]]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function ENT:LeaderReadTrainWire(id) function ENT:LeaderReadTrainWire(id)
if self.TrainWireOverrides[id] then return self.TrainWireOverrides[id] end if self.TrainWireOverrides[id] then return self.TrainWireOverrides[id] end
if self.TrainWireOutside[id] then return self.TrainWireOutside[id] end if self.TrainWireOutside[id] then
return (self.TrainWireOutsideFrom[id] and (self.TrainWireTurbostroi[self.TrainWireOutsideFrom[id]] or 0) or 1)*self.TrainWireOutside[id]
end
return (self.TrainWireTurbostroi[id] or 0)+(self.TrainWireWriters[id] or 0) return (self.TrainWireTurbostroi[id] or 0)+(self.TrainWireWriters[id] or 0)
end end

View File

@@ -321,7 +321,7 @@ concommand.Add("metrostroi_fail", function(ply, _, args)
if train then if train then
if IsValid(ply) then if IsValid(ply) then
ply:PrintMessage(HUD_PRINTCONSOLE,"Generating random failure in your train!") ply:PrintMessage(HUD_PRINTCONSOLE,"Generating random failure in your train!")
print("Player "..tostring(ply).." generated random failure in train "..train:EntIndex()) print(tostring(ply).." generated random failure in train "..train:EntIndex())
else else
print("Generating random failure in train "..train:EntIndex()) print("Generating random failure in train "..train:EntIndex())
end end
@@ -355,7 +355,7 @@ concommand.Add("metrostroi_fail_reset", function(ply, _, args)
if #trainList > 0 then if #trainList > 0 then
if IsValid(ply) then if IsValid(ply) then
ply:PrintMessage(HUD_PRINTCONSOLE,"Reset all failures in your train!") ply:PrintMessage(HUD_PRINTCONSOLE,"Reset all failures in your train!")
print("Player "..tostring(ply).." reset all failures in train "..trainList[1]:EntIndex()) print(tostring(ply).." reset all failures in train "..trainList[1]:EntIndex())
else else
print("Reset all failures in train "..trainList[1]:EntIndex()) print("Reset all failures in train "..trainList[1]:EntIndex())
end end
@@ -390,14 +390,17 @@ concommand.Add("metrostroi_wire", function(ply, _, args)
if train then if train then
if IsValid(ply) then if IsValid(ply) then
args[1] = tonumber(args[1]) args[1] = tonumber(args[1])
if not args[1] then ply:PrintMessage(HUD_PRINTCONSOLE,"Argument must be a number") return end if not args[1] then ply:PrintMessage(HUD_PRINTCONSOLE,"1st argument must be a number") return end
ply:PrintMessage(HUD_PRINTCONSOLE,"sets outside power in train wire"..args[1].."!") if args[2] and not tonumber(args[2]) then ply:PrintMessage(HUD_PRINTCONSOLE,"2nd argument must be a number") return end
print("Player "..tostring(ply).." sets outside power in train "..args[1].." wire failure in train "..train:EntIndex()) args[2] = tonumber(args[2])
ply:PrintMessage(HUD_PRINTCONSOLE,"sets outside power in train wire"..args[1]..(args[2] and "(from "..args[2].." wire)" or "").."!")
print(tostring(ply).." sets outside power in train "..args[1].." wire"..(args[2] and "(from "..args[2].." wire)" or "").." failure in train number "..train:GetWagonNumber())
else else
print("sets outside power in train wire "..train:EntIndex()) print("sets outside power in train wire "..train:EntIndex())
end end
--if train.WriteTrainWire then train:WriteTrainWire(args[1],1) end --if train.WriteTrainWire then train:WriteTrainWire(args[1],1) end
train.TrainWireOutside[args[1]] = 1 train.TrainWireOutside[args[1]] = 1
train.TrainWireOutsideFrom[args[1]] = args[2]
--if train.WriteTrainWire then train:WriteTrainWire(args[1],1) end --if train.WriteTrainWire then train:WriteTrainWire(args[1],1) end
else else
if IsValid(ply) then if IsValid(ply) then
@@ -426,12 +429,24 @@ concommand.Add("metrostroi_wire_reset", function(ply, _, args)
if #trainList > 0 then if #trainList > 0 then
if IsValid(ply) then if IsValid(ply) then
ply:PrintMessage(HUD_PRINTCONSOLE,"reset wire outside power in train!") if args[1] and not tonumber(args[1]) then ply:PrintMessage(HUD_PRINTCONSOLE,"Argument must be a number") return end
print("Player "..tostring(ply).." reset outside power in train ") ply:PrintMessage(HUD_PRINTCONSOLE,"reset "..(args[1] and args[1].." " or "").."wire outside power in train!")
print(tostring(ply).." reset "..(args[1] and args[1].." wire " or "").."outside power in train ")
else else
print("Reset outside power in trains ") print("Reset outside power in trains ")
end
args[1] = tonumber(args[1])
if args[1] then
for _,v in pairs(trainList) do
v.TrainWireOutside[args[1]] = nil
v.TrainWireOutsideFrom[args[1]] = nil
end
else
for _,v in pairs(trainList) do
v.TrainWireOutside = {}
v.TrainWireOutsideFrom = {}
end
end end
for _,v in pairs(trainList) do v.TrainWireOutside = {} end
else else
if IsValid(ply) then if IsValid(ply) then
ply:PrintMessage(HUD_PRINTCONSOLE,"You must be inside a train!") ply:PrintMessage(HUD_PRINTCONSOLE,"You must be inside a train!")
@@ -453,7 +468,7 @@ concommand.Add("metrostroi_can", function(ply, _, args)
if tonumber(args[4]) then value = tonumber(args[4]) end if tonumber(args[4]) then value = tonumber(args[4]) end
local srcid = tonumber(args[5]) local srcid = tonumber(args[5])
ply:PrintMessage(HUD_PRINTCONSOLE,"Hacking CAN!") ply:PrintMessage(HUD_PRINTCONSOLE,"Hacking CAN!")
print(Format("Player %s hack CAN(%s->%s:%s %s=%s)",ply,srcid,system,id,name,value)) print(Format("%s hack CAN(%s->%s:%s %s=%s)",ply,srcid,system,id,name,value))
train:CANWrite("Hacker",srcid or train:GetWagonNumber(),system,id,name,value) train:CANWrite("Hacker",srcid or train:GetWagonNumber(),system,id,name,value)
end) end)