Scripters cove

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

Moderators: winston, another_commander

User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Scripters cove

Post by Old Murgh »

phkb wrote: Fri Jul 08, 2022 10:50 pm
My suggestion is

Code: Select all

if (Math.random() < 0.1) 
Because it removes unnecessary calculations, while still being clear what percentage is being checked, in this case a 10% chance. To make it 50% just change 0.1 to 0.5.
Thanks. That feels much easier to get my head around.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: Scripters cove

Post by Slartibartfast »

Hello

again i have some simple questions

===> equipment.plist / "canCarryMultiple"
F.x. from "FuelTweaks.oxz": --> "Quirium Fuel Storage Unit"

- - (Is it possible to / How can i) get the number of installed pieces in a script?
- - Is it possible the set a maximum of pieces for a a ship? ( maybe in shipdata.plist )

matthias
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
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 »

Slartibartfast wrote: Fri Jul 15, 2022 6:50 pm
- - (Is it possible to / How can i) get the number of installed pieces in a script?
This should get you going:

Code: Select all

	var data = player.ship.equipmentStatus("EQ_FUEL_STORAGE", true);
	log(this.name, "Number of EQ_FUEL_STORAGE units OK: " + data["EQUIPMENT_OK"]);
	log(this.name, "Number of EQ_FUEL_STORAGE units Damaged: " + data["EQUIPMENT_DAMAGED"]);
Slartibartfast wrote: Fri Jul 15, 2022 6:50 pm
- - Is it possible the set a maximum of pieces for a a ship? ( maybe in shipdata.plist )
Only via script I'm afraid.

Code: Select all

this.playerBoughtEquipment = function(equipmentKey, paid) {
	if (equipmentKey == "EQ_FUEL_STORAGE") {
		var data = player.ship.equipmentStatus("EQ_FUEL_STORAGE", true);
		// make the limit 10 units
		if (data["EQUIPMENT_OK"] + data["EQUIPMENT_DAMAGED"] > 10) {
			// remove the item
			player.ship.removeEquipment("EQ_FUEL_STORAGE");
			// refund the player
			player.credits += paid;
		}
	}
}
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: Scripters cove

Post by Slartibartfast »

Hello Admiral

Thank you!

--- works great

only one small correction
in the second script snip i had to replace

player.credits += paid;
---with
player.credits += (paid / 10);

else i have a moneymaking machine. :wink:

cheers
Slartibartfast
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
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 »

Slartibartfast wrote: Sat Jul 16, 2022 2:30 pm
only one small correction
in the second script snip i had to replace

player.credits += paid;
---with
player.credits += (paid / 10);
Right! I should update the doco to reflect this. *makes mental note*
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: Scripters cove

Post by Slartibartfast »

hi

==> equipment.plist

from: https://wiki.alioth.net/index.php/Equipment.plist
1) The first entry is an integer that determines the technical level from which the equipment can be bought. A level of 99 has a special meaning. Only this value can be changed by script. Please note that the number displayed on the system data screen is one higher than the system's tech level, so to make equipment available at a displayed TL:10 and above in game, enter 9 here
but in my logs this appears: --- veryveryveryvery often

Code: Select all

[oxp-standards.deprecated]: TL99 is deprecated for EQ_.......
What should i use instead of "99" to make EQ not buyable?

I have not found any info -- neither in the wiki, nor in the forum.

Matthias
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: Scripters cove

Post by Slartibartfast »

next question about equipment.plist

to make "requires (equipment_a AND equipment_b)"
i have made this

Code: Select all

"requires_equipment" = "EQ_A";
"requires_any_equipment" = ("EQ_B");
does anybody now a better way?

cheers
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

Slartibartfast wrote: Thu Jul 21, 2022 10:27 am
What should i use instead of "99" to make EQ not buyable?

I have not found any info -- neither in the wiki, nor in the forum.

Matthias
Good evening Matthias,
did you have a closer look at

"available_to_all" =
"available_to_NPCs" =
"available_to_player" =

? :wink:
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

