The PokéCommunity Forums

The PokéCommunity Forums (https://www.pokecommunity.com/index.php)
-   Binary ROM Hacking (https://www.pokecommunity.com/forumdisplay.php?f=284)
-   -   Script [Emerald] Items as HMs: Checkitem doesn't seem to work (https://www.pokecommunity.com/showthread.php?t=419567)

McPaul March 29th, 2019 8:11 AM

[Emerald] Items as HMs: Checkitem doesn't seem to work
 
Here is the first script I made:

'---------------
#org 0xE3CFBC
lockall
checkflag 0x867
if 0x0 goto 0x8290721
checkitem 0x167 0x1
compare LASTRESULT 0x6
if 0x1 goto 0x8290721
setanimation 0x0 LASTRESULT
bufferitem 0x0 0x167
checkitem 0x167 0x1
msgbox 0x829072E MSG_YESNO '"This tree looks like it can be\ncu..."
compare LASTRESULT 0x0
if 0x1 goto 0x829072B
msgbox 0x8290771 MSG_KEEPOPEN '"[player] used [buffer1]!"
closeonkeypress
doanimation 0x2
waitstate
goto 0x8290710

'---------------
#org 0x290721
msgbox 0x829077D MSG_KEEPOPEN '"This tree looks like it can be\ncu..."
releaseall
end

'---------------
#org 0x29072B
closeonkeypress
releaseall
end

'---------------
#org 0x290710
applymovement LASTTALKED 0x829071F
waitmovement 0x0
hidesprite LASTTALKED
releaseall
end


'---------
' Strings
'---------
#org 0x29072E
= This tree looks like it can be\ncut down!\pWould you like to use [buffer1]?

#org 0x290771
= [player] used [buffer1]!

#org 0x29077D
= This tree looks like it can be\ncut down!


'-----------
' Movements
'-----------
#org 0x29071F
#raw 0x5B 'mov5B
#raw 0xFE 'End of Movements


The problem is that I can cut trees even if I don't have the item 0x167 in my bag despite using the checkitem command. Why is this happening? Did I do wrong somewhere?

Thanks for your answers.

DrFuji March 30th, 2019 2:52 AM

Here's a version of your script that will work:

Spoiler:
#dynamic 0x9C0B20

#org @start
lockall
checkflag 0x867
if 0x0 goto @CantCut
checkitem 0x167 0x1
compare 0x800D 0x1
if 0x0 goto @CantCut
setanimation 0x0 0x800D
bufferitem 0x0 0x167
checkitem 0x167 0x1
msgbox @CanBeCut 0x5
compare 0x800D 0x0
if 0x1 goto @DontCut
msgbox @UseCut 0x6
closeonkeypress
doanimation 0x2
waitstate
goto @Continue

#org @CantCut
msgbox @CutDown 0x6
releaseall
end

#org @DontCut
closeonkeypress
releaseall
end

#org @Continue
applymovement 0x800F @Cut
waitmovement 0x0
hidesprite 0x800F
releaseall
end

#org @CanBeCut
= This tree looks like it can be\ncut down!\pWould you like to use [buffer1]?

#org @UseCut
= [player] used [buffer1]!

#org @CutDown
= This tree looks like it can be\ncut down!

#org @Cut
#raw 0x5B
#raw 0xFE


Your issue stemmed these three lines in your original script:
Quote:

checkitem 0x167 0x1
compare LASTRESULT 0x6
if 0x1 goto 0x8290721
The checkitem command works by comparing the number of a specified item that you have to a chosen value (in this case, 0x1). If you have that many of the item or more, 0x800D is set to 0x1, if you have less, its set to 0x0. The compare line is then completely wrong, as 0x800D will never have 0x6 as a value from the previous command. This run on also breaks the if command as it will always be false, allowing the script to continue regardless as to whether you have the item or not.

Whenever you're making a script, I'd highly suggest that you use dynamic pointers. It ensures that you don't overwrite anything in the ROM by accident and if you're trying to get help here, its easier for others to follow the script's structure.

McPaul March 30th, 2019 3:18 AM

Thanks a lor DrFuji! I understood what you meant and can now proceed further!

The script I wrote had originally a dynamic offset command, but when I compiled the line disappeard, replaced by the offset the script went to and I just copypasted it.


All times are GMT -8. The time now is 9:13 AM.


Like our Facebook Page Follow us on Twitter © 2002 - 2018 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2016 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.

Acknowledgements
Use of PokéCommunity Assets
vB Optimise by DragonByte Technologies Ltd © 2023.