Hi!
I am trying to get the player's name who got the last shot on a helicopter taking it down.
I have the code:
It gets to outputting 2 in the console, then results in an object NRE when I shoot down a helicopter.Code:void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if (helicopterDeathAnnouncement && entity is BaseHelicopter) { if (helicopterDeathAnnouncementWithKiller) { Puts("1"); BasePlayer attacker = (BasePlayer)info.Initiator; Puts("2"); CreateMsgGUI(Lang("HelicopterDeathAnnouncementWithPlayer").Replace("{playername}", attacker.displayName), bannerTintRed, textWhite); Puts("3"); } else { CreateMsgGUI(Lang("HelicopterDeathAnnouncement"), bannerTintRed, textWhite); } } }
Any idea what I am doing wrong?
Solved Getting player killed helicopter? (C#)
Discussion in 'Rust Development' started by JoeSheep, Jun 19, 2016.
-
The HitInfo doesn't contain a Initiator for downed helicopters. I worked around this in Quests by storing each hit from OnEntityTakeDamage then working out who had the highest hitpoints but this could also be done to work out the final attacker
-
@k1lly0u
Yeah I wasn't sure when looking through my references.
I will see what I can come up with, cheers dude. -
-
At the moment I have a list which will store a player's name when they attack the heli, OnEntityDeath will get the last item in the list and use that. Seems a little bit of a perhaps slow way to do it, unless I can use a hashset as long as it just adds on to the list at the bottom so I can still get the last item as the last player to hit the heli?
-
-
-
-