• Problem with GetDamageType( )
    2 replies, posted
Hello, I try to make a Damage Indicator but my problem is this. In wiki you see for example DMG_BULLET = 2 but when I shoot with pistol it says in info:GetDamageType() 4098 Why?? How Do I fix it I wanted use table.HasValue. Example [CODE] local damagetyp1 = {DMG_BULLET} if table.HasValue(damagetype1 , DamageType) then --bullet end [/CODE]
As you can see on the wiki [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb455.html]here[/url], DMG_BULLET is 2 but DMG_NEVERGIB is 4096, so you'd just use '4098' to check if the damage type is by a bullet (Which is equal to 'DMG_BULLET + DMG_NEVERGIB') I'm not massively versed on damage types but I assume that depending on what you use it will add up the different properties of the damage (In this case, bullets never gib, so that is added on) You could do it two ways - [lua]local damagetyp1 = {DMG_BULLET + DMG_NEVERGIB} if table.HasValue(damagetype1 , DamageType) then --bullet end[/lua] [lua]local damagetyp1 = {4098} if table.HasValue(damagetype1 , DamageType) then --bullet end[/lua] *EDIT* Also it would be dandy if you could post in [url]http://www.facepunch.com/forumdisplay.php?f=65[/url] if you have any other questions, it stops this section from being clogged up with help threads. Thanks!
The damage types are binary flags, which allow a DamageInfo object to have more than one damage type. DMG_NEVERGIB has a value of 4096, a binary value of 0001 0000 0000 0000. DMG_BULLET has a value of 2, a binary value of 0000 0000 0000 0010. The damage type you're getting, 4098, is 0001 0000 0000 0010, so it is both DMG_BULLET and DMG_NEVERGIB. You would check whether or not a DamageInfo object has bullet damage by using bitwise operators: [lua] local damageType = info:GetDamageType() if ((damageType & DMG_BULLET) == DMG_BULLET) then --If the result of zeroing any bits that weren't 1 in both damageType and DMG_BULLET (bitwise "and") is equal to DMG_BULLET, then damageType contained all the bits of DMG_BULLET. --dothings end [/lua] [lua] local damageType = info:GetDamageType() if ((damageType | DMG_BULLET) == damageType) then --If the result of combining every bit that was 1 in either damageType or DMG_BULLET (bitwise "or") was equal to damageType, then damageType contained all the bits of DMG_BULLET. --dothings end [/lua] Either way is perfectly valid for testing binary flags. Note that bitwise "and" is &, not to be confused with &&, which is the logical "and". The same goes for bitwise "or", which is |, and logical "or", which is ||. And, since I just remembered the most simple solution, you can just use damageType:IsDamageType(DMG_BULLET) instead of testing the binary flags manually.
Sorry, you need to Log In to post a reply to this thread.