Page 1 of 1

scanForNearestShipWithRole: player - Does it work and how?

Posted: Tue Jan 16, 2007 1:39 pm
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?

Posted: Tue Jan 16, 2007 2:48 pm
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");     }; 
}


Posted: Tue Jan 16, 2007 7:37 pm
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.

Posted: Tue Jan 16, 2007 9:35 pm
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 = (); 
    }; 
}

Posted: Thu Jan 18, 2007 4:37 pm
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: