• Our software update is now concluded. You will need to reset your password to log in.
  • Please note that the site will be down briefly around 10AM EST, 23 February, for planned maintenance.
  • Welcome to PokéCommunity! Register now and join one of the best places on the 'net to talk Pokémon and more! Community members will not see the bottom screen advertisements.
  • Want to share your adventures playing Pokémon?
    Check out our new Travel Journals forum for sharing playthroughs of ROM Hacks, Fan Games, and other Pokémon content!
  • IMPORTANT: Following a takedown request, the following hacks have been delisted from PokéCommunity:

    • Pokémon Glazed
    • Pokémon: Giratina Strikes Back
    • Pokémon Flora Sky
    • Pokémon Stranded
    The downloads and discussion threads for these hacks will no longer be accessible, and staff will be unable to return questions regarding accessing this content.

[Other] Reusable Pokeballs

6
Posts
113
Days
  • Age 28
  • Seen Nov 6, 2023
Hey,

I'm trying to make an emerald version that is more "life-like" with day/night cycles dialog options, etc. because some things just always bothered me about the world building as a kid.
As a basis I'm using the pokemon-expansion by rh-hideout (V 1.6.2)

One of the things I want to incorporate is reusable Pokeballs. If a Pokemon frees itself I want the number of Pokeballs to stay the same. If I'm using e.g. a hyper ball and the Pokemon frees itself 3x before being caught, I don't want to use 4 balls but just 1.

I found the function that removes the Pokeball in src/item_use.c

Spoiler:

, the script for catching a Pokemon in data/battle_scripts_2.s

Spoiler:

, and the script for Pokemon that free themselves also in data/battle_scripts_2.s

Spoiler:

my idea is to pass gSpecialVar_ItemId to the Escape script so that I can return the kind of Pokeball I used and not some other kind.

I guess it would look something like this:

Spoiler:

However, I have no idea how to do that. After hours of searching, I couldn't find anyone who even tried to do it. So if anyone could help me, that would be really cool.

This is my first post, so If I missed any guidelines, please tell me. I don't wanna be the guy who makes it harder for future people to find stuff
 
421
Posts
6
Years
  • Age 37
  • Seen today
Hey,

I'm trying to make an emerald version that is more "life-like" with day/night cycles dialog options, etc. because some things just always bothered me about the world building as a kid.
As a basis I'm using the pokemon-expansion by rh-hideout (V 1.6.2)

One of the things I want to incorporate is reusable Pokeballs. If a Pokemon frees itself I want the number of Pokeballs to stay the same. If I'm using e.g. a hyper ball and the Pokemon frees itself 3x before being caught, I don't want to use 4 balls but just 1.
...

The battle scripting system doesn't have a "giveitem" command. You could create one, but an easier solution is to implement your change with C code. For example you could add your code at the location where BattleScript_ShakeBallThrow is called from:
Code:
diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c
index 32f61423a..ea4612194 100644
[COLOR="Red"]--- a/src/battle_script_commands.c[/COLOR]
[COLOR="Lime"]+++ b/src/battle_script_commands.c[/COLOR]
@@ -15168,6 +15168,8 @@ static void Cmd_handleballthrow(void)
                     gBattleCommunication[MULTISTRING_CHOOSER] = shakes;
 
                 gBattlescriptCurrInstr = BattleScript_ShakeBallThrow;
[COLOR="Lime"]+               if(gLastUsedItem != ITEM_SAFARI_BALL)
+                       AddBagItem(gLastUsedItem, 1);[/COLOR]
             }
         }
     }
 
6
Posts
113
Days
  • Age 28
  • Seen Nov 6, 2023
This works exactly as I wanted it to. If I exclude the if-statement, it works on all Pokeballs, since the balls are the only items, that can trigger BattleScript_ShakeBallThrow.

The final code for reusable Pokeballs looks like this:

Code:
            else // not caught
            {
                if (!gHasFetchedBall)
                    gLastUsedBall = gLastUsedItem;

                if (IsCriticalCapture())
                    gBattleCommunication[MULTISTRING_CHOOSER] = BALL_3_SHAKES_FAIL;
                else
                    gBattleCommunication[MULTISTRING_CHOOSER] = shakes;

                gBattlescriptCurrInstr = BattleScript_ShakeBallThrow;
                [COLOR="Lime"]AddBagItem(gLastUsedItem, 1);[/COLOR]
            }

It just needs this one change in 1 line in src_battle_script_commands.c

Thank you.
 
421
Posts
6
Years
  • Age 37
  • Seen today
This works exactly as I wanted it to. If I exclude the if-statement, it works on all Pokeballs, since the balls are the only items, that can trigger BattleScript_ShakeBallThrow.

The final code for reusable Pokeballs looks like this:

Code:
            else // not caught
            {
                if (!gHasFetchedBall)
                    gLastUsedBall = gLastUsedItem;

                if (IsCriticalCapture())
                    gBattleCommunication[MULTISTRING_CHOOSER] = BALL_3_SHAKES_FAIL;
                else
                    gBattleCommunication[MULTISTRING_CHOOSER] = shakes;

                gBattlescriptCurrInstr = BattleScript_ShakeBallThrow;
                [COLOR="Lime"]AddBagItem(gLastUsedItem, 1);[/COLOR]
            }

It just needs this one change in 1 line in src_battle_script_commands.c

Thank you.

I added the if statement to prevent the code from running in the Safari zone.
Safari balls aren't actually in your bag, so the code wouldn't let you reuse balls in the safari zone either way, instead it would add the "reused" safari balls to your bag allowing you to keep them outside the Safari zone.

However, if you wanted the player to have safari balls outside the Safari zone and be able to reuse them, this would've been a better check to use:
Code:
if(!(gBattleTypeFlags & BATTLE_TYPE_SAFARI))
 
Back
Top