OnEntityLeave vs. OnEntityKill

I want to inform the players, that the Patrolheli was killed or the Patrolheli has leaved the island. Sounds easy ... but in this case i always got the information that the Heli was killed although it just leaves the island... pls. help! 😩

void Broadcast(string msg, params object[] args)
{
    PrintToChat(msg, args);
}

void OnEntityLeave(TriggerBase trigger, BaseEntity entity)
{
    if (entity is BaseHelicopter)
    {
        Broadcast("Patrolheli leaves.");
    }
}

void OnEntityKill(BaseNetworkable entity)
{
    if (entity is BaseHelicopter)
    {
        Broadcast("Patrolheli was killed.");
    }
}

OnEntityLeave is called when an entity leaves a trigger not when they are leaving the map. Instead you should use:

object OnHelicopterRetire(PatrolHelicopterAI helicopter)
{
    Puts("OnHelicopterRetire works!");
    return null;
}

OnEntityKill is called every time an entity is killed, this is being called when the helicopter leaves because the helicopter leaves the map and is then destroyed.



Merged post

Also some additional comments:
- the wrapper for PrintToChat is unnecessary
- you can parse the type in the hook signature e.g.

 

void OnEntityKill(BaseHelicopter entity)
{
    //send chat message.
}​
@0x89A: Thanks! That helps me a lot.
hqroim8Msfq2wXh.jpg DrDBug
@0x89A: Thanks! That helps me a lot.

No problem. The OnHelicopterRetire hook wasn't in the hook docs at the time so I'm not surprised you missed it. It's been added now though :)