Slartibartfast wrote: Thu Jul 21, 2022 10:59 am
next question about equipment.plist

to make "requires (equipment_a AND equipment_b)"
i have made this

Code: Select all

"requires_equipment" = "EQ_A";
"requires_any_equipment" = ("EQ_B");
does anybody now a better way?

cheers
requires_equipment, requires_any_equipment, incompatible_with_equipment can be a single string or an array of strings.

For both issues, you can also use a condition script.
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: Scripters cove

Post by Slartibartfast »

Hi montana

when i set
"available_to_all" = no
i can´t install that via script/player.ship.awardEquipment

with "99" and "= yes" it works as i want
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

Slartibartfast wrote: Thu Jul 21, 2022 12:50 pm
Hi montana

when i set
"available_to_all" = no
i can´t install that via script/player.ship.awardEquipment

with "99" and "= yes" it works as i want
I had a similar issue in the past, just can't remember in which OXP. As much as I recall, I used a condition script at the end. I am currently relaxing with a bottle of sake on the beach, so no access to my database. I can have a look tomorrow morning and, hopefully, provide you with a solution.

EDIT:
For now, please have a look at this: https://wiki.alioth.net/index.php/Oolit ... on_scripts. this.allowAwardEquipment = function(eqKey, ship, context) is probably what you are looking for.
Last edited by montana05 on Thu Jul 21, 2022 1:14 pm, edited 2 times in total.
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: Scripters cove

Post by Slartibartfast »

==> equipment.plist / requires

ok this works fine

Code: Select all

"requires_equipment" = ("EQ_A","EQ_B");
maybe the wiki should be updated
like this:

"requires_equipment" = ("EQ_FUEL_SCOOPS, "EQ_OTHER"); // array of strings - add as much as you want
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: Scripters cove

Post by Slartibartfast »

--> equipment.plist / TL99

hmmm

a "condition-script " as solution
for me that seems to be more a "workaround"


==> for the next time i stay with "99"

and :wink:
( linux/bash)

Code: Select all

grep -v deprecated Latest.log > Last.log
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Scripters cove

Post by Old Murgh »

phkb wrote: Fri Jul 08, 2022 10:50 pm
My suggestion is

Code: Select all

if (Math.random() < 0.1) 
Because it removes unnecessary calculations, while still being clear what percentage is being checked, in this case a 10% chance. To make it 50% just change 0.1 to 0.5.
My finger has slipped somewhere. I thought I had a handle on this as a template but

Code: Select all

//add magmiss to system
this.systemWillPopulate = function ()
{
	if (Math.random() < 0.2)  // sets a 20% chance
	 {
		system.setPopulator("magmiss", 
		{
			callback: function(pos)
			{			
				system.addShips("magmiss", worldScripts["magmiss_populator"].$getRndInteger(1), pos); // spawns 1 ship with role magmiss
			}.bind(this),
			location: "LANE_WP",
			locationSeed: 0 
			// 0 = completely random position on the lane, otherwise use a specific seed number to have them in the same position each time
		});
	}
}

this.$getRndInteger = function(min, max)
{
	return (Math.floor(Math.random() * (max - min + 1) ) + min);
};
Gives this error.

Code: Select all

23:39:23.975 [script.javaScript.exception.ooliteDefined]: ***** JavaScript exception (magmiss_populator b1): Error: System.addShips: Invalid arguments (NaN) -- expected number (positive count no greater than 64).
:oops:

Does this have to do with me thinking I could alter this line

Code: Select all

system.addShips("scrub", worldScripts["scrub_populator"].$getRndInteger(1, 2), pos); // spawns 1 - 3 ships with role scrub
But changing (1, 2) to (1) doesn't actually mean I reduce it to 1 ship..?
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
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 »

Old Murgh wrote: Thu Jul 21, 2022 9:57 pm
But changing (1, 2) to (1) doesn't actually mean I reduce it to 1 ship..?
You'd need to use (1, 1). But in that case, there is no need to call the function at all, because it would only ever return 1.
Post Reply