Garry's Mod Wiki

WEAPON:Initialize

WEAPON:Initialize()

Description

Called when the weapon entity is created.

Entity:GetOwner will return NULL at this point because the weapon is not equpped by a player or NPC yet. Use WEAPON:Equip or WEAPON:Deploy if you need the owner to be valid.
This is sometimes not called clientside. You can work around this by setting a variable in Initialize and check if it exists in WEAPON:Think. See the example below.
This is not called serverside after a quicksave.

Example

Sets the weapon hold type to SWEP.HoldType.

function SWEP:Initialize() self:SetHoldType( self.HoldType ) end

Example

Fixes the function not being called clientside.

function SWEP:Initialize() self.m_bInitialized = true -- Other code end function SWEP:Think() if (not self.m_bInitialized) then self:Initialize() end -- Other code end

Page Links


Special Pages


Wikis

?

Render Time: 26ms

Session 0
DB GetPage 5
Generate Html 3
SaveChanges 10
Render Body 0
Render Sidebar 6