Page 106 of 115

Re: Scripters cove

Posted: Fri Jul 08, 2022 11:15 pm
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.

Re: Scripters cove

Posted: Fri Jul 15, 2022 6:50 pm
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

Re: Scripters cove

Posted: Sat Jul 16, 2022 5:34 am
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;
		}
	}
}

Re: Scripters cove

Posted: Sat Jul 16, 2022 2:30 pm
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

Re: Scripters cove

Posted: Sat Jul 16, 2022 10:57 pm
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*

Re: Scripters cove

Posted: Thu Jul 21, 2022 10:27 am
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

Re: Scripters cove

Posted: Thu Jul 21, 2022 10:59 am
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

Re: Scripters cove

Posted: Thu Jul 21, 2022 12:38 pm
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:

Re: Scripters cove

Posted: Thu Jul 21, 2022 12:41 pm
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.

Re: Scripters cove

Posted: Thu Jul 21, 2022 12:50 pm
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

Re: Scripters cove

Posted: Thu Jul 21, 2022 1:09 pm
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.

Re: Scripters cove

Posted: Thu Jul 21, 2022 1:13 pm
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

Re: Scripters cove

Posted: Thu Jul 21, 2022 1:53 pm
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

Re: Scripters cove

Posted: Thu Jul 21, 2022 9:57 pm
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..?

Re: Scripters cove

Posted: Thu Jul 21, 2022 10:07 pm
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.