Scripting requests

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

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:

Re: ....

Post by Commander McLane »

Lestradae wrote:
LittleBear wrote:
do = (
"setMissionMusic: none"
That one's interesting. Is there a XML command for the planetinfo.plist that lets a piece of music or a sound file be played when the player enters a system? I could use something like that for my special systems.
Who is speaking of entering a system? Mission Music can be played when a mission screen opens. Which is exactly what LittleBear's code snippet is about. (You haven't read the conditions-part of it, have you?)
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

@Lestradae: have I ever mentioned Javascript? You can play any music you like depending on any condition, at any time!

You could easily (I don't know with how many lines yet! ;) ) have a sound equivalent to system redux/famous planets: specific music when entering specific systems, or a more generic one playing music based on type of government, different sound effects when entering the aegis depending on the system technology, or even different 'warning' sound messages when being attacked, depending on the main role of the ship attacking you...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
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 »

In playerEntity.m there are three places were it calls

Code: Select all

[UNIVERSE allShipAIsReactToMessage:@"PLAYER WITCHSPACE"];
Probably it should also send a JS message to all scripts.

Currently I noticed Oolite has a bug that repeating timers in a ship script keep running when the player leaves the system. I have one mission ship that uses these timers. I now use the "PLAYER WITCHSPACE" AI message to send a script event to stop and delete the timers. But an added problem is that this ship ends its journey with an dockingAI. At the moment it switches to that AI I see no way to call that script function to stop the timers when the player leaves at that moment.

This is a temporary problem until the timer bug is fixed, but I can imagine other situations were it is easier to let the ship itself detect that the player left the system instead of doing it in a player worldScript.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

We can award specific cargo types to the player, but would it be do-able to add the ability to check for the amount of a specific cargo type that is in the hold, and also where present to selectively remove it (basically the opposite of awardCargo)?

Ideally both available in-flight rather than just when docked (and ditto the in-flight part for removeAllCargo, is that possible too?)
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

Post by Frame »

*

this would be nice

javascript acces to

Code: Select all

player.ship.galaxyCoords
player.ship.cursorCoords
Both Read Only

It would be nice to know where in witchspace you are, since we do not have system ID for witchspace, when writing an OXP

Cursor coords is just added bonus.. but should be included In my opinion as it can also serve in getting coordinates fast, for this and that system.. instead of having to go look it up on the wiki thus saving wiki bandwidth & traffic...

player.ship because it is selected by the player on the hyperspace computer on the ship...

I tested it, like this... and serve it on a silver plate :-)

file:OOJSPlayerShip.m

Code: Select all


enum
{
	// Property IDs,
	// other stuff removed for ease of reading in this post
	kPlayerShip_galaxy_coords,		//galaxy coordinates, vector read only
	kPlayerShip_cursor_coords,		//cursor coordinates, vector read only
	
};


static JSPropertySpec sPlayerShipProperties[] =
{
	// JS name						ID									flags
	// other stuff removed for ease of reading
	{ "galaxyCoords",		kPlayerShip_galaxy_coords,	JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
	{ "cursorCoords",		kPlayerShip_cursor_coords,	JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
	{ 0 }
   // other stuff removed for ease of reading

};
same file later in the file, in the function of

static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)

Code: Select all

case kPlayerShip_galaxy_coords:
			OK = NSPointToVectorJSValue(context, [player galaxy_coordinates], outValue);
			break;
		
		case kPlayerShip_cursor_coords:
			OK = NSPointToVectorJSValue(context, [player cursor_coordinates], outValue);
			break;
and file oolite-global-prefix.js

Code: Select all

this.defineCompatibilitySubGetter("player", "ship", "galaxyCoords");
this.defineCompatibilitySubGetter("player", "ship", "cursorCoords");
in a test build of revision 2220, (latest right now), this has checked out ok... using the debug console

I'm getting correct output

(x,y,0)
Bounty Scanner
Number 935
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Good job man! Will check this in the evening and if all good, this might become revision 2221.

Edit: It actually became revision 2223, Ahruman fixed a couple of things in the trunk before I managed to get there. Oh, and the names of the methods are player.ship.galaxyCoordinates and player.ship.cursorCoordinates.

Frame, can you please check that your name has been spelled correctly in the contributors thread in Announcements? ;-)
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

Post by Frame »

another_commander wrote:
Good job man!

Frame, can you please check that your name has been spelled correctly in the contributors thread in Announcements? ;-)
Thanks :)

And yes it is spelled correct.
Bounty Scanner
Number 935
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 »

I like to add a new pause command to the AI vocabulary: randomPauseAI. I already coded it and tested it on my test environment and it acts as I planned:

Code: Select all

- (void) randomPauseAI:(NSString *)intervalString
{
	NSArray*	tokens = ScanTokensFromString(intervalString);
	double start, end;

	if ([tokens count] != 2)
	{
		OOLog(@"ai.syntax.randomPauseAI", @"***** ERROR: cannot read min and max value for pause, needs 2 values: '%@'.", intervalString);
		return;
	}

	start = [(NSString *)[tokens objectAtIndex:0] doubleValue];
	end   = [(NSString *)[tokens objectAtIndex:1] doubleValue];


	[shipAI setNextThinkTime:[UNIVERSE getTime] + (start + (end - start)*randf())];
}
I needed it to create a random reaction time with AI scripting. e.g. like:

