Page 59 of 117

Re: Scripters cove

Posted: Thu Jan 24, 2013 9:42 pm
by cim
Pleb wrote:
Quick question, I'm trying to use the new allowOfferShip function to make a ship only available if a mission variable is set to a specific value and the player is in an anarchy system. Is this even possible? :?
Yes.

Set the condition_script in shipyard.plist to be the name of a script file. Then, in that script file:

Code: Select all

this.allowOfferShip = function(shipKey) {
  return (missionVariables.myShipIsAvailable == "yes" && system.info.government == 0);
}
If the script file is managing multiple ships with different conditions, you'd actually have to check the value of shipKey, of course.

That should prevent the ship from appearing in other circumstances, though of course there's no guarantee it'll show up at all, depending on chance and tech level settings in shipyard.plist.

Re: Scripters cove

Posted: Thu Jan 24, 2013 11:10 pm
by Pleb
Thanks cim, that worked a treat! couldn't find any other use of the new condition scripts anywhere else or in any of the newest OXP releases so figured I might be the first to try it out. :mrgreen:

Re: Scripters cove

Posted: Fri Jan 25, 2013 3:29 am
by Wildeblood
What's the correct syntax for defining a timer, when I need to pass parameters to the function the timer is calling? I need this timer:

this.$tradingTimer = new Timer(this, this.$performTrading, 15, 9);

to call this.$performTrading(param, param)

Re: Scripters cove

Posted: Fri Jan 25, 2013 5:48 am
by spara
Wildeblood wrote:
What's the correct syntax for defining a timer, when I need to pass parameters to the function the timer is calling? I need this timer:

this.$tradingTimer = new Timer(this, this.$performTrading, 15, 9);

to call this.$performTrading(param, param)
This should work. I used similar syntax in Troomp.
this.$tradingTimer = new Timer(this, function(){this.$performTrading(param, param)}, 15, 9)

Re: Scripters cove

Posted: Fri Jan 25, 2013 7:31 am
by Thargoid
I don't think you can directly - the parameters have to be routed via variables or a similar method. Or at least that was what was recommended to me a while back when I had the same question.

Spara's method may be an alternative.

Re: Scripters cove

Posted: Fri Jan 25, 2013 8:02 am
by cim
Pleb wrote:
Thanks cim, that worked a treat! couldn't find any other use of the new condition scripts anywhere else or in any of the newest OXP releases so figured I might be the first to try it out. :mrgreen:
There are some equipment condition scripts in the core game (replacing the TL99 hack for the Naval Energy Unit and the other restricted item). I'm not aware of any released for shipdata or shipyard.
Wildeblood wrote:
What's the correct syntax for defining a timer, when I need to pass parameters to the function the timer is calling?
Untested, but try

Code: Select all

new Timer(this, this.$performTrading.bind(this, param, param), 15, 9);

Re: Scripters cove

Posted: Sat Jan 26, 2013 7:01 pm
by spara
I don't get it. I want equipment to be available only if you have ASC and Passenger Berth. What's wrong with this?

Code: Select all

"requires_equipment" = 
	(
		"EQ_ADVANCED_COMPASS",
		"EQ_PASSENGER_BERTH"
	);

Re: Scripters cove

Posted: Sat Jan 26, 2013 7:13 pm
by Smivs
That looks OK to me. What is going wrong/not working?

Re: Scripters cove

Posted: Sat Jan 26, 2013 7:18 pm
by spara
Smivs wrote:
That looks OK to me. What is going wrong/not working?
I'm being vague again, sorry. Equipment is not offered, althought I meet the requirements. For some reason I can only get single item requires_equipment clauses to work. Like this:

Code: Select all

"requires_equipment" = "EQ_ADVANCED_COMPASS";

Re: Scripters cove

Posted: Sat Jan 26, 2013 7:43 pm
by Smivs
According to the wiki it should accept an array of strings. :? Have you tried "requires_any_equipment"?

Re: Scripters cove

Posted: Sat Jan 26, 2013 8:02 pm
by spara
Smivs wrote:
According to the wiki it should accept an array of strings. :? Have you tried "requires_any_equipment"?
Yes. That one seems allow the equipment, if anything of "requires_any_equipment" is present. It seems that either I'm doing something terribly wrong or there is a bug in here.

Re: Scripters cove

Posted: Sat Jan 26, 2013 8:12 pm
by Smivs
Ah, so "requires_any_equipment" worked, yes?

Re: Scripters cove

Posted: Sat Jan 26, 2013 8:27 pm
by spara
Smivs wrote:
Ah, so "requires_any_equipment" worked, yes?
It works alright, but it's not what I want. I want to allow the equipment only if both requirements are met. Requires_any_equipment allow's the equipment if either requirement is met.

EDIT: Actually, with this:

Code: Select all

"requires_any_equipment" = 
	(
		"EQ_ADVANCED_COMPASS",
		"EQ_PASSENGER_BERTH"
	);
* If I have ASC and no Passenger Berth, equipment IS offered
* If I have Passenger Berth and no ASC, equipment IS not offered

There must be something wrong. Or I'm losing it :? .

Re: Scripters cove

Posted: Sat Jan 26, 2013 8:47 pm
by Thargoid
Can you post the entire equipment.plist file, or at least the full section relating to that equipment item? What you've posted is OK, so it'd be worth double-checking that there's not something adrift elsewhere in the set-up.

For reference, below is the code for the planetary landing capability (from Planetfall) which similarly requires two bits of kit before it becomes available and seems to be working.

Code: Select all

(
	(
	8, 
	50000, 
	"Planetary Landing Capability", 
	"EQ_PLANETFALL", 
	"Modifications to the ships control thrusters, auto-pilot systems, heat shielding and landing gear to enable landing on planetary bodies and moons. Requires docking computers and heat shielding to already be installed.", 
		{
		"available_to_all" = yes;
		"requires_equipment" = 
			(
			"EQ_DOCK_COMP",
			"EQ_HEAT_SHIELD"
			); 
		script_info = { thargoidRepairBotChance = 0; };
		}
	)
)
[/color]

Re: Scripters cove

Posted: Sat Jan 26, 2013 9:09 pm
by spara
Here we go. I'm going crazy with this. All help is appreciated.

Code: Select all

(
	(
		0, 600, "In-System Taxi Licence",
		"EQ_IN_SYSTEM_TAXI_LICENCE",
		"Join Taxi Galactica's in-system taxi drivers division. Deliver customers from one station to another in-system. Buy this and you'll receive local delivery offers right to you Comms while cruising. When you get an offer, you have one minute to decide to take it or not. If you want to take it, just prime this small gadget and activate it.",
		{
			"available_to_all" = yes;
			"requires_equipment" = 
			(
				"EQ_ADVANCED_COMPASS",
				"EQ_PASSENGER_BERTH"
			);
			"portable_between_ships" = yes;
			"script" = "taxi_equipment.js";
			"damage_probability" = 0.0;
			"condition_script" = "taxi_equipment.js";
		}
	),
	(
		1, 100, "Remove In-System Taxi Licence",
		"EQ_WEAPON_IN_SYSTEM_TAXI_LICENCE_REMOVAL",
		"Stop receiving in-system delivery offers.",
		{
			"available_to_all" = true;
			"requires_equipment" = "EQ_IN_SYSTEM_TAXI_LICENCE";
			"condition_script" = "taxi_equipment.js";
		}
	)  
)
and

Code: Select all

this.allowAwardEquipment = function(eqKey, ship, context) {
	if (player.ship.dockedStation.hasRole("taxi_station"))
		return true;
	else return false;
}