Scripters cove

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

Moderators: winston, another_commander

DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Scripters cove

Post by DGill »

Thanks for the code, seems the best option.
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

LittleBear wrote: Tue Aug 29, 2023 9:32 pm
You can select a specific position number from an array in script if you want to. But this would mean C&Ping the names from descriptions into script in array format:

Code: Select all

this.feudalfirstnamegermanhe = ["Bruno","Dieter","Eric","Franz","Gustav","Heinrich","Johan","Lothar","Otto","Reinhard","Thorsten","Ulrich","Walter","Wilhelm","Wolfgang"];
You can then summon a particular position in the array by its number (but Oolite starts counting from 0) with:

Code: Select all

var position = 0;
var name = feudalfirstnamegermanhe[position &14];
Var name will now be the name in the array at position 0 out of 15 positions (the number for total number above is one less than the actual number as position 1 is 0 and so on).
Excuse me for intervening without being asked, but I think I should warn that using bitwise AND (&) to prevent out-of-bounds is a bad idea: unless the value on the right of the operator is a power of two minus one (7, 255, etc), some values will be never used, like in this case, 1&14 === 0 and it even worse for something like 33 - only 4 values can be accessed from 34 total.
If this is not the intended behaviour (I doubt it is) you need the modulo operator (%):

Code: Select all

var name = feudalfirstnamegermanhe[position % 15];
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Scripters cove

Post by DGill »

Thanks both, looks like I'm going to have fun trying out this coding :D
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2687
Joined: Thu Jun 20, 2013 10:22 pm
Location: On the moon Thought, orbiting the planet Ignorance.

Re: Scripters cove

Post by Redspear »

Is there a simple way to read 'alert condition' of a non-player ship?

I appreciate that non-player ships don't strictly have an alert condition (at least not in the manner that the player does) but never the less that would appear to provide a servicable description of what I'm after.

Specifically, I want to alter non player ship speed when engaged in combat (condition red) compared to otherwise.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

NPC ships have "alertCondition". From the wiki:
alertCondition : Number (read-only integer)

The ship's current alert condition (Docked = 0, Green = 1, Yellow = 2, Red = 3). Non-Station non-Player ships are generally only found at condition Yellow or Red.
Is that not working?
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2687
Joined: Thu Jun 20, 2013 10:22 pm
Location: On the moon Thought, orbiting the planet Ignorance.

Re: Scripters cove

Post by Redspear »

phkb wrote: Sat Oct 14, 2023 11:35 pm
Is that not working?
It's likely working better than my brain right now...
I even had that very page open :roll: :lol:
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Scripters cove

Post by DGill »

I'm having a problem with ship AI

I have used the AI code from wiki to have a ship attack me, i.e. I use this.shipSpawned ... this.ship.switchAI("thisTestAI.js");

Code: Select all

// ship script event handler triggered when a new AI is loaded
this.aiStarted = function() {
    // create a new AI controller and assign it this ship
	var ai = new worldScripts["oolite-libPriorityAI"].PriorityAIController(this.ship);
	// set up the priority list
	var priorities = [ 
	{
		condition: ai.conditionLosingCombat,
		behaviour: ai.behaviourFleeCombat,
		reconsider: 20
	},
	{
		condition: ai.conditionInCombat,
		configuration: ai.configurationAcquireCombatTarget,
		behaviour: ai.behaviourDestroyCurrentTarget,
		reconsider: 5
	},
	{
		condition: ai.conditionPlayerNearby,
		configuration: ai.configurationAcquirePlayerAsTarget,
		behaviour: ai.behaviourDestroyCurrentTarget,
		reconsider: 5
	},
	{		
		configuration: ai.configurationSetDestinationToWitchpoint,
		behaviour: ai.behaviourApproachDestination,
		reconsider: 20
	}
	];
	// apply the priority list to the AI
    ai.setPriorities(priorities);
}
The code works fine except if I cloak. When I uncloak my attacker just heads off towards the planet, if I shoot at it it does not respond - just lets itself be blown up.

Is there a command to have NPC ships re-engage their AI after the player de-cloaks?
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

There is no such command and there shouldn't be a need in the reactivating AIs.

I just tested the code - spawned an adder nearby and switched to the AI via console - all works fine for me - a ship keeps fighting both during cloak usage and after it.

Maybe there is something useful in the logs? Have you tried to use oolite_flag_behaviourLogging to check where it breaks?
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Scripters cove

Post by DGill »

Alnivel wrote: Tue Oct 24, 2023 5:51 pm

Maybe there is something useful in the logs? Have you tried to use oolite_flag_behaviourLogging to check where it breaks?
Tried again, and all works well using cloaking when fighting pirates but, alas not when fighting my test ship.

