PDA

View Full Version : [Tutorial] ADD Functions Scripts


Juan
November 19th, 2009, 08:33 AM
Following the discussion that Pokepal17 started on the topic of discussion on reusing scripts several times to save space, I come with this tutorial on how to add more functions (std's).

Functions are pre-defined scripts that can be used in any script(gotostd, callstd, gotostdif, callstdif).

Example(BPEE):

std 0x06:
#org 0x271494
preparemsg 0x0
waitmsg
waitkeypress
release
returnThese are the commands to display a normal message box.
You do not need to always use these commands, simply call with callstd 0x06.

In Emerald (BPEE), the table of pointers start in 0x081DC2A0 and ends in 0x081DC2CC.
o we can say that there are 11 functions. (0x0 - 0xA)

Functions in BPEE:

ROM:081DC2A0 DCD off_8271AD3 ; 0x0
ROM:081DC2A4 DCD off_8271BFD ; 0x1
ROM:081DC2A8 DCD off_8271315 ; 0x2
ROM:081DC2AC DCD off_8271320 ; 0x3
ROM:081DC2B0 DCD off_827132A ; 0x4
ROM:081DC2B4 DCD off_8271332 ; 0x5
ROM:081DC2B8 DCD off_8271494 ; 0x6
ROM:081DC2BC DCD off_8271BB7 ; 0x7
ROM:081DC2C0 DCD off_82742C9 ; 0x8
ROM:081DC2C4 DCD off_827133C ; 0x9
ROM:081DC2C8 DCD off_8271347 ; 0xATo add more functions, just copy the table of pointers to an empty space.
After copying, you must edit 8 pointers.

The following offsets store pointers to the table of functions:
0x08099530
0x08099560
0x080995AC
0x080995ACJust change them to the new offset.

The next pointers, store pointers to the end of the function table (0x081DC2CC):
0x00099534
0x00099564
0x000995B0
0x000995FCTo change them, just follow the following form:

Offset = TableOffset + (number of functions * 4)This will be the new offset the end of the function table.

Example:
Offset = 0x081DC2A0 + (11 * 4)
Offset = 0x81DC2CC======================================================

Data:
BPEE

Number of Functions= 11
Table Start= 0x081DC2A0
Table End= 0x081DC2CC
Table Begin Pointers= 0x08099530
0x08099560
0x080995AC
0x080995AC
Table End Pointers= 0x08099534
0x08099564
0x080995B0
0x080995FC
BPRE

Number of Functions= 9
Table Start= 0x08160450
Table End= 0x08160478
Table Begin Pointers= 0x0806A178
0x0806A1A8
0x0806A1F4
0x0806A240
Table End Pointers= 0x0806A17C
0x0806A1AC
0x0806A1F8
0x0806A244
======================================================

BPEE Functions:

0x0:
'---------------
#org 0x271AD3
additem 0x8000 0x8001
copyvar 0x8007 LASTRESULT
call 0x8271AE3
return

'---------------
#org 0x271AE3
bufferitems2 0x1 0x8000 0x8001
checkitemtype 0x8000
call 0x8271B08
compare 0x8007 0x1
if 0x1 call 0x8271B95
compare 0x8007 0x0
if 0x1 call 0x8271BA9
return

'---------------
#org 0x271B08
copyvar 0x8000 LASTRESULT
compare 0x8000 0x1
if 0x1 goto 0x8271B45
compare 0x8000 0x5
if 0x1 goto 0x8271B55
compare 0x8000 0x2
if 0x1 goto 0x8271B65
compare 0x8000 0x3
if 0x1 goto 0x8271B75
compare 0x8000 0x4
if 0x1 goto 0x8271B85
end

'---------------
#org 0x271B95
preparemsg 0x8272A78 '"Obtained the [buffer2]!"
waitfanfare
msgbox 0x8272A9A MSG_KEEPOPEN '"[player] put away the [buffer2]\ni..."
setvar LASTRESULT 0x1
return

'---------------
#org 0x271BA9
setvar LASTRESULT 0x0
return

'---------------
#org 0x271B45
bufferstd 0x2 0xE
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271B55
bufferstd 0x2 0xF
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271B65
bufferstd 0x2 0x10
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271B75
bufferstd 0x2 0x11
compare 0x8007 0x1
if 0x1 call 0x8271BB3
return

'---------------
#org 0x271B85
bufferstd 0x2 0x12
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271BAF
fanfare 0x172
return

'---------------
#org 0x271BB3
fanfare 0x174
return


'---------
' Strings
'---------
#org 0x272A78
= Obtained the [buffer2]!

#org 0x272A9A
= [player] put away the [buffer2]\nin the [buffer3] POCKET.0x1:
'---------------
#org 0x271BFD
lock
faceplayer
checksound
copyvar 0x8004 0x8000
copyvar 0x8005 0x8001
checkitemroom 0x8000 0x8001
copyvar 0x8007 LASTRESULT
bufferitems2 0x1 0x8000 0x8001
checkitemtype 0x8000
call 0x8271B08
compare 0x8007 0x1
if 0x1 call 0x8271C3A
compare 0x8007 0x0
if 0x1 call 0x8271CA1
release
return

'---------------
#org 0x271B08
copyvar 0x8000 LASTRESULT
compare 0x8000 0x1
if 0x1 goto 0x8271B45
compare 0x8000 0x5
if 0x1 goto 0x8271B55
compare 0x8000 0x2
if 0x1 goto 0x8271B65
compare 0x8000 0x3
if 0x1 goto 0x8271B75
compare 0x8000 0x4
if 0x1 goto 0x8271B85
end

'---------------
#org 0x271C3A
hidesprite LASTTALKED
additem 0x8004 0x8005
special2 LASTRESULT 0x19E
copyvar 0x8008 LASTRESULT
compare 0x8008 0x1
if 0x1 call 0x8271C8F
compare 0x8008 0x0
if 0x1 call 0x8271C9B
waitfanfare
waitmsg
bufferitems2 0x1 0x8004 0x8005
setvar 0x8004 0xC
special 0xF3
compare LASTRESULT 0x1
if 0x1 goto 0x8271C86
msgbox 0x8272A9A MSG_KEEPOPEN '"[player] put away the [buffer2]\ni..."
return

'---------------
#org 0x271CA1
msgbox 0x8272A78 MSG_KEEPOPEN '"Obtained the [buffer2]!"
msgbox 0x8272AD0 MSG_KEEPOPEN '"Too bad!\nThe BAG is full[.]"
setvar LASTRESULT 0x0
return

'---------------
#org 0x271B45
bufferstd 0x2 0xE
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271B55
bufferstd 0x2 0xF
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271B65
bufferstd 0x2 0x10
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271B75
bufferstd 0x2 0x11
compare 0x8007 0x1
if 0x1 call 0x8271BB3
return

'---------------
#org 0x271B85
bufferstd 0x2 0x12
compare 0x8007 0x1
if 0x1 call 0x8271BAF
return

'---------------
#org 0x271C8F
bufferitems2 0x0 0x8004 0x8005
preparemsg 0x82731A9 '"[player] found one [buffer1]\n[buf..."
return

'---------------
#org 0x271C9B
preparemsg 0x8272ABF '"[player] found one [buffer2]!"
return

'---------------
#org 0x271C86
msgbox 0x8272AEA MSG_KEEPOPEN '"[player] put away the [buffer2]\ni..."
return

'---------------
#org 0x271BAF
fanfare 0x172
return

'---------------
#org 0x271BB3
fanfare 0x174
return


'---------
' Strings
'---------
#org 0x272A9A
= [player] put away the [buffer2]\nin the [buffer3] POCKET.

#org 0x272A78
= Obtained the [buffer2]!

#org 0x272AD0
= Too bad!\nThe BAG is full[.]

#org 0x2731A9
= [player] found one [buffer1]\n[buffer2]!

#org 0x272ABF
= [player] found one [buffer2]!

#org 0x272AEA
= [player] put away the [buffer2]\nin the BAG.0x2:
'---------------
#org 0x271315
lock
faceplayer
preparemsg 0x0
waitmsg
waitkeypress
release
return0x3:
'---------------
#org 0x271320
lockall
preparemsg 0x0
waitmsg
waitkeypress
releaseall
return0x4:
'---------------
#org 0x27132A
preparemsg 0x0
waitmsg
waitkeypress
return0x5:
'---------------
#org 0x271332
preparemsg 0x0
waitmsg
yesnobox 0x14 0x8
return0x6:
'---------------
#org 0x271494
preparemsg 0x0
waitmsg
waitkeypress
release
return0x7:
'---------------
#org 0x271BB7
adddecoration 0x8000
copyvar 0x8007 LASTRESULT
call 0x8271BC5
return

'---------------
#org 0x271BC5
bufferdecoration 0x1 0x8000
compare 0x8007 0x1
if 0x1 call 0x8271BE0
compare 0x8007 0x0
if 0x1 call 0x8271BF7
return

'---------------
#org 0x271BE0
fanfare 0x172
preparemsg 0x8272B09 '"Obtained the [buffer2]!"
waitfanfare
msgbox 0x8272B48 MSG_KEEPOPEN '"The [buffer2] was transferred\nto ..."
setvar LASTRESULT 0x1
return

'---------------
#org 0x271BF7
setvar LASTRESULT 0x0
return


'---------
' Strings
'---------
#org 0x272B09
= Obtained the [buffer2]!

#org 0x272B48
= The [buffer2] was transferred\nto the PC.0x8:
'---------------
#org 0x2742C9
buffertrainerclass 0x0 0x8000
buffertrainername 0x1 0x8000
closeonkeypress
pause 0x1E
fanfare 0x1CC
msgbox 0x8272E0F MSG_KEEPOPEN '"Registered [buffer1] [buffer2]\nin..."
waitfanfare
closeonkeypress
pause 0x1E
return


'---------
' Strings
'---------
#org 0x272E0F
= Registered [buffer1] [buffer2]\nin the POKéNAV.0x9:
'---------------
#org 0x27133C
preparemsg 0x0
fanfare 0x1CB
waitfanfare
waitmsg
return0xA:
'---------------
#org 0x271347
pokenavcall 0x0
waitmsg
return

Tropical Sunlight
November 19th, 2009, 11:19 AM
I'm not getting this. What's this for?
I'm sorry for being such a nuisance.

Wichu
November 19th, 2009, 11:45 AM
It's about adding/using standard functions (for example, instead of manually scripting the commands for an item ball, you can just call the item ball standard function instead).

Tropical Sunlight
November 19th, 2009, 11:47 AM
It's about adding/using standard functions (for example, instead of manually scripting the commands for an item ball, you can just call the item ball standard function instead).
Oh.
Seems useful.
Thank you

Pokepal17
November 19th, 2009, 01:10 PM
Wow its useful and I'm gonna try this out. Glad I could be of help. :P

Juan
November 19th, 2009, 03:01 PM
I'm not getting this. What's this for?
I'm sorry for being such a nuisance.

It's about adding/using standard functions (for example, instead of manually scripting the commands for an item ball, you can just call the item ball standard function instead).[2]
Instead of entering multiple commands always, you can enter only one and save space.
Ex: Yes/No msgbox:


loadpointer 0x0 @message ' "loadpointer 0x0" is the same than "msgbox"
preparemsg 0x0
waitmsg
yesnobox 0x14 0x8

15 bytes

Alternative:
loadpointer 0x0 @message ' "loadpointer 0x0" is the same than "msgbox"
callstd 0x5

8 bytes

Or in actual XSE:

msgbox @message 0x5

8 bytes

You'll economize 7 bytes whenever you use a yes/no msgbox.

Scripts related items are bigger, so you save even more bytes.

Wow its useful and I'm gonna try this out. Glad I could be of help. :P
:D

colcolstyles
November 19th, 2009, 03:48 PM
Very helpful. Thanks a lot. :)

