lukrop / GCICAP

Autonomous GCI and CAP script for DCS: World.
Other
7 stars 1 forks source link

despawn Handler #12

Closed Quax456 closed 8 years ago

Quax456 commented 8 years ago

Your despawnhandler has some havy disadvanteges.

  1. When a player leaves an AC it will throw the event DEAD and PLAYER_LEAVE_UNIT
  2. Leaving the Spectator and jumping into a Unit causes the EVENT PLAYER_LEAVE_UNIT with the event.initiator = nil
  3. If for any circumstances a ground unit will die your handler will trie to handle it like an Airunit.
lukrop commented 8 years ago

It seems there are some timing issues with those event handlers. There are situation where this snippet:

if (event.id == world.event.S_EVENT_DEAD or
      event.id == world.event.S_EVENT_CRASH or
      event.id == world.event.S_EVENT_ENGINE_SHUTDOWN) and
      event.initiator ~= nil then
      local unit = event.initiator
      local group = unit:getGroup()

throws a error because it can't access getGroup() on a nil object. This means event.initiator becomes nil in the timeframe between two lines. Maybe pulling the group name directly on the event into a different variable and working with that is a option.

Regarding ground units: It actually should not. The handler checks with

local flight = gcicap.Flight.getFlight(group:getName())
-- check if we manage this group
if flight then
...
end

if we don't find a flight for this group we won't do anything.

I think this issue is the same as #10.

lukrop commented 8 years ago

Fixed with 1ce3b5c98ecdb518a9f9b424a4d6c3d7d9493ae6 until proven otherwise.