reactToAIMessage not working?

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

reactToAIMessage not working?

Post by Zieman »

Using Trunk 1.75.4.4621 on WinXP pro 32 bit.

I have this bit of code in the ship script of a pirate ship I'm working on:

Code: Select all

this.shipTargetAcquired = function(target)
	{
		if (target.isPlayer && player.bounty > 0) {this.ship.reactToAIMessage("TARGET_LOST"); this.ship.commsMessage("Oho.")};
	}
In my test setup I get my bounty increased by 10 whenever I jump to another system and these ships are added around witchpoint when emerging from witchspace. The ship script also contains a part that causes those ships hail me if I have a bounty.

I always get those aforementioned hails, no problem there.
But, one or more blips turn quite soon red and they attack me.
At this point this.ship.commsMessage("Oho.") works, but this.ship.reactToAIMessage("TARGET_LOST") seems to do nothing. I even added a commsMessage to pirateAI.plist's "TARGET_LOST" handler of the state "ATTACK_SHIP", but that message is never displayed and the ships keep attacking me.

Is my code defective or why the buggers won't try to find other targets?
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: reactToAIMessage not working?

Post by Capt. Murphy »

Mmm, I think this probably because although your sending the AI the "TARGET_LOST" message the player still actually remains the pirates target and the AI is eventually looping back to attack mode without your handler being fired again, because the pirate is not acquiring a new target.

Try manually nulling the pirate's target rather than sending the AI message. That way if the player is re-targetted your code will fire again. I don't think you need to send the "TARGET_LOST" aswell.

Note that in the pirateAI the target acquisition happens in states "LURK", "TRAVEL_TO_LURK_AREA", and "CLEAR_STATION". Not all of these have actions assigned to "TARGET_LOST" anyway. As your code is firing at target acquisition the pirate isn't I think in the state "ATTACK_SHIP" when you are asking it to react to "TARGET_LOST".

E.g.

Code: Select all

this.shipTargetAcquired = function(target)
   {
      if (target.isPlayer && player.bounty > 0) {this.ship.target = null; this.ship.commsMessage("Oho.")};
   }
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: reactToAIMessage not working?

Post by Zieman »

Thanks Capt. Murphy, your fix works! :)
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
Post Reply