Skip to content

Understanding Bitwise Operations and Spawnflags

Derpduck edited this page Jan 5, 2021 · 29 revisions

<- (Previous) Viewing Changes In Game | Ladder Modification (Next) ->

Bitwise Operations and Spawnflags

A bitwise operation operates on a bit string at the level of individual bits. The spawnflags property of an entity uses a bit string value to determine which flags are on and off. Each flag has a unique value that when enabled increases the spawnflags value by a set amount. An understanding of how binary and bits work is helpful for understanding this concept, however it can be shown by example.

Spawnflags use a base-2 system, or a binary numeral system. This means that each value, or bit, is a power of 2. Example:

2= 1   |  2^0 = 1
2¹ = 2   |  2^1 = 2
2² = 4   |  2^2 = 4
2³ = 8   |  2^3 = 8
2= 16  |  2^4 = 16

For example, the weapon_item_spawn entity has 3 possible spawnflags:

1 : Enable Physics on spawned item
2 : Spawned Item Must Exist
8 : Infinite Items

The number represents the value spawnflags is increased by when the flag is enabled.
So a spawnflags value of 2 would mean: the item must exist.
A spawnflags value of 9 would mean: physics is enabled AND there is an infinite amount of the item (flags 1 + 8).

However, the Windows 10 calculator actually has a very useful feature for visualizing this:

  1. Open the Calculator app.
  2. Click the dropdown, and select Programmer.
  1. Select DEC for decimal.
  1. Select the Bit toggling keypad.
  1. You will now see this display, each 0 represents a bit. Starting from the bottom right, click one of the bits to toggle it.
    • The value under each set of bits is the power of 2 that bit represents.
  1. This will increase the overall value by the value of that bit.

For example, these bits represent the spawnflags value in our second example:

Now you can experiment with this to understand bitwise operations and how to calculate the spawnflags value.

Setting Spawnflags in Hammer Editor

Next, it is useful to know how spawnflags are presented in Hammer, how they are set, and how to find the spawnflags value of an entity.

  1. Open Hammer Editor and create an entity.
  2. Make the entity a prop_car_alarm and select the Flags tab. These are all of the spawnflags that can be changed on this type of entity.
1 : Start Asleep.
2 : Dont take physics damage.
4 : Debris - Dont collide with the player or other debris.
8 : Motion Disabled.
64 : Enable motion when grabbed by gravity gun.
128 : Not affected by rotor wash.
256 : Generate output on +use.
512 : Prevent pickup.
1024 : Prevent motion enable on player bump.
4096 : Debris with trigger interaction.
8192 : Force server-side (Multiplayer only; see sv_pushaway_clientside_size)
1048576 : Gravity gun can ALWAYS pick up. No matter what.
16 : Break on Touch
32 : Break on Pressure
// Not listed on wiki
32768 : Enable +use glow effect

NOTE: Spawnflags are not always in order of value in Hammer, and some entities have gaps between values in their flags (skipping powers of 2), and some flags have no effect in L4D2 due to being legacy flags from Half-Life.

  1. Select the Class Info tab, and click the SmartEdit button. This will expose the spawnflags parameter. You can now change the flags to the desired values and copy the value of the spawnflags property.

Clone this wiki locally