Making a simple BBS sale tutorial (Page 3 of 5)

Written by Roguey,

Making a simple BBS sale tutorial, written by Roguey


Making an offer


Hopefully now we have our text ready to display, we need to actually code something... yup, things dont work without no code! So back into X3 and into the script editor. Hopefully you have our old template at hand called plugin.bbs.template.. So copy the template and name it plugin.bbs.salsale. If you dont have the template - no problemo, just follow the guide on this page.

So to be clear we should have new script opened named plugin.bbs.salsale, which looks like this:

A basic template for BBS scripts

The first thing to do is make 2 new lines at 001, and press enter, and select General Commands, then then <RetVar/IF><Expression>, <Variable> and finally type Ware. On the <?> set this to Salvage Insurance by going through select ware list, then selecting Salvage Insurance. Which should look like this:

$ware = Salvage Insurance

The next recommend doing is increasing the odds of the BBS sale appearing by increasing the number return value (line 8 for me) from 5 on to 999. This just makes it easier to find - I dont want to check 50 stations when testing this script.

Before we make the offer, we need to know which race owns the station we are docked at. So head back to line 2 and insert 2 blank lines. One the first blank line (line 2), add the command get environment under General Object Commands, set script input to <Variable> then station. On the <?> set to the constant PLAYERSHIP. This basically tells our script which station the player is landed at.

So the next thing is to do is to get the race owner of this station. So on the next blank line add get owner race, once again under General Object Commands, set the script input to <Variable>, then race. Now set <?> to the available variable station. If all goes well, you should have the following:

Working out the station owner

So now we need to make an offer, however before the actual offer we need to work-out our deal. The things we need to do is to work out a seller name, the amount of Salvage Insurance we are selling at this time and how much we plan on selling them for.

So lets prepare an offer, under the line else if $Event == 'offer' insert some new lines (about 4 or 5). One the first blank line add the command get random name: race=<Var/Race> under General Commands, <Variable> then type in name. The first <?> set to, available variable then pick race.

we now need two random numbers, one for the amount of Salvage Insurance we are planning on selling on this transaction and another for the price. So the next two blank insert this command:

<RetVar> = =  random value from <Var/Number> to <Var/Number> -1

Our first random we will use for the amount (called variable amount), and the next for the price (variable price). Next we need to set some ranges, so I recommend setting the amount range from 1 to 4 (notice the -1, so the range is 1 to 3), whilst price from 10 to 101. Like so:

Amount and price range set

Now the next thing to do is to store our values somewhere. If we dont do this, our two variables amount and price will be empty. It maybe a good idea to store the random race name too, as our message will look better with the same author.

So where do we store this data? well... argument number 3, data. This is an array we can use to store data between various events in our bbs script. So head under our random amount and price (on a blank line), then add the command append <Value> to array <Var/Array> (found under General Commands then Arrays). The order of the append will matter, as the first variable added to the array data will be data[0], the next being data[1] and so on. We have 2 pieces of data we wish to store: $name and $price. So append both to the array data like so: You should have something like this:

Appending name and price

The offer stage is nearly complete now. We just need to display our message to the bbs with the correct terms. If you noticed, our BBS text contained %s, these are variables we can replace within a script. On our offer message (id 10), the first %s was in author, the second before x Salvage Insurance, then our third just before credits.

Now we want sprintf which is located on the General Command page, which looks like this:

<RetVar> = sprintf: page id=<Var/Number> textid=<Var/Number>, <Value>, <Value>, <Value>, <Value>, <Value>

When ask for script input, set the variable msg. Now set page idto in 999880 and textid to 10. After the textid, you should see five null's. Change the first name, amount and third to price, like so:

Our sprintf all setup correctly

We are now looking for set quest state in General Commands, so add it after our sprintf line, this is the command we want:

set quest state with message: quest=<Var/Quest> state=<Var/Number> msg=<Var/String>

When ask for script input set object. The second detail, press enter, then select select constant and add Quest.Offered. Now set msg= to the variable msg. After which our offer section should look like this:

Our finished offer section.

Next: Deal or no deal?
<< Previous Page - Next Page >>