Code: Select all

		"INCOMING_MISSILE" = ("messageSelf: FIGHT_MISSILE", "randomPauseAI: 0.5 3.0"); 
		"FIGHT_MISSILE" = (setTargetToPrimaryAggressor, fightOrFleeMissile);
No instant reaction on incoming missiles but sending itself an instruction to react between a minimum and maximum time interval.

EDIT: Added the above command to the trunk.
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 »

another_commander wrote:
Good job man! Will check this in the evening and if all good, this might become revision 2221.

Edit: It actually became revision 2223, Ahruman fixed a couple of things in the trunk before I managed to get there. Oh, and the names of the methods are player.ship.galaxyCoordinates and player.ship.cursorCoordinates.
Thanks for taking up a suggestion from back in January! :wink: :D

Now what about my other suggestions about the whole witchjumping business? Like this one. Oh, and of course making misjumps scriptable (if you're at it, you know...) :wink:
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

...

Post by Lestradae »

I suggest expanding the following command: %Jxxx
Will display the system name of system with ID number "xxx". xxx must be a 3 digit number or no replacement takes place. e.g. %J007 is Lave (in Galaxy 1, that is)

... to a four-digit number %Jyxxx in which the y (0-7) stands for the galaxy or sector the system is in.

That way, trans-galactic missions can be displayed correctly by using the above command and use the new "1.73" trunk feature of also depicting oxp-altered planet/system names.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Commander McLane wrote:
Now what about my other suggestions about the whole witchjumping business? Like this one. Oh, and of course making misjumps scriptable (if you're at it, you know...) :wink:
As of SVN2267, we have scriptable misjumps. The new read/write JavaScript boolean property player.ship.scriptedMisjump has been added. As long as this is set to true the player ship will be executing misjumps, so handle with care and make sure to reset it after having finished with 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 »

another_commander wrote:
As of SVN2267, we have scriptable misjumps. The new read/write JavaScript boolean property player.ship.scriptedMisjump has been added. As long as this is set to true the player ship will be executing misjumps, so handle with care and make sure to reset it after having finished with it.
Great job A_C, Witchspace travelling will never be save anymore. :evil:

Just one suggestion: Don't let an oxp reset that property buy let the code reset it after every jump. That way an oxp can only set it for the next jump.

When oxp'ers must reset that themselves it will lead to conflicts when two of them use this feature. When not needed an oxp is likely to clear the property always to be sure and not check if he was the one that had set it or that an other oxp has set it. By making it auto clearing on jumping you avoid these problems.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

You are right Eric. SVN2268 makes the scripted misjumps have a lifespan of one jump only, then they are autoreset. This should make things simpler for OXPers, as they only have to worry about setting the property before the actual scripted jump, then they can forget about it. The scripted_misjump flag will remain set to true during the shipWillExitWitchspace handler, but will be back to false at the end of the shipExitedWitchspace handler.
User avatar
Nemoricus
---- E L I T E ----
---- E L I T E ----
Posts: 388
Joined: Mon May 18, 2009 8:51 pm

Post by Nemoricus »

Hmm....it occurs to me that if an OXP has a scripted misjump in it, they may not want things that usually show up in Witchspace to show up.

While I can't think of an example off-hand, I do know that the presence of Thargoids and Navy vessels from other OXPs may complicate the misjumping OXP's plans.

OXP makers should therefore add a check to see if the misjump flag has been set so that they don't interfere with the scripted events.
Dream as if you'll live forever
Live as if you'll die tomorrow
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

Post by Frame »

another_commander wrote:

As of SVN2267, we have scriptable misjumps. The new read/write JavaScript boolean property player.ship.scriptedMisjump has been added. As long as this is set to true the player ship will be executing misjumps, so handle with care and make sure to reset it after having finished with it.
I do not see it in resources/oolite-global-prefix.js, but then again, i'm not even sure if it is needed in there... I'm not double checking, I'm just writing a new feature to suggest... and thereby fell over it. as I suspected it being last and to look something like.

Code: Select all

this.defineCompatibilitySubGetterAndSetter("player", "ship", "scriptedMisjump");
Nemoricus wrote:
Hmm....it occurs to me that if an OXP has a scripted misjump in it, they may not want things that usually show up in Witchspace to show up.

While I can't think of an example off-hand, I do know that the presence of Thargoids and Navy vessels from other OXPs may complicate the misjumping OXP's plans.

OXP makers should therefore add a check to see if the misjump flag has been set so that they don't interfere with the scripted events.
I always felt that Thargoids being auto present was a bit cheesy , especially since we can force mis-jumps by rolling the ship now. But they are there, and so is the galactic navy & behemots and so on...

OXP makers should deal with it like this, in case they want neither...

1 At Player entering interstellar space move player to a location far away.
preferbly at WillExitWitchSpace

2 remove all Not wanted ships before spawning yours

system.allShips contains all ships to be removed.

3 move player back to position at which he jumped in..
Last edited by Frame on Tue Jul 28, 2009 3:19 pm, edited 1 time in total.
Bounty Scanner
Number 935
Post Reply