Just thought I'd share the results of the work on the generic script I talked about. Quite often there's a need to generate names and ranks for specific characters, and at the moment each world script has a long and convoluted routine to produce these and save them as mission variables. I wanted to put this all into a single generic script, which could be called by different world scripts as necessary.
Several posts ago, Kaks suggested this was doable by attaching a generic function to the player, e.g.
Code: Select all
player.defineChallegerGender = this.defineChallengerGender = function
While this worked, I realised that each thread of the OXP (missions, promotions, tournaments and challenges) all needed to have their own set of variables, often running in parallel. So, for example, the name of a challenger opponent mustn't overwrite the name of a mission target. As a result, I needed to overhaul the way the OXP was handling names and ranks.
Here's how I've handled it. Below is the generic name and rank generator in its entirety (note the logs are just there for test purposes):
Code: Select all
this.name = "feudal-ranks.js";
this.author = "Ramirez";
this.copyright = "December 2009";
this.description = "Script used to generate ranks and names for feudal characters";
this.version = "1.0";
player.feudalRankGenerator = this.feudalRankGenerator = function()
{
if(player.rankGenerator_house == "Geinona")
{var rankGenerator_language = "spanish"
player.rankGenerator_of = "de"}
if(player.rankGenerator_house == "Oreseren" || player.rankGenerator_house == "Aronar")
{var rankGenerator_language = "dutch"
player.rankGenerator_of = "van"}
if(player.rankGenerator_house == "Digibeti" || player.rankGenerator_house == "Edzaon")
{var rankGenerator_language = "english"
player.rankGenerator_of = "of"}
if(player.rankGenerator_house == "Esredice" || player.rankGenerator_house == "Ededleen")
{var rankGenerator_language = "german"
player.rankGenerator_of = "von"}
if(player.rankGenerator_house == "Gelaed")
{var rankGenerator_language = "french"
player.rankGenerator_of = "de"}
if(player.rankGenerator_house == "Onusorle" || player.rankGenerator_house == "Tibedied")
{var rankGenerator_language = "swedish"
player.rankGenerator_of = "af"}
if(player.rankGenerator_house == "Tibecea")
{var rankGenerator_language = "italian"
player.rankGenerator_of = "di"}
log([rankGenerator_language])
log([player.rankGenerator_house])
log([player.rankGenerator_gender])
player.rankGenerator_feudal_middle_rank = expandDescription("[feudal_middle_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"_rank]");
log([player.rankGenerator_feudal_middle_rank]);
player.rankGenerator_feudal_high_rank = expandDescription("[feudal_high_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"_rank]");
log([player.rankGenerator_feudal_high_rank]);
player.rankGenerator_feudal_specific_rank = expandDescription("[feudal_level"+[player.rankGenerator_level]+"_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"_rank]");
log([player.rankGenerator_feudal_specific_rank]);
player.rankGenerator_feudal_firstname = expandDescription("[feudal_firstname_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"]");
log([player.rankGenerator_feudal_firstname]);
player.rankGenerator_feudal_lastname = expandDescription("[feudal_lastname_"+[rankGenerator_language]+"]");
log([player.rankGenerator_feudal_lastname]);
}
In order to sent some data to this generator, it has to be attached to the player. In the feudal-challenger world script, for example, this is done by doing something like:
Code: Select all
this.defineGeneratorInputs = function()
{
player.rankGenerator_house = missionVariables.feudal_challenger_house
player.rankGenerator_gender = missionVariables.feudal_challenger_gender
player.rankGenerator_level = missionVariables.feudal_challenger_rank_no
}
The player.rankGenerator variables are not persistent and only serve to send the data to the generator.
With these details, the generator does its stuff and churns out a load of other variables; the relevant world script picks up the data it wants and saves them as mission variables:
Code: Select all
this.defineGeneratorOutputs = function()
{
missionVariables.feudal_challenger_of = player.rankGenerator_of
missionVariables.feudal_challenger_firstname = player.rankGenerator_feudal_firstname
missionVariables.feudal_challenger_lastname = player.rankGenerator_feudal_lastname
missionVariables.feudal_challenger_rank = player.rankGenerator_feudal_specific_rank
}
In the calling worldscript, you just need to include these three lines in an appropriate function, e.g.:
Code: Select all
this.feudalChallengeOffer = function()
{
this.defineGeneratorInputs()
player.feudalRankGenerator()
this.defineGeneratorOutputs()}
So, if a script needs say a level 4 female noble from the House of Tibecea, a quick run of the generator will give you Antoinetta Romano, Contessa di Tibecea, and each of those terms will be available to use in the mission text..
The point of all this is that it allows me to expand the OXP into other galaxies while minimising the amount of additional scripting. It also makes it easier to introduce additional languages and ranks as well. The real trick has been working out the syntax to put variables inside the expandDescription parts of the script, as this has done the most to avoid repetition.