scanForNearestShipWithRole: player - Does it work and how?

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
Dr. Nil
---- E L I T E ----
---- E L I T E ----
Posts: 983
Joined: Thu Sep 28, 2006 5:11 pm
Location: Nearest Hoopy Casino
Contact:

scanForNearestShipWithRole: player - Does it work and how?

Post by Dr. Nil »

Code: Select all

    "THE_STATE_WHICH_DOESNT_WORK" = {
		ENTER = ("setDesiredRangeTo: 30000.0", "scanForNearestShipWithRole: player");
	"TARGET_FOUND" = (setTargetToFoundTarget, "commsMessage: [a_message_in_descriptions_works_fine]", "setStateTo: THE_NEXT_STAGE_WHICH_WORKS_FINE" ); 
        "INCOMING_MISSILE" = (fireECM); 
		UPDATE = ("pauseAI: 10.0");
		EXIT = ();
	}; 


    GLOBAL = {ENTER = (performHold, "setStateTo: THE_STATE_WHICH_DOESNT_WORK"); EXIT = (); UPDATE = (); }; 
I don't seem to be able to get an AI to return a "TARGET_FOUND" to the "scanForNearestShipWithRole: player" in this piece. Why not?
Image

300 billboards in Your Ad Here!
Astromines and more in Commies.
AVAILABLE HERE along with other Oolite eXpansion Packs.
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2882
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

Odd. I've used the same trick in the imaginatley titled "killplayerAI" in assassins and it works fine (although I'm having it switch to Attack ship when it finds a target.) That said, I have included another scanforNearstShipwithRole: Player under the update for each state.

Roberto used this script to send the player a message every so often when he is nearby (and I've shamlessly cribbed it for use in my Black Monk Branch!):-

Code: Select all


IDLE = { 
        ATTACKED = (setTargetToPrimaryAggressor, increaseAlertLevel, launchDefenseShip, "sendTargetCommsMessage: [monk-warning]", "setStateTo: DEFENSE_MODE"); 
        "OFFENCE_COMMITTED" = (setTargetToFoundTarget, setTargetToPrimaryAggressor, "markTargetForOffence: 15", launchDefenseShip, increaseAlertLevel); 
        ENTER = (); 
        EXIT = (); 
        "INCOMING_MISSILE" = (fireECM, increaseAlertLevel, setTargetToPrimaryAggressor, launchDefenseShip, "sendTargetCommsMessage: [monk-warning]", "setStateTo: DEFENSE_MODE"); 
        "TARGET_FOUND" = (setTargetToFoundTarget, "pauseAI: 5.0", "sendTargetCommsMessage: [monk-greeting]", "pauseAI: 120.0"); 
        UPDATE = ("scanForNearestShipWithRole: player");     }; 
}

OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
User avatar
Dr. Nil
---- E L I T E ----
---- E L I T E ----
Posts: 983
Joined: Thu Sep 28, 2006 5:11 pm
Location: Nearest Hoopy Casino
Contact:

Post by Dr. Nil »

Yeah. It is strange. I had already tried with and without repeating the scan in the update without luck. :?

I've used it with code taken from Murgh before with no problems and it works fine in those other oxps.
Image

300 billboards in Your Ad Here!
Astromines and more in Commies.
AVAILABLE HERE along with other Oolite eXpansion Packs.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2483
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

Hi Doc
here's a simple AI script i use when testing out angry ships, the script just scans for the players ship and attacks it on sight, i added a sendTargetCommsMessage to the script after spotting this thread to see if it worked and it does seem to, have you tried this command in your script instead of the commsMessage you are currently using?

Code: Select all

{
"ATTACK_SHIP" = {
        ENTER = (performAttack); 
        "ATTACKED" = (setTargetToPrimaryAggressor); 
        "INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, "setStateTo: ATTACK_SHIP");
        "TARGET_DESTROYED" = ("setStateTo: LOOK_FOR_TARGETS"); 
        "TARGET_LOST" = ("setStateTo: LOOK_FOR_TARGETS"); 
        EXIT = (); 
	  UPDATE = (performAttack); 
     };

"LOOK_FOR_TARGETS" = {
ENTER = ("setDesiredRangeTo: 25.0", "scanForNearestShipWithRole: player");
        "ATTACKED" = (setTargetToPrimaryAggressor, "setStateTo: ATTACK_SHIP"); 
        "INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, "setStateTo: ATTACK_SHIP"); 
		"TARGET_FOUND" = (setTargetToFoundTarget, "sendTargetCommsMessage: I see you!", "setStateTo: ATTACK_SHIP"); 
        	"NOTHING_FOUND" = (performIdle); 
EXIT = ();
	UPDATE = ("scanForNearestShipWithRole: player", "pauseAI: 10.0");
	}; 
  
GLOBAL = {
        ENTER = ("setStateTo: LOOK_FOR_TARGETS"); 
        EXIT = (); 
        UPDATE = (); 
    }; 
}
User avatar
Dr. Nil
---- E L I T E ----
---- E L I T E ----
Posts: 983
Joined: Thu Sep 28, 2006 5:11 pm
Location: Nearest Hoopy Casino
Contact:

Post by Dr. Nil »

Thanks.

When I couldn't even get this piece to work, I had to act on an earlier suspicion I had dismissed straight away.

:lol: :oops: :roll: :lol: :oops: :oops:

I should never use a ship which I have forgotten to give the role "player" for playtesting anything which involves "scanForNearestShipWithRole: player".

I should never use a ship which I have forgotten to give the role "player" for playtesting anything which involves "scanForNearestShipWithRole: player".

I should never use a ship which I have forgotten to give the role "player" for playtesting anything which involves "scanForNearestShipWithRole: player".

I should never use a ship which I have forgotten to give the role "player" for playtesting anything which involves "scanForNearestShipWithRole: player".

And once more:

I should never use a ship which I have forgotten to give the role "player" for playtesting anything which involves "scanForNearestShipWithRole: player".

:oops:
Image

300 billboards in Your Ad Here!
Astromines and more in Commies.
AVAILABLE HERE along with other Oolite eXpansion Packs.
Post Reply