• Player:LastHitGroup() is always returning 0
    3 replies, posted
I want to recognise if something isn't a head shot in something I am coding. Player:LastHitGroup() has no documentation on the Wiki and I couldn't find any sight of it on code.garrysmod.com either. This is in GM:DoPlayerDeath(); [lua]local LastHitGroup = Player:LastHitGroup(); print( "Hit group: ", LastHitGroup ); if( LastHitGroup != HITGROUP_HEAD ) then print( "Hi" ); end[/lua] Console prints: [code]Hit group: 0 Hi [/code] No matter where I kill my test subject (a bot) either on the torso or the head the result is always the same. Any ideas? Thanks in advance. [editline]09:28PM[/editline] I managed to solve it. Will post it for any future people who find LastHitGroup() to be useless: [lua] function GM:ScalePlayerDamage( Player, HitGroup, DamageInfo ) if( HitGroup == HITGROUP_HEAD ) then Player.ReceivedHeadShot = true; else Player.ReceivedHeadShot = false; end end[/lua] And I then check that boolean in GM:DoPlayerDeath() when I want to see if they died from a head shot or not. Lock/ignore/whatever this. :)
You may want to update the [URL=http://wiki.garrysmod.com/index.php?title=Player.LastHitGroup&action=edit&redlink=1]Wiki[/URL] with your findings. :3
I fixed this in the next update
Thank you very much Garry. :) And I did try and add it to the wiki Unrealomega but the page to Player:LastHitGroup() 404'd so I thought I could at least add it here.
Sorry, you need to Log In to post a reply to this thread.