The oolite_flag_behaviourLogging gives:

Code: Select all

21:44:06.822 [Prinz-Class Zerstoerer (Digebiti)]: Considering branch with 4 entries
21:44:06.822 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 0
21:44:06.822 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 1
21:44:06.822 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 2
21:44:06.822 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 3
21:44:06.822 [Prinz-Class Zerstoerer (Digebiti)]: Conditions met
21:44:06.822 [Prinz-Class Zerstoerer (Digebiti)]: Executing behaviour
21:44:26.839 [Prinz-Class Zerstoerer (Digebiti)]: Considering branch with 4 entries
21:44:26.839 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 0
21:44:26.839 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 1
21:44:26.839 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 2
21:44:26.839 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 3
21:44:26.839 [Prinz-Class Zerstoerer (Digebiti)]: Conditions met
21:44:26.839 [Prinz-Class Zerstoerer (Digebiti)]: Executing behaviour
21:44:46.842 [Prinz-Class Zerstoerer (Digebiti)]: Considering branch with 4 entries
21:44:46.842 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 0
21:44:46.842 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 1
21:44:46.842 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 2
21:44:46.842 [Prinz-Class Zerstoerer (Digebiti)]: Conditions met
21:44:46.842 [Prinz-Class Zerstoerer (Digebiti)]: Executing behaviour
21:44:47.622 [Prinz-Class Zerstoerer (Digebiti)]: Considering branch with 4 entries
21:44:47.622 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 0
21:44:47.622 [Prinz-Class Zerstoerer (Digebiti)]: Considering: entry 1
21:44:47.622 [Prinz-Class Zerstoerer (Digebiti)]: Conditions met
21:44:47.622 [Prinz-Class Zerstoerer (Digebiti)]: Executing behaviour
21:45:22.034 [exit.context]: Exiting: Shift-escape pressed.
21:45:22.041 [gameController.exitApp]: .GNUstepDefaults synchronized.
which does not tell me much other than initially it selects entry 3 which I believe is head to witch point.
It then selects entry 2, probably on meeting me, which is acquirePlayerAsTarget
then entry 1, DestroyCurrentTarget
When I'm fired upon I cloak and then de-cloak at which point no more entries and I shoot at and destroy the ship .
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

DGill wrote: Tue Oct 24, 2023 9:04 pm
Alnivel wrote: Tue Oct 24, 2023 5:51 pm

Maybe there is something useful in the logs? Have you tried to use oolite_flag_behaviourLogging to check where it breaks?
Tried again, and all works well using cloaking when fighting pirates but, alas not when fighting my test ship.

The oolite_flag_behaviourLogging gives:
. . .
which does not tell me much other than initially it selects entry 3 which I believe is head to witch point.
It then selects entry 2, probably on meeting me, which is acquirePlayerAsTarget
then entry 1, DestroyCurrentTarget
When I'm fired upon I cloak and then de-cloak at which point no more entries and I shoot at and destroy the ship .
Have you checked if your AI script is being switched to something else after de-cloaking or starting a fight? Either by the ship's or world script.
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Scripters cove

Post by DGill »

Alnivel wrote: Tue Oct 24, 2023 11:14 pm
Have you checked if your AI script is being switched to something else after de-cloaking or starting a fight? Either by the ship's or world script.
I have checked which is why I was initially wondering whether there was a command to switch it back. But I'll have to do a more thorough search particularly, as you say, in other world-scripts.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

DGill wrote: Wed Oct 25, 2023 12:30 am
I have checked which is why I was initially wondering whether there was a command to switch it back. But I'll have to do a more thorough search particularly, as you say, in other world-scripts.
You should be able to see what AI script is active by checking the AIScript property of the ship. You might also want to check autoAI of the ship and see whether it's true or false.
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Scripters cove

Post by DGill »

Thanks folks, found the offending script :D
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 556
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Scripters cove

Post by Nite Owl »

Trying to write my first JavaScript file from a blank page. Not having much luck. The project is based on the Docking Fees OXZ. Trying to eliminate the Fees and just have a Message always appear on the Station Arrival Screen. The current behavior is that if the Player has a Fine or has scooped an Escape Pod with a Bounty or some Insurance attached to it then the Arrival Screen shows when Docking. My goal is to write some Messages that will come up on the Arrival Screen even when neither of the two previous conditions are present, as in every time a player Docks anywhere. Getting the Messages written is done as most are variations from Layne and Eris original Docking Fees OXZ with some personal flourishes mixed in. The description.plist is "easy" so that is done and is, most likely, correct. The JavaScript file from the original Docking Fees OXZ had far too many Fee based variables to be reused although that was attempted by commenting out lines of the code. Decided to start from scratch and see what could be learned along the way. Unfortunately, a wall has been hit and no further progress is being made. The Latest.log and the JavaScript Linter in use are showing no errors. My collection of 300+ OXZs and OXPs has been scoured looking for any similar usage with no further findings. Any help and corrections to the following code would be much appreciated. No comments please on the coding style as that just makes things easier for my tired old eyes to read.

