Skip to content

Commit

Permalink
Minor changes in the effects core (#3174)
Browse files Browse the repository at this point in the history
Doesn't create new vectors/angles and also formats the code a bit
  • Loading branch information
Astralcircle authored Nov 9, 2024
1 parent 2c98046 commit f73616c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lua/entities/gmod_wire_expression2/core/custom/effects.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
E2Lib.RegisterExtension("effects", false, "Allows E2s to play arbitrary effects.")

local wire_expression2_effect_burst_max = CreateConVar( "wire_expression2_effect_burst_max", 4, {FCVAR_ARCHIVE} )
local wire_expression2_effect_burst_rate = CreateConVar( "wire_expression2_effect_burst_rate", 0.1, {FCVAR_ARCHIVE} )
local wire_expression2_effect_burst_max = CreateConVar("wire_expression2_effect_burst_max", 4, FCVAR_ARCHIVE)
local wire_expression2_effect_burst_rate = CreateConVar("wire_expression2_effect_burst_rate", 0.1, FCVAR_ARCHIVE)

-- Use hook Expression2_CanEffect to blacklist/whitelist effects
local effect_blacklist = {
Expand Down Expand Up @@ -53,14 +53,14 @@ end
e2function effect effect:setOrigin(vector pos)
if not this then return self:throw("Invalid effect!", nil) end

this:SetOrigin(Vector( pos[1], pos[2], pos[3] ))
this:SetOrigin(pos)
return this
end

e2function effect effect:setStart(vector pos)
if not this then return self:throw("Invalid effect!", nil) end

this:SetStart(Vector( pos[1], pos[2], pos[3] ))
this:SetStart(pos)
return this
end

Expand All @@ -74,7 +74,7 @@ end
e2function effect effect:setAngles(angle ang)
if not this then return self:throw("Invalid effect!", nil) end

this:SetAngles( Angle( ang[1] ,ang[2] ,ang[3] ))
this:SetAngles(ang)
return this
end

Expand All @@ -96,7 +96,7 @@ end
e2function effect effect:setNormal(vector norm)
if not this then return self:throw("Invalid effect!", nil) end

this:SetNormal(Vector( norm[1], norm[2], norm[3] ))
this:SetNormal(norm)
return this
end

Expand Down Expand Up @@ -151,8 +151,8 @@ end

e2function effect effect:setColor(number index)
if not this then return self:throw("Invalid effect!", nil) end
index = math.Clamp(index,0,255)
this:SetColor(index)

this:SetColor(math.Clamp(index, 0, 255))
return this
end

Expand All @@ -169,7 +169,7 @@ e2function void effect:play(string name)

name = name:lower()
if effect_blacklist[name] then return self:throw("This effect is blacklisted!", nil) end
if hook.Run( "Expression2_CanEffect", name, self ) == false then return self:throw("A hook prevented this function from running", nil) end
if hook.Run("Expression2_CanEffect", name, self) == false then return self:throw("A hook prevented this function from running", nil) end

fire(self, this, name)
end
Expand All @@ -181,12 +181,11 @@ end
e2function number effectCanPlay(string name)
if not isAllowed(self) then return 0 end
if effect_blacklist[name] then return 0 end
if hook.Run( "Expression2_CanEffect", name:lower(), self ) == false then return 0 end
if hook.Run("Expression2_CanEffect", name:lower(), self) == false then return 0 end

return 1
end


registerCallback("construct", function(self)
self.data.effect_burst = wire_expression2_effect_burst_max:GetInt()
end)

0 comments on commit f73616c

Please sign in to comment.