1. 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:

    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);
                    }
                }
            }
    It gets to outputting 2 in the console, then results in an object NRE when I shoot down a helicopter.
    Any idea what I am doing wrong?
     
    Last edited by a moderator: Jun 19, 2016
  2. 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
     
  3. @k1lly0u
    Yeah I wasn't sure when looking through my references.
    I will see what I can come up with, cheers dude.
     
  4. Notifier also displays players getting killed by helis, you could have a look at that.
     
  5. 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?
     
  6. You only need to store a single player to keep track of the last attacker, why use a list at all?
     
  7. It was the first solution that came to mind. What method would you suggest?
     
  8. Just storing the last player.
     
  9. So perhaps a var that is accessible from all scopes and have that change each time the helicopter takes damage?
     
  10. Ok I declared BasePlayer LastHitPlayer null in the plugin scope, every time the helicopter gets hit LastHitPlayer = (BasePlayer)info.Initiator.
    Then LastHitPlayer.displayName replaces {playername} in the message sent in OnEntityDeath.

    Thanks for the help @k1lly0u and @sqroot