mkafrin / PolyZone

PolyZone is a FiveM mod to define zones of different shapes and test whether a point is inside or outside of the zone
MIT License
202 stars 193 forks source link

Add onEntityDamaged helper #11

Closed mkafrin closed 4 years ago

mkafrin commented 4 years ago

This helper is mostly to easily allow the caller to destroy an entity zone when the entity dies or is destroyed. But might as well generalize it to all damage.

This is really efficient because it can piggyback off of the CEvent "game events" that are triggered (meaning no on-frame check). Specifically, the event is "CEventNetworkEntityDamage", which includes "victim" at arg[1], "attacker" at arg[2], "victimDied" at arg[4], "weaponHash" at arg[5], "isMelee" at arg[10], and "vehicleDamageTypeFlag" at arg[11].

My thoughts on an api is:

zone:onEntityDamaged(function(entityDied, attacker, weaponHash, isMelee)
    print("stuff here")
end)

and the main use would be:

zone:onEntityDamaged(function(entityDied)
    if entityDied then zone:destroy() end
end)

Honestly, given the lack of anyone upgrading yet, might be a good idea to just slot this into 1.2.

Sources: https://vespura.com/fivem/damageevents/ https://github.com/DevTestingPizza/DamageEvents/blob/v1.0.0/DamageEvents/DamageEvents.cs#L188