PDA

View Full Version : [SNIPPET] TF2 deathflags


r5053
06-06-2009, 12:34
new deathflags = GetEventInt(event, "death_flags")
new bool:nofakekill = true
new bool:df_firstblood = false
new bool:df_assisterrevenge = false
new bool:df_killerrevenge = false
new bool:df_assisterdomination = false
new bool:df_killerdomination = false

if (deathflags >= 32)
{
deathflags = deathflags - 32
nofakekill = false
}
if (deathflags >= 16)
{
deathflags = deathflags - 16
df_firstblood = true
}
if (deathflags >= 8)
{
deathflags = deathflags - 8
df_assisterrevenge = true
}
if (deathflags >= 4)
{
deathflags = deathflags - 4
df_killerrevenge = true
}
if (deathflags >= 2)
{
deathflags = deathflags - 2
df_assisterdomination = true
}
if (deathflags == 1)
{
df_killerdomination = true
}

psychonic
06-06-2009, 12:38
Why all the extra math instead of just checking the bits?
#define killerdomination (1 << 0)
#define assisterdomination (1 << 1)
#define killerrevenge (1 << 2)
#define assisterrevenge (1 << 3)
#define firstblood (1 << 4)
#define feigndeath (1 << 5)

Ex.
if (deathflags & firstblood) {
//firstblood
}

r5053
06-08-2009, 15:59
damn doku, searched for this but found nothing

r5053
06-08-2009, 16:06
found !!!:

These two operators are also important, but not used often. They are the bitwise shift operators, << is a left shift and >> is a right shift. They shift the bits in a number to one direction.
//This takes the number 3 (00011) and shifts it three places to binary (11000), or 24.
(3 << 3)
//This takes the number 24 (11000) and shifts it three places to binary (00011), or 3.
(24 >> 3)

r5053
06-08-2009, 16:12
ok ... found this:

//4 (00100) is not a bit inside 16 (10000) and this will return 0.
(16 & 4)

means the correct code to check for killerrevenge is:

#define killerrevenge 4

if (deathflag & killerrevenge)

(as example)
I think this is better readable