Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Scripters cove

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

Moderators: another_commander, winston

User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Note that I revamped the property list page on the wiki just a couple of hours ago.

That is indeed “ASCII format”, or more accurately OpenStep format. there is no explicit way to represent booleans in this format, but starting with Oolite 1.69 the strings “true”, “yes” and “on” or “false”, “no” and “off” may be used. The previous statement that numbers would work is not correct for earlier versions, but this also works in 1.69. (There may be cases where this stuff still doesn’t work; if you find one, please report it.) In general, starting with 1.69, it should be OK to use OpenStep format for any plist… as long as the file is parsed properly by both Mac OS X and GNUstep. (Apart from being stricter about quotation marks, GNUstep also seems to require that plists with a dictionary as the root have surrounding braces, while OS X doesn’t.)

McLane: under OS X, unquoted words with underscore are always OK. GNUstep is stricter in ways that I haven’t explored fully, but I’m pretty sure unquoted words with underscores are OK for dictionary keys, i.e. on the left hand side of an = sign. (Also, Griff seems to have successfully used that one on Windows.)

Of course, this isn’t actually anything to do with scripting. Do we need a Property List Workshop sticky? :-)
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Randon generation between 0 and 1

Post by Eric Walch »

Something I tried out and it worked.

I wanted to place some ships at random places within the system. With "addSystemShips: role 1 0.5" a ship is placed at a place nearby halfway the witchpointbeacon and the stationbeacon.

In most scriptlines you can place a variable within brackets instead of text. for random placement on the planet-witchpoint axis you would like a random variable between 0 and 1. The only random generator existing is d100_number. (random number between 0 and 99)

I assumed that the system is probably fist replacing everything within brackets in a scriptline for text and than executes this new string. So I tried:

"addSystemShips: role 1 0.[d100_number]"

And it worked, the random-part is changed and you get a number between 0.0 and 0.99

Just for information, and this is no guarantee that this works in future versions of Oolite.

Eric Walch
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

I wouldn’t expect it to change in future versions. However, the futuristic version which definitely shouldn’t break is:

Code: Select all

system.legacy_addSystemShips("role", 1, Math.random());
With the new addShips() functions scheduled for 1.70, the non-“legacy” way will probably end up something like:

Code: Select all

var position = Vector.interpolate(system.witchPoint, system.mainStation, Math.random());
system.addShip("role", position);
The legacy_addShips() etc. methods will be retained, though. Of course, all this requires adopting JavaScript for OXP scripting, which is officially The Future. ;-)

Edit: note that you can also use arithmetic here; for instance, Math.random() * 0.3 + 0.2 will give you a number between 0.2 and 0.5. The ability to arbitrarily combine operations is one of the major reasons that switching to a “real” scripting language is The Future.
Last edited by JensAyton on Fri Jul 20, 2007 3:54 pm, edited 1 time in total.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

@ Eric Walch:

That's really cool! Sometimes I wished to have a small random number, but never came to that idea.

Thanks for sharing!
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Agressive escort

Post by Eric Walch »

I thought I was ready with my OXP, but then I discovered AI. To surprise the player I wanted to introduce some unexpected new behavior for the ships.
I tried to give the player an escort. The escort commands didn't work on the player. But no player would probably just fly straight with an escort in formation. Therefor I wrote a follow script were the escort follows the player and in the meantime looks for other ships with a certain role to attack them.

I had however some starting problems. I used following script state to initially link the escort to the player:

"ESCORT_ANNOUNCEMENT" = {
ENTER = (performTumble, "scanForNearestShipWithRole: player");
EXIT = ();
"TARGET_FOUND" = ("commsMessage: We'll escort you", setTargetToFoundTarget, "setStateTo: FOLLOW_MOTHER");
UPDATE = ("scanForNearestShipWithRole: player", "pauseAI: 3.0");
};

When I left out the "performTumble", the escorts became hostile to the player for a second. Then they cooled down. But by then they sometimes had already fired at me. Sometime even shoot a missile at me. That was not the behavior you expect from an escort. It was the command "setTargetToFoundTarget" that triggered the unfriendly action. But I needed to target the player for them to follow me with the "FOLLOW_MOTHER" state.

I almost gave up and then I introduced the "performTumble". I don't know why it worked because it makes the ship just rotate. But maybe the delay is enough and a pause would also do the trick.

Now they have followed me for a while without any mishaps. Without the tumble I was occasionally completely shot down by my own escorts.

Eric Walch
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

hyperSpaceExit

Post by Eric Walch »

One of the things on my wish-list to program is a mid-space friendly interaction with a system vessel. Today I worked on the possibilities to write such a thing with the AI scripting. It worked.

The target-ship hails the player. And then transfers fuel, money, cargo or a mission-task. One task is to deliver a package to the main station. After transfer, the target-ship is ready and is not needed anymore. I send him to the witchpoint and there he performs a hyperspace exit. Here I found a bug in the system. Directly after exiting he jumps back in again. It does not matter if I use the "performHyperSpaceExit" exit or switch to the "exitSystemAI.plist" In both cases he hypers back in elsewhere at the witchspace beacon point at the same moment he disappears through the wormhole. The biggest problem is that the AI-script starts al over again.

