Skip to content

Commit

Permalink
Entities: Replaced self.BaseClass with BaseClass (#1373)
Browse files Browse the repository at this point in the history
To prevent future issues with inheritance (stack overflow) entities now
use DEFINE_BASECLASS as well
  • Loading branch information
TimGoll authored Feb 5, 2024
1 parent 6d3d51f commit a52f830
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gamemodes/terrortown/entities/entities/base_ammo_ttt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENT.AmmoType = "Pistol"
ENT.AmmoAmount = 1
ENT.AmmoMax = 10
ENT.AmmoEntMax = 1
ENT.Model = Model("models/items/boxsrounds.mdl")
ENT.Model = "models/items/boxsrounds.mdl"

---
-- bw compat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ if SERVER then
AddCSLuaFile()
end

DEFINE_BASECLASS("base_ammo_ttt")

ENT.Type = "anim"
ENT.Base = "base_ammo_ttt"
ENT.AmmoType = "AlyxGun"
ENT.AmmoAmount = 12
ENT.AmmoMax = 36
ENT.Model = Model("models/items/357ammo.mdl")
ENT.Model = "models/items/357ammo.mdl"
ENT.AutoSpawnable = true
ENT.spawnType = AMMO_TYPE_DEAGLE

Expand All @@ -17,5 +19,5 @@ function ENT:Initialize()
-- Differentiate from rifle ammo
self:SetColor(Color(255, 100, 100, 255))

return self.BaseClass.Initialize(self)
return BaseClass.Initialize(self)
end
4 changes: 3 additions & 1 deletion gamemodes/terrortown/entities/entities/ttt_beacon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if SERVER then
AddCSLuaFile()
end

DEFINE_BASECLASS("ttt_base_placeable")

if CLIENT then
ENT.Icon = "vgui/ttt/icon_beacon"
ENT.PrintName = "Beacon"
Expand All @@ -28,7 +30,7 @@ local beaconDetectionRange = 135
function ENT:Initialize()
self:SetModel(self.Model)

self.BaseClass.Initialize(self)
BaseClass.Initialize(self)

if SERVER then
self:SetMaxHealth(100)
Expand Down
8 changes: 5 additions & 3 deletions gamemodes/terrortown/entities/entities/ttt_c4/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- bomb menus

DEFINE_BASECLASS("ttt_base_placeable")

include("shared.lua")

local starttime = C4_MINIMUM_TIME
Expand Down Expand Up @@ -186,7 +188,7 @@ local wire_colors = {
---
-- @realm client
function WIREPANEL:Init()
self.BaseClass.Init(self)
BaseClass.Init(self)

self:NoClipping(true)
self:SetMouseInputEnabled(true)
Expand Down Expand Up @@ -234,7 +236,7 @@ end
---
-- @realm client
function WIREPANEL:OnCursorExited()
self.PaintOver = self.BaseClass.PaintOver
self.PaintOver = BaseClass.PaintOver
end

---
Expand All @@ -246,7 +248,7 @@ function WIREPANEL:DoClick()

self.IsCut = true

self.PaintOver = self.BaseClass.PaintOver
self.PaintOver = BaseClass.PaintOver

self.m_Image:SetMaterial(c4_wirecut_mat)

Expand Down
6 changes: 4 additions & 2 deletions gamemodes/terrortown/entities/entities/ttt_c4/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ if SERVER then
AddCSLuaFile("shared.lua")
end

DEFINE_BASECLASS("ttt_base_placeable")

if CLIENT then
-- this entity can be DNA-sampled so we need some display info
ENT.Icon = "vgui/ttt/icon_c4"
Expand Down Expand Up @@ -72,7 +74,7 @@ ENT.safeWires = nil
-- Initializes the data
-- @realm shared
function ENT:SetupDataTables()
self.BaseClass.SetupDataTables(self)
BaseClass.SetupDataTables(self)

self:NetworkVar("Int", 0, "ExplodeTime")
self:NetworkVar("Bool", 0, "Armed")
Expand All @@ -84,7 +86,7 @@ end
function ENT:Initialize()
self:SetModel(self.Model)

self.BaseClass.Initialize(self)
BaseClass.Initialize(self)

if SERVER then
self:SetUseType(SIMPLE_USE)
Expand Down
4 changes: 3 additions & 1 deletion gamemodes/terrortown/entities/entities/ttt_cse_proj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if SERVER then
AddCSLuaFile()
end

DEFINE_BASECLASS("ttt_base_placeable")

ENT.Base = "ttt_base_placeable"
ENT.Model = "models/Items/battery.mdl"

Expand All @@ -24,7 +26,7 @@ ENT.CanUseKey = true
function ENT:Initialize()
self:SetModel(self.Model)

self.BaseClass.Initialize(self)
BaseClass.Initialize(self)

self:SetSolid(SOLID_VPHYSICS)

Expand Down
4 changes: 3 additions & 1 deletion gamemodes/terrortown/entities/entities/ttt_decoy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ if SERVER then
AddCSLuaFile()
end

DEFINE_BASECLASS("ttt_base_placeable")

ENT.Base = "ttt_base_placeable"
ENT.Model = "models/props_lab/reciever01b.mdl"
ENT.CanHavePrints = false
Expand All @@ -18,7 +20,7 @@ ENT.CanUseKey = true
function ENT:Initialize()
self:SetModel(self.Model)

self.BaseClass.Initialize(self)
BaseClass.Initialize(self)

if SERVER then
self:SetMaxHealth(100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
-- @class ENT
-- @section ttt_firegrenade_proj

AddCSLuaFile()
if SERVER then
AddCSLuaFile()
end

DEFINE_BASECLASS("ttt_basegrenade_proj")

ENT.Type = "anim"
ENT.Base = "ttt_basegrenade_proj"
Expand All @@ -22,7 +26,7 @@ function ENT:Initialize()
self:SetDmg(25)
end

return self.BaseClass.Initialize(self)
return BaseClass.Initialize(self)
end

---
Expand Down
10 changes: 7 additions & 3 deletions gamemodes/terrortown/entities/entities/ttt_health_station.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

if SERVER then
AddCSLuaFile()
else
end

DEFINE_BASECLASS("ttt_base_placeable")

if CLIENT then
ENT.Icon = "vgui/ttt/icon_health"
ENT.PrintName = "hstation_name"
end
Expand All @@ -27,7 +31,7 @@ ENT.HealFreq = 0.2
---
-- @realm shared
function ENT:SetupDataTables()
self.BaseClass.SetupDataTables(self)
BaseClass.SetupDataTables(self)

self:NetworkVar("Int", 0, "StoredHealth")
end
Expand All @@ -37,7 +41,7 @@ end
function ENT:Initialize()
self:SetModel(self.Model)

self.BaseClass.Initialize(self)
BaseClass.Initialize(self)

local b = 32

Expand Down
8 changes: 6 additions & 2 deletions gamemodes/terrortown/entities/entities/ttt_radio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

if SERVER then
AddCSLuaFile()
else
end

DEFINE_BASECLASS("ttt_base_placeable")

if CLIENT then
-- this entity can be DNA-sampled so we need some display info
ENT.Icon = "vgui/ttt/icon_radio"
ENT.PrintName = "radio_name"
Expand All @@ -25,7 +29,7 @@ ENT.SoundDelay = 0.5
function ENT:Initialize()
self:SetModel(self.Model)

self.BaseClass.Initialize(self)
BaseClass.Initialize(self)

if SERVER then
self:SetMaxHealth(40)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
-- @class ENT
-- @section ttt_smokegrenade_proj

AddCSLuaFile()
if SERVER then
AddCSLuaFile()
end

DEFINE_BASECLASS("ttt_basegrenade_proj")

ENT.Type = "anim"
ENT.Base = "ttt_basegrenade_proj"
Expand All @@ -17,7 +21,7 @@ function ENT:Initialize()
self:SetRadius(20)
end

return self.BaseClass.Initialize(self)
return BaseClass.Initialize(self)
end

if CLIENT then
Expand Down

0 comments on commit a52f830

Please sign in to comment.