Berth Control for OXP authors
Posted: Tue Jan 21, 2014 1:43 pm
So, my first contribution...
Edited to re-purpose this thread - as Commander McLane points out further down there is a place for scripting examples elsewhere, and as you will see this thread becomes a very interesting discussion in its own right.
Passenger Berth Script
This script is to allow a ship to have a number of 'permanent' passenger berths fitted - berths that cannot be removed - while allowing extra berths to be bought and sold. When the last 'removeable' berth is sold, a console message confirms that it is the last removeable berth and warns against trying to remove the permanent ones. If an attempt is made to remove a permanent berth a console message points out that it cannot be removed. About 25 minutes of game-time is lost while the technicians confirm this, but the permanent berth remains in place and there is no cost to the player.
For this to work, you will need to specify the number of permanent berths in the shipyard.plist as 'standard equipment' thus:-
Code: Select all
"standard_equipment" =
{
extras =
(
"EQ_PASSENGER_BERTH",
"EQ_PASSENGER_BERTH",
"EQ_PASSENGER_BERTH",
"EQ_PASSENGER_BERTH",
"EQ_PASSENGER_BERTH"
);
};
DO NOT list "EQ_PASSENGER_BERTH" in the "optional_equipment" section of the shipyard.plist.
Next you will need to refer to the script in the shipdata.plist thus:-
Code: Select all
script = "Smivs'_passenger_berth_script.js";
Code: Select all
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
"use strict";
// Standard attributes
this.name = "Smivs'_passenger_berth_script.js";
this.author = "Smivs";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "1.0";
this.description = "script to prevent sale of 'permanent' passenger berths, and keep a tally of any 'normal' berths bought to allow their sale.";
this.playerBoughtNewShip = function(ship)
// starts counter, and sets berth count to zero when ship is bought ('Permanent' berths are ignored)
{
if(ship.name === "shipName")
{
if (!missionVariables.passengerBerth_count)
{
missionVariables.passengerBerth_count = 0;
}
}
}
this.playerBoughtEquipment = function(equipment)
// adds +1 to counter when a non-permanent berth is bought
{
if (equipment == "EQ_PASSENGER_BERTH")
{
missionVariables.passengerBerth_count++;
}
// allows non-permanent berths to be removed, and reduces counter by -1 for each removal
if (equipment == "EQ_PASSENGER_BERTH_REMOVAL" && missionVariables.passengerBerth_count > 1)
{
missionVariables.passengerBerth_count--;
return;
}
// when final non-permanent berth is removed, adds warning about permanent berths.
else if (equipment == "EQ_PASSENGER_BERTH_REMOVAL" && missionVariables.passengerBerth_count === 1)
{
missionVariables.passengerBerth_count--;
player.consoleMessage("There are no more removeable berths. Do not attempt to remove the Permanent Berths.",5);
return;
}
// effectively prevents removal of permanent berths
else if (equipment == "EQ_PASSENGER_BERTH_REMOVAL" && missionVariables.passengerBerth_count === 0)
{
player.ship.awardEquipment("EQ_PASSENGER_BERTH");
player.consoleMessage("The Permanent Passenger Berth could not be removed.",5);
player.credits += 100;
}
}
Code: Select all
if(ship.name === "shipName")
I hope this will be useful to some of you.