Skip to content

Commit

Permalink
safeguard all terraformer funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Doridian committed Mar 25, 2024
1 parent e08e858 commit 944db4b
Showing 1 changed file with 49 additions and 31 deletions.
80 changes: 49 additions & 31 deletions lua/sa/environment/server/terraformer_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,58 @@ local function SA_Terraformer_PushAtmosphere(terent, resName, atmoname, amount)
end

local function SA_Terraformer_Sparks(terent)
local Rep = ents.Create("point_tesla")
Rep:SetKeyValue("targetname", "teslab")
Rep:SetKeyValue("m_SoundName", "DoSpark")
Rep:SetKeyValue("texture", "sprites/physbeam.spr")
Rep:SetKeyValue("m_Color", "200 200 255")
Rep:SetKeyValue("m_flRadius", 1000)
Rep:SetKeyValue("beamcount_min", 2)
Rep:SetKeyValue("beamcount_max", 5)
Rep:SetKeyValue("thick_min", 2)
Rep:SetKeyValue("thick_max", 8)
Rep:SetKeyValue("lifetime_min", "0.1")
Rep:SetKeyValue("lifetime_max", "0.2")
Rep:SetKeyValue("interval_min", "0.05")
Rep:SetKeyValue("interval_max", "0.08")
local OBBMid = terent:OBBCenter()
local OBBMax = terent:OBBMaxs()
local SparPos = terent:LocalToWorld(Vector(OBBMid.x, OBBMid.y, OBBMax.z))
Rep:SetPos(SparPos)
Rep:Spawn()
Rep:Fire("DoSpark", "", 0)
Rep:Fire("kill", "", 1)
if not IsValid(terent) then
return
end

local Rep = ents.Create("point_tesla")
Rep:SetKeyValue("targetname", "teslab")
Rep:SetKeyValue("m_SoundName", "DoSpark")
Rep:SetKeyValue("texture", "sprites/physbeam.spr")
Rep:SetKeyValue("m_Color", "200 200 255")
Rep:SetKeyValue("m_flRadius", 1000)
Rep:SetKeyValue("beamcount_min", 2)
Rep:SetKeyValue("beamcount_max", 5)
Rep:SetKeyValue("thick_min", 2)
Rep:SetKeyValue("thick_max", 8)
Rep:SetKeyValue("lifetime_min", "0.1")
Rep:SetKeyValue("lifetime_max", "0.2")
Rep:SetKeyValue("interval_min", "0.05")
Rep:SetKeyValue("interval_max", "0.08")
local OBBMid = terent:OBBCenter()
local OBBMax = terent:OBBMaxs()
local SparPos = terent:LocalToWorld(Vector(OBBMid.x, OBBMid.y, OBBMax.z))
Rep:SetPos(SparPos)
Rep:Spawn()
Rep:Fire("DoSpark", "", 0)
Rep:Fire("kill", "", 1)
end

local function SA_Terraformer_Explosion(terent)
local OBBMins = terent:OBBMins()
local OBBMaxs = terent:OBBMaxs()
local vPoint = terent:LocalToWorld(Vector(math.random(OBBMins.x, OBBMaxs.x), math.random(OBBMins.y, OBBMaxs.y), math.random(OBBMins.z, OBBMaxs.z)))
local effectdata = EffectData()
effectdata:SetStart(vPoint)
effectdata:SetOrigin(vPoint)
effectdata:SetScale(1)
effectdata:SetMagnitude(1)
util.Effect("Explosion", effectdata)
if not IsValid(terent) then
return
end

local OBBMins = terent:OBBMins()
local OBBMaxs = terent:OBBMaxs()
local vPoint = terent:LocalToWorld(Vector(math.random(OBBMins.x, OBBMaxs.x), math.random(OBBMins.y, OBBMaxs.y), math.random(OBBMins.z, OBBMaxs.z)))
local effectdata = EffectData()
effectdata:SetStart(vPoint)
effectdata:SetOrigin(vPoint)
effectdata:SetScale(1)
effectdata:SetMagnitude(1)
util.Effect("Explosion", effectdata)
end

function SA.Terraformer.Run(terent)
if not IsValid(terent) then
return
end

local ply = terent:CPPIGetOwner()
if not (ply and ply:IsValid() and ply:IsPlayer()) then return end
if not (ply and ply:IsValid() and ply:IsPlayer()) then
return
end

if terent.environment.IsProtected or (not terent.environment:IsPlanet()) or terent.environment == SA.SB.GetSpace() then return end
local energy = terent:GetResourceAmount("energy")
Expand Down Expand Up @@ -231,6 +245,10 @@ function SA.Terraformer.Run(terent)
end

function SA.Terraformer.SpazzOut(terent, forcekill)
if not IsValid(terent) then
return
end

if terent.FinalSpazzed or terent.environment.IsProtected or (not terent.environment:IsPlanet()) or terent.environment == SA.SB.GetSpace() then return end
local energy = terent:GetResourceAmount("energy")
if terent.State ~= -1 then
Expand Down

0 comments on commit 944db4b

Please sign in to comment.