Fixed Wire Map Interfaces not working on new maps (#3028)

* Fixed Wire Map Interfaces not working on new maps

The way GMod handles Hammer input/outputs has been changed and no longer conflicts with Wiremod's self.Output. So we can remove the override workaround.

* Removed dead code and uneeded parentheses
This commit is contained in:
Grocel 2024-04-05 02:16:53 +02:00 committed by GitHub
parent d0c4bf5c28
commit c5bbf67de0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 159 deletions

View File

@ -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
@ -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 {}

View File

@ -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")
@ -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 {}
@ -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 {}
@ -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

View File

@ -1,72 +0,0 @@
-- Copied from the gmod base entity, it's changed to work with wire map interface.
-- It's only changed for this entity.
-- This function is used to store an output.
function ENT: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 {}
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, value, delayoffset)
if (output.times == 0) then return false end
local delay = output.delay + (delayoffset or 0)
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, value or output.param)
else
timer.Simple(delay, function()
if (IsValid(ent)) then
ent:Input(output.input, activator, this, value or 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 trigger an output.
-- This changed version supports value replacemant and delay offsets.
function ENT:TriggerOutput(name, activator, value, delayoffset)
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, value, delayoffset)) then
self._OutputsToMap[name][idx] = nil
end
end
end