KaukausInsurgency / ki-dcs

Kaukasus Insurgency
5 stars 2 forks source link

Heli still has cargo after death #140

Closed Igneous01 closed 6 years ago

Igneous01 commented 6 years ago

If you load troops into heli. Then die / reslot into same spot, you still have cargo in your helicopter. This should be reset when you reslot.

Igneous01 commented 6 years ago

Proposed fix in KI.Hooks.GameEventHandler:onEvent

elseif event.id == world.event.S_EVENT_CRASH or
        event.id == world.event.S_EVENT_DEAD or
        event.id == world.event.S_EVENT_EJECTION or
        event.id == world.event.S_EVENT_PILOT_DEAD or
        event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT then
        env.info("KI.Hooks.GameEventHandler - DEATH EVENT")

        -- doing something sneaky - modify the event object so that if the unit that died is AI, add a .target property and set it to the AI unit that died - this will capture the category, unit type information and store it in the target columns, rather than the player columns (we'll set those to "AI")
        if not playerName then
          event.target = event.initiator
        end

        table.insert(KI.Data.GameEventQueue,
          GameEvent.CreateGameEvent(KI.Data.SessionID,
            KI.Data.ServerID,
            event,
            timer.getTime())
        )

        -- if a helicopter died/left slot remove the cargo contents from the heli
        SLC.TransportInstances[event.initiator:getName()] = nil
        return