2. I'll give you this for this!
Keeping the ball rolling from the last tutorial, lets begin our script in earnest.
We already now how we'll start our script so lets do the next part of our tutorial. This is actually the section we should have done first. For this script we'll Rename $ShowText to $GotCookie
2.1 One time only. (Using Flags)
Alright. When creating our script this function would normally go first because this is the start of our script.
Apropriatly our first few lines are:
#org $Startscript
Lock
Faceplayer
The last item on our list is actually a check to see if we've done this script already.
The ONLY way to store this value so that it won't be forgotten when you restart the game is by using the command setflag.
There are aproximately 6000 true/false flags available in the program however there are a large number inside the range of 0x300 - 0x400 and 0x800 to 0x900 that are used by the program itself so it's best to avoid these numbers. Flags are usually written in hex. So pick a value.
At this point in time we don't need to set the flag but we do need to check it using checkflag, and if true we go to another section of script.
since I'm going to use flag 0x200 the next two lines look like this.
checkflag 0x200
if B_TRUE goto $GotCookie
In the above if statement B_TRUE can also be written as 1 or 0x1. $GotCookie refers to the script we made earlier which will be placed at the end of the script we're working on now. If you've been reading along then we renamed the script for the purposes of our new script.
2.2 Yes Or No
Yes and no Questions are actually very similar to message boxes, mainly cause they both start with a message.
message $AskMe
$AskMe 1 = Would you like a Lava Cookie?
boxset 5
As you can see, the only difference here is in the boxset command. 6 displayed a normal textbox, but 5 also displays a "Yes/No" dialog so the user can select one.
Unlike checkflag the boxset statement can not be followed by an if statement. The way messagebox works is by placing you're response into a location in memory referred to as LASTRESULT. To find out what this is we need to use a compare statement first.
compare LASTRESUILT B_TRUE
if B_False goto $DontGet
Compare can also be used at a more advanced level to check other values in locations other than LASTRESULT and not only that but you can compare it to values other than 1 or 0 (B_True and B_False). For example, the command Countpokemon will return the number of pokemon in your party. At the moment though we don't need to worry about that cause we're nearly half way through our list of actions.
$DontGet will be another message script we will write later making a witty remark about your not taking a cookie.
2.3 Recieving Items
And finally we get to recieve our cookie. The value representing the cookie is 0x26. You can get item values from items.txt in the resource section of this thread.
It's a very simple command that has a built in check to make sure you have room in your bag. If your bag is full it will tell you and your script will end automatically.
The command is:
giveitem 0x26 1
Follow that with
setflag 0x200
to say we've completed the script all the way through and compliment the checkflag at the beginning of the script all that remains is the usual:
Release
end
So the overall code so far should read:
Code:
#org $Startscript
Lock
Faceplayer
checkflag 0x200
if B_TRUE goto $GotCookie
message $AskMe
$AskMe 1 = Would you like a Lava Cookie?
boxset 5
compare LASTRESUILT B_TRUE
if B_False goto $DontGet
giveitem 0x26 1
setflag 0x200
Release
end
#ORG $GotCookie
Lock
Faceplayer
message $NoCookie
$NoCookie 1 = I'm not made of cookies!\lYou only get one.
boxset 6
release
end
#ORG $DontGet
Lock
Faceplayer
message $AllMine
$AllMine 1 = All the more for me!
boxset 6
release
endThat's your giveitem script.
2.4 Checking for Items
Time for a new script. This one will follow on from the script above and I'm going to play it out like this:
1. You activate the character on the map.
2. If you have a lava cookie she trades it for an UltraBall
3. If you dont have the lava cookie from the last script she tells you she likes lava cookies.
4. If you gave her the cookie then she thanks you
This is actually an expansion of the last script we made. The script will be almost identical so we'll breeze through most of it.
Because our last script used flag 0x200 this script will use flag 0x201 and we'll change the offset name $GotCookie to $GotBall both at the if statement and where we display the message so we'll change that in the above script now.
Then we put in a new command.
Checkitem 0x26
Checkitem will return a value indicating the number of items you have. This will be stored in LASTRESULT and can be checked using compare.
So, bare minimum we need to do this:
Compare LASTRESULT 1
But this is where things get interesting. Because this is a special item it is wholely possible for us to have got lavacookies for elsewhere, so what happens if we have two cookies in our bag?
What we need is an if statement that checks if the number is greater or lower than our desired number. So, here are the statements you can use for the IF command.
B_<< Lower Than (0)
B_== Equals (1)
B_>> Greater Than (2)
B_<= Lower than or Equal to (3)
B_>= Greater than or Equal to (4)
B_!= Not exactly equal to (5)
This brings our code to date as thus:
#Org $StartScript
checkflag 0x201
if B_True goto $GotBall
checkitem 0x26
compare LASTRESULT 1
if B_<< goto $NoCookie
2.5 Removing Items
Now assuming all goes well we need to ask the ever important Question.
message $WantBall
$WantBall 1 = Oh, You have a lavacookie.\pIf you give it to me I'll\lgive you this UltraBall...\pWhat do you say?
message 5
boxset 5
compare LASTRESULT 1
if B_FALSE goto $DontGet
Later on we'll change the text in these message functions to say something apropriate.
Now it's time to recieve the ball, and more importantly take away one of the cookies. You know the first command and the second one will seam obvious to you once you read it.
As per the last script if you don't have room in the ball pouch the script will stop at this point.
giveitem 0x2 1
removeitem 0x26 1
Simple no. Just like giveitem the properties for removeitem are the item number followed by the number of items to remove.
If we had wanted to make the price of the UltraBall 5 cookies then we could easily change the above lines like this:
compare LASTRESULT 5
if B_<< goto $NoCookie
and
giveitem 0x2 1
removeitem 0x26 5
And before you know it we're done. All that remains is
Release
end
and to adjust the text to something apropriate for our new script.
Here's your code:
Code:
#Org $StartScript
checkflag 0x201
if B_True goto $GotBall
checkitem 0x26
compare LASTRESULT 1
if B_<< goto $NoCookie
message $WantBall
$WantBall 1 = Oh, You have a lavacookie.\pIf you give it to me I'll\lgive you this UltraBall...\pWhat do you say?
boxset 5
compare LASTRESULT 1
if B_FALSE goto $DontGet
giveitem 0x2 1
removeitem 0x26 1
Release
end
#ORG $GotBall
Lock
Faceplayer
message $LikeCookie
$LikeCookie 1 = Thanks for the cookie!
boxset 6
release
end
#ORG $NoCookie
Lock
Faceplayer
message $LoveCookie
$LoveCookie 1 = I Absolutely LOVE Lava Cookies!\lThey're Just so Spicy!
boxset 6
release
end
#ORG $DontGet
Lock
Faceplayer
message $AAAW
$AAAW 1 = Aaw C'Mon. It's a fair trade!!\nI Love those things.
boxset 6
release
endAnd Thats Part Two.
Burn these scripts and Your Done