Now I probably have no other option than fly the target-ship far beyond the scanner-range of the player and blow the damn thing into pieces.

Has anyone a more friendly solution?


Eric Walch
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2866
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 »

Think landOnplanet removes a ship from the game. He will wink out of existence rather than leaving a hyperspace cloud though.
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
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

You sure it’s not a script regenerating an identical ship and starting the mission over again?
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

I agree with A, this sounds like a script looking for a specific ship, and adding it if it is not found.

When the ship leaves, it then finds there is no ship of that type in the system and adds it.

Introduce a local_variable that remembers the ship has been created.
(eg. add to the line with "AddShip: ship" a "set: local_variable_shipspawned YES")
Then add to the conditions a "local_variable_shipspawned equal UNDEFINED"

This prevents the ship from being spawned more than once in a system.
The local_variable is not conserved between jumps...or saved to the player-file (IIRC) like the mission_variables are.
Should you want to spawn it again, without leaving the system, reset the variable.
If you want to repeat this trick a given number of times, just use increment: local_variable and check for it to be equal to the number of times you want the script to be repeated.



On your earlier escort problem.

Are the escorts using a pirateAI? or are you a criminal? In both cases, the AI may decide to attack you. First thing I would suggest is putting the commsMessage at the end of that line of code.
PauseAI: seconds may be of help as well, as long as no behavioural methods like performX have been called.
Then again, the ship should not attack without performAttack, performGroupAttack or fightOrFlight etc being called.
We need to see the entire AIcode to know for certain.
(put in between [ code ] tags please.) ;)


ps:
Are these services free of charge?
I hope you paid a hefty fee for a escort-contract or you have to perform a difficult mission these escorts are supposed to assist you with. :p

edit: hmm... are [spoiler]spoiler tags[/spoiler] working yet?
edit2: bugger. :(
Last edited by Arexack_Heretic on Thu Jul 26, 2007 10:36 pm, edited 3 times in total.
Riding the Rocket!
User avatar
TGHC
---- E L I T E ----
---- E L I T E ----
Posts: 2157
Joined: Mon Jan 31, 2005 4:16 pm
Location: Berkshire, UK

Post by TGHC »

I really like this thread even though I don't understand the technicalities. It looks like some excellent new ideas and solutions to problems are being resolved, well done guys!
The Grey Haired Commander has spoken!
OK so I'm a PC user - "you know whats scary? Out of billions of sperm I was the fastest"
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Re: hyperSpaceExit

Post by Frame »

Eric Walch wrote:
Has anyone a more friendly solution?
Eric Walch
Once he is beyond range, or when the player docks then simply let him "become explosion", i figure the easiest way to do this, would be to switchAI once he has delivered his money/mission/cargo...

Cheers Frame....
Bounty Scanner
Number 935
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

that would violate the non-player centality of oolite, but would work.
IF it is an AI problem.
It would be more consistent to have him dock, land (if adder etc) or hyperspace away (after sunskimming).
Riding the Rocket!
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Ahruman wrote:
You sure it’s not a script regenerating an identical ship and starting the mission over again?
That was the first thing I looked at. I am sure, the ship is created under condition:

status_string equal STATUS_EXITING_WITCHSPACE

And I stay in the system all the time.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

On your earlier escort problem.

Are the escorts using a pirateAI? or are you a criminal? In both cases, the AI may decide to attack you. First thing I would suggest is putting the commsMessage at the end of that line of code.
Escorts have a sels written AI. CLASS_MILITARY or CLASS_POLICE. (I tried both). I had a lot of commsMessages but I left them away in the example.
Then again, the ship should not attack without performAttack, performGroupAttack or fightOrFlight etc being called.
That's the thing I found odd. They just went offensive on using the command setTargetToFoundTarget. But just one second. Then they got friendly again. But in that seccond I got shot at of a missile launched. But it works now.
Are these services free of charge?
I hope you paid a hefty fee for a escort-contract or you have to perform a difficult mission these escorts are supposed to assist you with.
I think so. I have a valuable gargo and the enemy knows it.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Once he is beyond range, or when the player docks then simply let him "become explosion", i figure the easiest way to do this, would be to switchAI once he has delivered his money/mission/cargo...
That was also my backup solution. The second one was to dive into the sun. But I don't like those idea's

Going towards the planet or docking was no solution as he asks the player to deliver the package at the station as he has go somewhere else. And above all: it is a nice view seeing him creating a wormhole and dissapear. It is an anaconda thas has sometimes escorts. If pressent you see them also going througt the wormhole.

The solution I came up with was checking if I am near the WitchSpacePoint. If yes, then switch to enteringTraderAI.plist. Checking was still a problem as I found no way to detect the buoy. If I did a find NearestShipWithRole: buoy-witchpoint he didn't find anything. This role I copies from the shipdata list. It should be right.
But tried a other solution. Just fly to the witchpoint with "setCourseToWithchpoint" If arived switch to other traderAI. It only wont work if the player is near the witchpoint. But I will make sure that the ship is first time created far from this point.

(In my opinion it is a bug in version 1.65 After going trough the wormhole he left the system.)
Post Reply