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

Written by Roguey,

Making a simple BBS sale tutorial, written by Roguey


Deal or no deal?


Now we made an offer to the player, we now need some code to do the deal. In this script we are simply worried about if the player has enough money to buy our Salvage Insurance's - nothing else.

So we need to move down to else if $Event == 'select' (ie. if a player presses the button to accept the deal). The first thing we need to do is insert some blank lines, so we can add some code. Now we need to get our data from the array data, this includes the author name and how much we are asking for.

So, on the first blank line (just under else if $Event == 'select'), find this command (in General Commands, Arrays then add this command (2nd from top)):

<RetVar/IF><Var/Array>[<Var/Number>]

When ask for input, use the variable name, and set first <?> to the available variable data, and the second <?> to the number 0. It might be worth copying this line, then change the first variable to cost and the 0 to a 1. So you should have this:

Getting the data from the array data

So now we know who was the author and how much we were asking for. The next thing to do is to check the player cash flow - does he/she have enough money to buy our Salvage Insurance's?

So on the next blank line, we want the command get players money (found in Trade Commands). Set the <variable> to players.money. Now we know how much we are asking for, and how much money the player has.

Now we must check to see if the player has enough, or more than our asking price. This is done by a simple if statement built up from <RetVar/IF><Expression> in General Commands. So built the following statement:

if $players.money < $price

So if the player has less money than we asking for, then we need to fail the deal. On the next line we want our old friend sprintf which is located on the General Command page:

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

Script input to the variable msg, page id to 999880 and textid to 11, then the first null to $name. We are now looking for set quest state in General Commands, so add it after our sprintf line, ie:

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

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

Our deal failed because the player didnt have enough money.

So now if the player doesnt have enough money, the deal is aborted. However we now need to add some code for if the player has enough money.. ie. deal successful! So under the set quest state command add a else (found in General Commands, Flow Control). The first thing to do is take the money from the player, however there is no take money from player command. What we have to do is to add a negative number to the players money. To do this we need a <RetVar/IF><Expression>, using the variable player.cost, then equalling 0 (the number), followed by a minus operator, then the variable price, like so:

Minus from the players money.

We now need to add this negative number to the players money, we can do this by using the command add money to player (inside Trade Commands). When ask for a variable, use player.cost .. not price!.

The next bit is to add the ware to the player ship - the ware being Salvage Insurance. To do this add the command (under Trade Commands):

<RetVar/IF><RefObj> Install <Var/Number>< units of <War/Ware>

Set no return value. On the first <?>, change it to PLAYERSHIP, the second <?> to amount, then the third to ware.

On the next two lines, I recommend you copy and paste the sprintf and set quest state lines above, remmeber sprintf is before quest statement. Change the textid (on the sprintf line) to 12, then on the quest state, change [Quest.Aborted] to [Quest.Accepted], you should have the following:

The code for a successful deal.

Nearly done... Now add a end command found in General Commands, Flow Control.

Now copy the set quest state and paste it under else if $Event == 'accept' and else if $Event == 'check'. Change [Quest.Accepted] to [Quest.Finished]. Hopefully it should look like this:

Our finished code.

Now the easy bit.. the setup script.

Next: Setup script
<< Previous Page - Next Page >>