Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Wire Map Interfaces not working on new maps #3028

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 1 addition & 81 deletions lua/entities/info_wiremapinterface/entityoverride.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,9 @@ function WIREENT:TriggerInput(name, value, ...)
if (not Entity.TriggerWireInput) then return end

local Input = self.Inputs[name] or {}
Entity:TriggerWireInput(name, value, (IsValid(Input.Src) == true), self, ...)
Entity:TriggerWireInput(name, value, IsValid(Input.Src) == true, self, ...)
end

-- Copied from the gmod base entity, it's changed to work with wire ports.
-- It's only changed for this entity.
-- This function is used to store an output.
function WIREENT:StoreOutput(name, info)
local rawData = string.Explode(",", info)

local Output = {}
Output.entities = rawData[1] or ""
Output.input = rawData[2] or ""
Output.param = rawData[3] or ""
Output.delay = tonumber(rawData[4]) or 0
Output.times = tonumber(rawData[5]) or -1

self._OutputsToMap = self._OutputsToMap or {}
-- This table (self._OutputsToMap) got renamed,
-- because it was called self.Outputs,
-- that caused conflicts with wiremod!

self._OutputsToMap[name] = self._OutputsToMap[name] or {}
table.insert(self._OutputsToMap[name], Output)
end

-- Nice helper function, this does all the work.
-- Returns false if the output should be removed from the list.
local function FireSingleOutput(output, this, activator)
if (output.times == 0) then return false end
local delay = output.delay
local entitiesToFire = {}

if (output.entities == "!activator") then
entitiesToFire = {activator}
elseif (output.entities == "!self") then
entitiesToFire = {this}
elseif (output.entities == "!player") then
entitiesToFire = player.GetAll()
else
entitiesToFire = ents.FindByName(output.entities)
end

for _,ent in pairs(entitiesToFire) do
if (IsValid(ent)) then
if (delay == 0) then
ent:Input(output.input, activator, this, output.param)
else
timer.Simple(delay, function()
if (IsValid(ent)) then
ent:Input(output.input, activator, this, output.param)
end
end)
end
end
end

if (output.times ~= -1) then
output.times = output.times - 1
end

return ((output.times > 0) or (output.times == -1))
end

-- This function is used to store an output.
function WIREENT:TriggerOutput(name, activator)
if (not self._OutputsToMap) then return end
local OutputsToMap = self._OutputsToMap[name]
if (not OutputsToMap) then return end

for idx,op in pairs(OutputsToMap) do
if (not FireSingleOutput(op, self, activator)) then
self._OutputsToMap[name][idx] = nil
end
end
end


-- Remove its overrides
function WIREENT:_RemoveOverrides()
for k, v in pairs(self._Overrides_WireMapInterfaceEnt or {}) do
Expand All @@ -108,16 +34,10 @@ function WIREENT:_RemoveOverrides()
end
self._Settings_WireMapInterfaceEnt = nil

if (self.Outputs) then
table.Merge(self.Outputs, self._OutputsToMap)
end
self._OutputsToMap = nil

self._WireMapInterfaceEnt = nil
self._RemoveOverride = nil
end


-- Adds its overrides
function ENT:OverrideEnt(Entity)
Entity._Overrides_WireMapInterfaceEnt = Entity._Overrides_WireMapInterfaceEnt or {}
Expand Down
9 changes: 3 additions & 6 deletions lua/entities/info_wiremapinterface/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ Keep in mind that you have to know what you do
and that you have to activate spawnflag 8 to make it work.
Spawnflag 8 is better known as "Run given Lua codes (For advanced users!)" in the Hammer Editor.

Please don't change thinks unless you know what you do. You may break maps if do something wrong.
Please don't change things unless you know what you do. You may break maps if do something wrong.
]]

include("convert.lua")
include("entitycontrol.lua")
include("entityoverride.lua")
include("output.lua")

local ALLOW_INTERFACE = CreateConVar("sv_wire_mapinterface", "1", {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_GAMEDLL}, "Aktivate or deaktivate the wire map interface. Default: 1")

Expand Down Expand Up @@ -221,7 +220,7 @@ function ENT:AcceptInput(name, activator, caller, data)
local pattern = "(%d+)"
local I = tonumber(string.match(name, "triggerwireoutput"..pattern)) or 0

if ((I > 0) and (I <= MAX_PORTS) and (self.OutsExist[I])) then
if I > 0 and I <= MAX_PORTS and self.OutsExist[I] then
self.Timer = self.Timer or {}
self.Timer.Out = self.Timer.Out or {}

Expand Down Expand Up @@ -329,9 +328,8 @@ function ENT:KeyValue(key, value)

local I, name = string.match(key, "output"..pattern)
local I, name = tonumber(I) or 0, tostring(name or "")
if ((I > 0) and (I <= MAX_PORTS) and (name ~= "")) then
if I > 0 and I <= MAX_PORTS and name ~= "" then
self.Outs = self.Outs or {}
--self.OutsIDs = self.OutsIDs or {}
self.OutsExist = self.OutsExist or {}

self.Outs[I] = self.Outs[I] or {}
Expand All @@ -340,7 +338,6 @@ function ENT:KeyValue(key, value)
elseif (name == "desc") then
self.Outs[I][name] = value
elseif (name == "name") then
--self.OutsIDs[value] = I
self.OutsExist[I] = true
self.Outs[I][name] = value
end
Expand Down
72 changes: 0 additions & 72 deletions lua/entities/info_wiremapinterface/output.lua

This file was deleted.

Loading