Garry's Mod Wiki

Entity:AddSpawnFlags

  Entity:AddSpawnFlags( number flag )

Recently Added

This was recently added in version (2024.12.04). It might only be available on the Dev Branch right now.

Description

Adds onto the current SpawnFlags of an Entity.

SpawnFlags can easily be found on https://developer.valvesoftware.com/wiki/.

Arguments

1 number flag
The SpawnFlag to add to the Entity

Example

When a turret Entity is created, it adds the Out of Ammo SpawnFlag, therefore it doesn't have ammo.

hook.Add( "OnEntityCreated", "AddSpawnFlagsExample", function( ent ) timer.Simple( 0.1, function() if ( !IsValid(ent) or ent:GetClass() != "npc_turret_floor" ) then return end ent:AddSpawnFlags(256) -- https://developer.valvesoftware.com/wiki/Npc_turret_floor#Flags end ) end )

Example

When a turret Entity is created, it adds the Out of Ammo and Fast Retire SpawnFlag, therefore it doesn't have ammo and it goes into idle state faster.

hook.Add( "OnEntityCreated", "AddSpawnFlagsExample", function( ent ) timer.Simple( 0.1, function() if ( !IsValid(ent) or ent:GetClass() != "npc_turret_floor" ) then return end ent:AddSpawnFlags(256 + 128) -- https://developer.valvesoftware.com/wiki/Npc_turret_floor#Flags end ) end )