Page 3 of 3
Posted: Sat Nov 13, 2010 2:20 am
by Switeck
I'm at a loss on how to have an AI.plist script check for the player's number of kills...and immediately avoid/flee if you're Dangerous/Deadly/Elite.
Closest I can come up with would be an ODDS check...flee if "ODDS_BAD".
Posted: Sat Nov 13, 2010 10:35 am
by Kaks
The best way to do it is to use a mixture of AI & js. The ship needs to have a custom js script, with a function that generates AI messages the AI is configured to respond to. On the AI side you need something like:
Code: Select all
"TARGET_FOUND" = ( setTargetToFoundTarget, "sendScriptMessage: checkTargetRank");
"TARGET_NOTPLAYER" = (//whatever);
"TARGET_NOOB" = (//oh yeah!);
"TARGET_AVERAGEISH" = (//doable);
"TARGET_RISKY" = (//am I feeling lucky?);
"TARGET_DANGEROUS" = (//run like the wind!);
and on the js side something like
Code: Select all
this.checkTargetRank = function (){
var messageAI = 'TARGET_NOTPLAYER';
var T = this.ship.target;
if (T && T.isPlayer) {
if (T.score < 25) messageAI = 'TARGET_NOOB';
else if (T.score < 100) messageAI = 'TARGET_AVERAGEISH';
else if (T.score < 250) messageAI = 'TARGET_RISKY';
else messageAI = 'TARGET_DANGEROUS';
}
reactToAIMessage(messageAI);
}
Of course you need to replace my (//comments) on the AI side with actual commands, otherwise Oolite will complain!
Note that you can make up the message names! As it's right and proper an AI will only react to the messages it knows about, and they could be named anything you like.
Using this kind of method you could create all sort of behaviours, like pirates that attack you only if you're carring at least 2 tons of computers, or a ragtag band of rusties only attacking other ships if they're carring food supplies, etc...
Posted: Sat Nov 13, 2010 11:50 am
by Commander McLane
Like Kaks said. Not doable via AI alone, but very easy with a ship script. The catch is of course how to attach this script to all pirates.
You can do it in the shipdata of all ships which can have the role "pirate". However, this is impractical, as you would need a shipdata-overrides.plist containing each possible ship, and you would have to release an amended version of your OXP each time somebody releases a new pirate ship. Also you could accidentally override other ship scripts.
So you're left with the second approach, which is to attach your script functions to the existing ship scripts of pirates "on the fly". It's a workaround, and it won't work in all cases, but it is doable, and it's the best I can come up with spontaneously.
There is an explanation by Ahruman either in the scripting requests thread or in the progress thread on how to attach scripts on the fly. Basically you need a world script running on every exitingWitchspace event, which identifies all ships in system with primary role "pirate", and copies the piece of script laid out by Kaks into their ship scripts. The main caveat is that only the pirate ships already in existence when the player enters the system would get the script. Entering traders turning pirates later would not get it.
Posted: Sat Nov 13, 2010 1:23 pm
by Kaks
Well, what I thought was that you could have your very own 'clever pirates', working independently from the usual ones.
If you want to override all pirates everywhere, you could do that by using the shipSpawned world event. It should get fired every time a new ship appears in the ooniverse.
Posted: Sat Nov 13, 2010 1:56 pm
by Disembodied
I think a sprinkling of "smart pirates" would be better than simply altering the behaviour of all pirates everywhere ... there's no way the player can see, for example, how dangerous an NPC might be. Maybe some pirates might be more clued-up than others, but there should still be a lot of uninformed and/or reckless bandits out there. Apart from anything else, it would make life very frustrating for players if all our potential targets just legged it the minute they came onto the scanners!
Would this also be a method of reducing the chances of pirates attacking Offender/Fugitive players?
Posted: Sat Nov 13, 2010 2:25 pm
by Commander McLane
@ Kaks: I didn't have shipSpawned as a world event on my radar, I have only ever used it as a ship event. But of course it's perfect for this.
@ Disembodied: The OXP Switeck has in the making is a complete overhaul of the generic ship behaviours, so the player actually would expect altered behaviours everywhere.
Posted: Sat Nov 13, 2010 3:30 pm
by Kaks
Commander McLane wrote:@ Kaks: I didn't have shipSpawned as a world event on my radar.
If I may misquote Commander McLane: look up the scripting information on the wiki, it's a really good source of information!
There was quite a huge improvement in scriptability between 1.73 & 1.74, I doubt any of us managed to catch up with
all that stuff.
On a slightly sadder note, I was looking up some new-ish features a little while ago, only to find out they had been added by Kaks.
Posted: Sun Nov 14, 2010 9:12 am
by Switeck
Commander McLane wrote:@ Disembodied: The OXP Switeck has in the making is a complete overhaul of the generic ship behaviours, so the player actually would expect altered behaviours everywhere.
I'm still fishing for ideas, but my mod almost certainly won't include pirates fleeing/ignoring the player based on the players' stats as default behavior. Most pirates won't know about you. Of the few that do, few will care. Of those that care, most won't care in a NICE way!