colcolstyles
May 30th, 2010, 05:51 PM
The following offsets store pointers to the table of functions:
0x08099530
0x08099560
0x080995AC
0x080995AC

A great tutorial but I think that in the above quote, the bolded text should be "0x080995F8" and not a repeat of the previous address. At least, that's where I found a pointer to "0x081DC2A0".

X-Buster
June 7th, 2010, 09:08 PM
i did try this and it work, now i can manage to call my arcanine jump script with call std 0xA.

one question, is there a limit in adding std functions? what if you exceeded 255(0xFF). 256(0x00 0x01) or more is already a word, and callstd needs only a byte. is it possible to have more than 256(0 - 255) functions?

i know 256 std functions is a crazy idea. but hey, they can be useful tho.

droomph
December 4th, 2011, 02:54 PM
i did try this and it work, now i can manage to call my arcanine jump script with call std 0xA.

one question, is there a limit in adding std functions? what if you exceeded 255(0xFF). 256(0x00 0x01) or more is already a word, and callstd needs only a byte. is it possible to have more than 256(0 - 255) functions?

i know 256 std functions is a crazy idea. but hey, they can be useful tho.


You would probably have to change the actual engine of the game, which is something *nobody* should really want to do, and if you don't change all the callstd/gostd/jumpstd 0xyy commands in the game to callstd/gostd/jumpstd 0xyyyy, the game is unplayable, as it will do crazy things to the commands after every callstd/gostd/jumpstd from then on.






(It's also not very realistic to have 257 standard function anyways, because then you would need 257 6-byte-or-more string of frequently-used pattern of commands to make everything economical. And judging by how many standard functions even GameFreak used for ALL the games, you will need one complicated/long storyline to utilize every standard function you make.

I'm not saying you shouldn't, but that's reality.)

Full Metal
December 7th, 2011, 02:27 PM
The absence of the on-slaught of n00bs asking questions bothers me.
This is a great tutorial, and one of the few decent ( and useful ) ones
that I have seen in a while. It covers something that isn't so ( forgive me, those of you who think Advance Map is hard to figure out and requires a tutorial ) simple, or obvious. If I was still hacking actively ( as opposed to passively ) I would definitely be using this. -- Thumbs Up --