Code: Select all

this.shipWillDockWithStation = function (station)
{
	if (system.techLevel == 0 && player.ship.dockedStation.hasRole ("coriolis") || player.ship.dockedStation.hasRole ("dodecahedron") || player.ship.dockedStation.hasRole ("icosahedron") || player.ship.dockedStation.hasRole ("sfep_station"))
	{
		player.addMessageToArrivalReport = (expandDescription("[dockmessage_0]"));
	}
	else
	if (system.techLevel == 1 && player.ship.dockedStation.hasRole ("coriolis") || player.ship.dockedStation.hasRole ("dodecahedron") || player.ship.dockedStation.hasRole ("icosahedron") || player.ship.dockedStation.hasRole ("sfep_station"))
	{
		player.addMessageToArrivalReport = (expandDescription("[dockmessage_1]"));
	}

// This continues on for all 14 Tech Levels. Individual Station Roles come into play next.

	}
	else
	if (player.ship.dockedStation.hasRole ("rockhermit") || player.ship.dockedStation.hasRole ("rockhermit-chaotic") || player.ship.dockedStation.hasRole ("rockhermit-pirate"))	   	 
	{
		player.addMessageToArrivalReport = (expandDescription("[dockmessage_rock]"));	
	}
	else
	if (player.ship.dockedStation.hasRole ("constore"))
	{
		player.addMessageToArrivalReport = (expandDescription("[dockmessage_store]"));
	}

//Etc. and so on.

}
Some code from the description.plist just in case.

Code: Select all

{
	"dockmessage_0" = 
	(
	"The Docking Bay is sticky with a rather pungent odor. The platform appears unattended. Local gangs of toughs mutter darkly from the overlook. A few Trumbles skitter away from the light and vanish into an air duct.",

	"The Landing Berth is scrawled with crude graffiti and littered with trash. It takes some effort not to step on anything.",

	"The Landing Pad creaks ominously. One of the Docking Bay lights flickers and then goes dark. Eyes seem to watch from everywhere.",

	"The Docking Bay lights flicker unsteadily. Disembarking onto the creaking metal floor is an uneasy process. Hope springs eternal that the station holds together while business is conducted."
	);

//============================================================================================================================
	
	 "dockmessage_1" = 
        (
	"The place stinks, literally stinks, as if someone had deliberately painted the place with a vat of crushed sulfurous tree slugs. It is best to tread lightly in such places and to remember not to breath in too deeply. Get this over with quickly and get out.", 	

	"The deserted Docking Bay is scrawled with rude graffiti. The walkway is sticky and noisome. What exactly is causing the stickiness is best left unknown. New shoes may be in order at a more well provisioned station.",

	"A gang of locals are betting on a fight between a hauler bot and a giant %I [26] [30]. The raucous shouts quickly descend into some sort of turf war. Getting out of the way quickly provides some relief.",

	"The Landing Berth lights are dim and flicker continuously. Someone is hiding in the corners of the bay's shadows. Quickly moving on is the best option. "
	);

// This continues on as well.

}
Both files are rather long. There are probably better was of using Arrays and such to accomplish this goal. Though for a first attempt at such things keeping it simple and basic is probably best. Thank You once again for any help you can render. It is much appreciated.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

You're using the shipWillDockWithStation event, but I suspect you can't check the player.ship.dockedStation property in that event, because the player won't be docked yet. However, the station is being passed to the function, though, so you can still check it.

Also, this line needs some work:

Code: Select all

if (system.techLevel == 0 && player.ship.dockedStation.hasRole ("coriolis") || player.ship.dockedStation.hasRole ("dodecahedron") || player.ship.dockedStation.hasRole ("icosahedron") || player.ship.dockedStation.hasRole ("sfep_station"))
The "&&" and "||" are working against each other. I'd put a bracket around the "||" elements (and use the "station" object):

Code: Select all

if (system.techLevel == 0 && (station.hasRole ("coriolis") || station.hasRole ("dodecahedron") || station.hasRole ("icosahedron") || station.hasRole ("sfep_station")))
Same for each line that starts if (system.techLevel == ...
Post Reply