• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

PKSV scripting Tutorial/Script Thread

Full Metal

C(++) Developer.
810
Posts
16
Years
PKSV scripting Tutorial v2.0!

Intro.

Scripting is just sticking one command ontop of another.
Each command does something different.
Usually, just reading the command name tells you what it does.
Every script is stored at an "offset"
An offset is just a number representing a place in your ROM
So if you store your script in 0x800000, then that's your offset
In order to store your script you must know where to put it.
Well...I usually cheat and let PKSV decide for me xD
This is called DYNAMIC offsets, and for this tut, we will only use these
Dynamic offsets work like this
[Commands start now]
#dynamic OFFSET
[No more commands]
OFFSET is just where PKSV starts looking for a place to store your script
Usually, I use "#dynamic 0x740000"
That is where a good chunk of free space begins, so we hackers like to use it
Comments (stuff that PKSV will ignore) are allowed after a single spoiler character ( ' )
eg
uncommmentedd and creating bugs 'Commented, but not making bugs
or
lock 'Locks our player
faceplayer 'look at player
PKSV can be found HERE!


Hello World!

A script always starts somewhere
So we'll declare a script like this

#dynamic 0x740000
#org @start
'pretty simple

"#org @start" is declaring a dynamic label.
the "@start" part of your script is dynamically placed in your ROM based on the offset PKSV
found when you used "#dynamic 0x740000"
This is how you store an offset to anything
if you call a message the syntax looks like this
Spoiler:

cripts, Text, Movements, and Pokemart data are all called in the above manner

Okay, whenever you talk to someone you don't want them wondering all over the place right?
Wouldn't it be nice to lock them down in chains?
Well now you can! With this awesome command your players will never move again!
What is the command you ask? Simple!
"lock"
But that's not all, you also want the speaker to look at the talker right?
This one is simple to!
"faceplayer"
that's it!
Now there are two parts to displaying a message
Loading the message
And showing it
"message @textlabel" will load the message stored in your textlabel
"callstd MSG_NORMAL" will show the message just loaded in normal format
So now you've shown a message, great!
But..your player can't move anymore!, atleast, not yet anyways
Before the player can move again, he/she has to be "released" from the "lock" we put on them
the command to do this is
"release"
and finally, to prevent a crash of your ROM we will put
"end"
"end" is a necessity to your script, just always keep it there and you'll be good to go!

So to put it all together
Spoiler:

There are problems with text being to long.
The messagebox can hold a max of about 35 characters per line, and 2 lines per "box"
So there are "symbols" to get around this

\n The text following will be in a new line
\l scrolls the bottom line up, and adds the following text in a new line (use only after \n)
\p starts a new box
\v\h01 Players name
\v\h02 buffer 0
\v\h03 buffer 1
\v\h04 buffer 2
\v\h05 buffer 3
\v\h06 Rivals name

which means
So you got it to work eh?\nGood Job! Would display as

So you got it to work eh?
Good Job!


Message-Box.

In order to variate your message you just have to change a single command
callstd 2 This will rid you of needing a "lock" , a "faceplayer" , or a "release"
Spoiler:

callstd 3 commonly used for signs
nothing special, displays the message and thats it
AKA MSG_SIGN

callstd 4 ensures that the message won't go away until the command "closemsg" is called
Spoiler:

2 new commands were introduced here
jump- continues script somewhere else
jump also has a similar, call, call is used to go to a script, but still comeback (using the command "return" instead of "end")

if (value) (command) (label)

callstd MSG_YESNO
if 0x1 jump @pushy 'This will jump to pushy if the value returned from yes/no box is 1
jump @pushno

since we aren't using "Call" there is no need for an "end" command in our main script, instead place the end command in the places where the script would actually end (in this case it is pushn and pushy) Also, since the script would continue at pushy if the user pushed yes, then there is no need to waste space with another if statement. Instead, just use "jump @pushno" since you know the only other possibility is that the user pushed no.


Giving Things.

In this lesson we will learn how to
give AND take items
give pokemon
give eggs

the commands for each are simple
giving a pokemon:
addpokemon PokemonName (level) itemname (0) (0) (0)
example:
addpokemon BULBASAUR 25 00 0 0 0'Gives a level twenty five bulbasaur, not holding 'an item
addpokemon PIKACHU 25 LIGHTBALL 0 0 0 'Gives a level 25 pikachu holding a 'lightball
just always ALWAYS ALLLLLWWAAAYYSS remember to add three '0's

giving an item:
additem itemname (amount)
example:
additem POKEBALL 50 'Gives 50 pokeballs to the player
giving an egg:
giveegg PokemonName
example:
giveegg Pichu 'Gives us a pichu egg


Flags.

flags are amazingly useful, the equivalent of BOOLEAN values in C/C++
They allow you to do an event ONLY once, do it again when something happens, etc
This time I'll start with an example first
Spoiler:

Setflag – This will make checkflag return 1
Clearflag – This will make checkflag return 0
Checkflag-- This will compare a flag for it being raised,or lowered. Afterwards you want to add "if 0x1 [jump/call] @[scriptlabel]"


Variables.

The pokemon games have lots of spots in the GBA memory to store numeric values in. These are called "variables"

setvar 0x[varnumber] 0x[value] –That sets the [varnumber] to be [value]
subtractvar 0x[varnumber] 0x[value] – Subtracts [value] from [varnumber] variable
addvar 0x[varnumber] 0x[value] – Adds [value] to [varnumber] variable
compare 0x[varnumber] 0x[value] – Returns 1 if [varnumber] is set to [value] again, useage of the if statement is used
compare 0x8000 0x3
if 0x1 [jump/call] [label]
resetvars – Resets the variables 0x8000 through 0x8001
storevar 0x[buffernumber (\v\h02-\v\h05)] 0x[varnumber]
This can be used in loops as in this example
Spoiler:

There is a new command introduced here again
storevar 0x[buffernumber] 0x[varnumber]
If you use 0x0 for buffernumber the variable is stored in \v\h02, 0x1 means \v\h03, etc until you get to \v\h05 and 0x3

While the above method works, there is a new feature in PKSV that makes everything much more efficient.
Spoiler:

There are now two types of labels for PKSV. There is one that works like we've discussed so far. These are the '@' labels we've been using.There is also another way.
A ' : ' label is used within an '@' label. It is simply a way to start a script from somewhere other than the beginning, and you can use them just like you would an '@' label.
Spoiler:

There were also two new commands from the above example
fadesong [song number] – fades the current song that's playing into the sappy song number
fadedefault – Fades the song back to the default song for the map


Misc.

there are also more things to store in a buffer
they are always preceded with "storeZZZ" where ZZZ can be replaced with attack,boxname,comp,firstpokemon,furniture,item,it ems,pokemon,pokemonvar,or text
the arguments are the same for storevar and can be called just the same way, through messages.

Waitbutton – Continues the script after the user pushes a button

lasttrainerbattle – Initiates the last battle the player taken.


Getplayerpos 0x[varx] 0x[vary] – stores the players x position and y position in the corresponding variables

showpokepic POKEMONNAME xpos ypos– shows the pokemon sprite at x,y position

hidepokepic – The sprite displayed w/ above command will not hide until this command used

random ZZ – Generates a random number between 0 and ZZ then puts it in LASTRESULT or 0x800D

special XX – This is for a bunch of commands that must be used through this one
Here is a list of specials for you (they are different for each game)
Spoiler:

For Movements it's almost like movements
PKSV comes with a movement planner which makes everything much much easier
syntax:
applymovement 0x[person event number] @label

Then add "#org @movement label"
Next make your movement script and copy it to your clipboard now just make a new line and paste the data.


Show me the Money!

These are a few commands used to give,take,check for money,and show money
Giveing Money
Command: givemoney ZZ 0
Where ZZ is the amount of money to give (must be less than one million)
example:
[...]
givemoney 200 0 'Gives 200 pokedollars to the player
[...]

Takeing Money
command: paymoney ZZ 0
where ZZ is the amount of money to be taken from the player(must be less than or equal to the amount of money the player has)
example:
[...]
paymoney 200 0 'Makes player loose 200 pokedollars
[...]

Checking money
command: checkmoney ZZ 0
where ZZ is the amount of money to be looked for, if the player has this much money, LASTRESULT is set to 1, otherwise it is 0
example:
[...]
checkmoney 200 0 'Checks if the player has 200 pokedollars, sets LASTRESULT to 1 if he/she does
compare LASTRESULT 0x1 'Compares LASTRESULT to containing 1
if 0x1 jump @continue 'Jumps to #org @continue if LASTRESULT had one in it
jump @notenough 'Jumps to the script saying that the player did not have enough money
[...]

Showing Money
A little more complex than the other money commands
Showing Money
command: showmoney [ZZ] [YY] 0
Where ZZ is the x coordinates and YY is the y coordinates
example:
[...]
showmoney 10 10 0 'Displays money at 10,10 on the screen
[...]
However if you take money, or give it, the money that the player sees needs to be updated to avoid confusion
command: updatemoney [ZZ] [YY] 0
Where [zz] and [yy] are the same as the coordinates used in your show money

Also, you will want to remove the money from the screen before your script ends.
command: hidemoney [zz] [yy] 0
Where [zz] and [yy] are the same as the coordinates used in your show money
example:
[...]
showmoney 10 10 0
paymoney 200 0
updatemoney 10 10 0
hidemoney
[...]

You really shouldn't use any of these commands without using them all, with the exception of updatemoney maybe...
An example using them all
#org @main
'-----------------------------------
lock
faceplayer
checkmoney 0x96 0x0 0x0
compare LASTRESULT 0x1
if == jump @canhave ' Equal To
jump @canthave

#org @canhave
'-----------------------------------
showmoney 0xA0A 0x0
msgbox @hy ' Hey \v\h01, do you w...
callstd MSG_YESNO ' Yes/No message
compare LASTRESULT YES
if == jump @want ' Equal To
jump @notwant

#org @want
'-----------------------------------
paymoney 0x96 0x0 0x0
additem SUPERPOTION 1
msgbox @ty ' Thank you for your b...
callstd MSG_LOCK ' Built-in lock command
hidemoney 0xA 0xA
release
end

#org @canthave
'-----------------------------------
msgbox @he ' Hello \v\h01.
callstd MSG_LOCK ' Built-in lock command
release
end

#org @notwant
'-----------------------------------
msgbox @mb ' My business is alway...
callstd MSG_LOCK ' Built-in lock command
hidemoney 0xA 0xA
release
end


#org @hy
= Hey \v\h01, do you want a\nA super potion for 150 ?

#org @ty
= Thank you for your business.

#org @he
= Hello \v\h01.

#org @mb
= My business is always open\nto those who can afford it.
Weather!
These are simple commands to change the weather in outdoors maps.
SetWeather and doweather work together
setweather 0x3 'Sets the weather to do to 3 for rain
doweather 'Does the weather we set with setweather
resetweather 'Undoes the effects of setweather and doweather
You can find a list of weathers in a-map under the header tab
This should be enough to get you started, I might post more sooner, but not until I get suggestions to add, or PKSV has more features needing explanations.

Also, just so you know
"#dynamic 0x740000" can be "#dyn 0x740000" also, the offset does NOT have to be 0x740000 it can be any offset you want.


Level Scripts.

There are two types of level scripts....
.....Type 1
........The kind that is under the events tab (aka trap script)
.....Type 2
........The kind that is under the header tab (aka ...level scripts?)
How to use type 1
1) Create a script event in a-map events tab (the green s kind...)
2) Assign a variable into the correct box
3) Assign the value to be whatever that variable isn't (after the level script is used the variable is assigned this value...)
4) Assign the "unkown" to 3
5) Compile your script
6) Assign the script offset to the proper box
How to use type 2
These are a little bit more challenging and i'll update again when i can explain it


