Author Topic: explosion listener  (Read 801 times)

Offline Nighthawk

  • |______[o]_|
  • Posts: 750
  • Cookies: 18
explosion listener
« on: August 22, 2007, 03:58:15 PM »
what instruction should I use to get the object that is exploding when listening to ET_OBJECT_EXPLODING?

pEvent.GetDestination() or pEvent.GetSource()?

if I use:

Code: [Select]
import MissionLib
import TacticalInterfaceHandlers

def init():
        pGame        = App.Game_GetCurrentGame()
        pEpisode = pGame.GetCurrentEpisode()
        pMission = pEpisode.GetCurrentMission()
        App.g_kEventManager.AddBroadcastPythonFuncHandler(App.ET_OBJECT_EXPLODING, pMission, __name__ + ".EvaluateTarget")

def EvaluateTarget(pObject, pEvent):
     pShip = App.ShipClass_Cast(pEvent.GetDestination())
     pPlayerTarget = App.ShipClass_Cast(MissionLib.GetPlayer().GetTarget())
     if pShip == pPlayerTarget:
           TacticalInterfaceHandlers.TargetNearest()
           print "passed 1"
     else:
           print pShip
           print pPlayerTarget


pShip outputs None, but pPlayerTarget does output a Ship instance.

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: explosion listener
« Reply #1 on: August 22, 2007, 06:41:51 PM »
Which means that GetDestination is at the very least not a ShipClass. ;)

Considering the semantics, I'd say that you need GetSource().
But, a little search for App.ET_OBJECT_EXPLODING revealed this line in MissionLib.py:
Code: [Select]
pDyingObject = App.DamageableObject_Cast(pEvent.GetDestination())If pDyingObject (pShip in your case) is not None, then do the following comparison:
Code: [Select]
if pShip.GetObjID() == pPlayerTarget.GetObjID():On the other hand, in the missions they are all using App.ShipClass_Cast (and GetDestination).

So, before I confuse you even more, try a couple of times with different casts (work your way up from ShipClass, or lower, depending on your view on the class inheritance model).
In case you don't know what I'm talking about, DamageableObject is the super class of ShipClass (ShipClass inherits from DamageableObject).

It's also possible that the event isn't firing for the ship, but for the projectile.
Add a pObject.CallNextHandler(pEvent) at the bottom of the function (not in any of the if branches), or at the very top (I think it's easier, in this instance, to do it at the bottom, from a readability perspective).
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline Nighthawk

  • |______[o]_|
  • Posts: 750
  • Cookies: 18
Re: explosion listener
« Reply #2 on: August 22, 2007, 11:34:59 PM »
So, before I confuse you even more, try a couple of times with different casts (work your way up from ShipClass, or lower, depending on your view on the class inheritance model).
In case you don't know what I'm talking about, DamageableObject is the super class of ShipClass (ShipClass inherits from DamageableObject).
don't worry, I do understand that.
in fact, those lines are copied from a KM 1.0 script, precisely, a handler for explosions.

It's also possible that the event isn't firing for the ship, but for the projectile.
Add a pObject.CallNextHandler(pEvent) at the bottom of the function (not in any of the if branches), or at the very top (I think it's easier, in this instance, to do it at the bottom, from a readability perspective).
well, I didn't think on that the first time. actually, I destroyed my target by torpedoes and pulses.
I'll try with a phaser and see what happens.
should I try to filter if the exploding thing IS a ship?

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: explosion listener
« Reply #3 on: August 23, 2007, 11:13:59 AM »
I think you should start by adding pObject.CallNextHandler(pEvent) to the bottom. ;)

And you are filtering it, through the App.ShipClass_Cast
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.