-
Notifications
You must be signed in to change notification settings - Fork 8
Understanding 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
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.
However, the Windows 10 calculator actually has a very useful feature for visualizing this:
- Open the Calculator app.
- Click the
≡
dropdown, and selectProgrammer
.
- Select
DEC
for decimal.
- Select the
Bit toggling keypad
.
- You will now see this display, each
0
represents abit
. 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.
- 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.
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.
- Open Hammer Editor and create an entity.
- See the basic Hammer guide if you don't know how.
- Make the entity a
prop_car_alarm
and select theFlags
tab. https://i.imgur.com/lU011Yl.png
1: Start Asleep.
2: Don't take physics damage.
4: Debris - Don't 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.
on the class info tab, click the SmartEdit
button to toggle it off, this will expose the value of spawnflags
https://i.imgur.com/l92BkwT.png
https://i.imgur.com/N7gEgz1.png
Note that spawnflags are not always in order in hammer, and some entities have gaps between their flags, i.e. the values can skip powers of 2