Sample Scripts.


Snes Script
Description: Displays "[player] turned on the snes!" then plays battle music, followed by a "player has X lives left" where x is a number which is automatically decremented. Then when the player has no more lives left "Game over time to go"
Spoiler:

Credit: Full Metal

-Untitled-
Description:This only happens once,player looks left and up pops an excite icon, OW person w/ event id of 4 looks down and right,then player talks about not being late to get their first pokemon,then the other guy will run down 3 steps and dissapear. Please note that if you don't have your map set up as mryvn's then the script will look a little weird. So i reccomend that you also set the person id no to 8C3 (which makes them dissapear forever,i'll explain more on the next update) as well as adjust the movement and sprite placement to fit to your map (eg add more downs/change direction the other person runs)
Spoiler:

Credit: Mervyn

Eevee Script
Description: Give the player an Eevee!
Spoiler:

Credit: Undocumented.

 
Last edited:

NarutoActor

The rocks cry out to me
1,974
Posts
15
Years
bravo I always liked pksv better than xse but sadly pksv isnt used that much by the better scripters and no WERE no tutorials for pksv this is the first good pksv tutorial good job I hope you add more :D
 

Full Metal

C(++) Developer.
810
Posts
16
Years
Lolz, thanks for the comments, if you have any ideas for the tut just give them to me ok?
I think I might add money stuff next...
also, how was the tut?
Any improvements needed?
 

NarutoActor

The rocks cry out to me
1,974
Posts
15
Years
I like it :D I dont know what to sugestion because I look thow scripting tuorials that have something I dont know...the only thing herd of that I cant do but will love to learn is this
changing the overworld players sprite
(to be continued)
 

Full Metal

C(++) Developer.
810
Posts
16
Years
Like the ones in PKSV?
Well...not really in need of a tutorial, but lemme have a look
Ok well for flag skeleton numero uno
of course you have
lock and faceplayer
it first checks your flag
if it's set, it will go to #org @flag-2
otherwise it will continue and say the message in #org @flag-1-msg
really simple actually
Now for flag skeleton numero dos (:P i'm learning spanish now xD)
hehe.. this is Score_Under using The new " : " label feature, this way the second message is said every time, but the first is said but once
Reread tut if you don't understand

and also,
@rairaiku- Did you mean css padding? Cuz i didn't use any css if i remember right...just a bunch of div's so that it would look a little less boring, but still look good with almost all the themes that PC has, i find it doesn't look half bad in PawLicious, but if you insist, i'll add some padding.

@sharppoint- as in text wrapping, or as in the format that the information was given?
*edit*
Would you all like me to provide a download to this in PDF/Word/Open Office format for download?
 
Last edited:

NarutoActor

The rocks cry out to me
1,974
Posts
15
Years
okay I understand flag skeliton 1 but not 2 I check the tut still a little confused oh and do you know what I mean by changing the playes overworld have have seen it been done in a couple of hacks it was used for a couple of things like a digging mini game
 

Full Metal

C(++) Developer.
810
Posts
16
Years
Hm...
how to put this

you have to understand this
dynamic labels are just a way to "rename" offsets
every command will take a few bytes
eg lock takes one byte,a pointer takes 4
A " : " label is inside of a dynamic label, but it is pointing at a further spot on the script
Eg,
At position 45 is lock
at position 46 is faceplayer
then if you have a ":" label it points to 45+2
so that way you can say
Jump :-label which will go to the #dynamic label, but it would skip the lock and faceplayer
:\ it's hard to explain, just think of it as a way to skip around in your script.
another example
#org @a is stored at 0x123456
lock
faceplayer
:-label is just a way for PKSV to say, jump to #org @a+2, which is where the :-label is at
If i can think of a way to explain better i will.
And as far as changeing the players ow...if i can get some better asm, i'll post that up here to, but, asm is a bit out of my range, if i'm walked through it, i can figure it out, but it's not very easy.
 

NarutoActor

The rocks cry out to me
1,974
Posts
15
Years
thanks I understand the use of skeliton 2
on the overworld player changing pokepal was able to do it without asm he said something about load from pointer or data I ask him how to do it but he said its complicated and thats he is not a good teacher
 

score_under

Inactive; Former ROM hack tool author, ❤️
526
Posts
18
Years
It's no fun when it's so easy.
...what?
In what way do you mean it? You mean you prefer having to look up movement codes for yourself, you prefer writing scripts without features like code labels, and you don't like convenience?

I should send you a table of the commands and their hex value. That'd satisfy you ;)
 

.Seth

.explorer.
1,644
Posts
15
Years
...what?
In what way do you mean it? You mean you prefer having to look up movement codes for yourself, you prefer writing scripts without features like code labels, and you don't like convenience?

I should send you a table of the commands and their hex value. That'd satisfy you ;)

Movement Codes aren't #raw's anymore, in XSE at least. :/
I'm not saying I don't like convenience, but it's a bit more fun when you're not guided through everything. *coughD/P/Ptcough*

Believe me, I think your script editor is wonderful. I just prefer XSE.
 

Maxzeroedge

Ready for simply anything
49
Posts
14
Years
A dumb question......How do u insert the script into the ROM and btw.......Thanks for the tutorial....Its easy learning!!
 

mervyn797

What? I'm right here. >D
1,696
Posts
15
Years
  • Seen Nov 28, 2011
how do i make sprites dissapear? i mean, if move them, what's the syntax?
 
Back
Top