Permalink
Browse files

Added 3rd argument to ENT:TriggerOutput

  • Loading branch information...
1 parent 9a03727 commit 8fef618deea9a2ff668d22b9449d34b414aa5a7e @robotboy655 robotboy655 committed Jun 26, 2015
Showing with 41 additions and 38 deletions.
  1. +41 −38 garrysmod/gamemodes/base/entities/entities/base_entity/outputs.lua
@@ -7,72 +7,75 @@
-- If called from ENT:KeyValue, then the first parameter is the key, and
-- the second is value.
-function ENT:StoreOutput(name, info)
- local rawData = string.Explode(",",info);
-
+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
-
+ Output.delay = tonumber( rawData[4] ) or 0
+ Output.times = tonumber( rawData[5] ) or -1
+
self.Outputs = self.Outputs or {}
- self.Outputs[name] = self.Outputs[name] or {}
-
- table.insert(self.Outputs[name], Output);
+ self.Outputs[ name ] = self.Outputs[ name ] or {}
+
+ table.insert( self.Outputs[ 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)
+local function FireSingleOutput( output, this, activator, data )
- if (output.times == 0) then return false end
+ if ( output.times == 0 ) then return false end
- local entitiesToFire = {};
+ 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 );
+ 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 (ent:IsValid()) then
- if (output.delay == 0) then
- ent:Input(output.input, activator, this, output.param);
- else
- timer.Simple(output.delay,
- function()
- if IsValid(ent) then
- ent:Input(output.input, activator, this, output.param)
- end
- end)
+
+ for _, ent in pairs( entitiesToFire ) do
+ if ( output.delay == 0 ) then
+ if ( IsValid( ent ) ) then
+ ent:Input( output.input, activator, this, data or output.param )
end
+ else
+ timer.Simple( output.delay, function()
+ if ( IsValid( ent ) ) then
+ ent:Input( output.input, activator, this, data or output.param )
+ end
+ end )
end
end
-
- if (output.times ~= -1) then
- output.times = output.times - 1;
+
+ if ( output.times ~= -1 ) then
+ output.times = output.times - 1
end
- return (output.times > 0) || (output.times == -1)
+ return ( output.times > 0 ) || ( output.times == -1 )
end
-- This function is used to trigger an output.
-function ENT:TriggerOutput(name, activator)
- if (!self.Outputs) then return end
- if (!self.Outputs[name]) then return end
+function ENT:TriggerOutput( name, activator, data )
+ if ( !self.Outputs ) then return end
+ if ( !self.Outputs[ name ] ) then return end
- local OutputList = self.Outputs[name]
+ local OutputList = self.Outputs[ name ]
for idx = #OutputList, 1, -1 do
- if ( OutputList[idx] and !FireSingleOutput( OutputList[idx], self.Entity, activator ) ) then
+ if ( OutputList[ idx ] and !FireSingleOutput( OutputList[ idx ], self.Entity, activator, data ) ) then
- self.Outputs[name][idx] = nil
+ self.Outputs[ name ][ idx ] = nil
end

0 comments on commit 8fef618

Please sign in to comment.