Created Set Up Item Balls on a Map Without Needing New Scripts (markdown)

Josh 2022-10-02 04:39:58 +01:00
parent ffbfe7af86
commit cdc6bbd7a9
1 changed files with 37 additions and 0 deletions

@ -0,0 +1,37 @@
## Set Up Item Balls on a Map Without Needing New Scripts
Credits to Deokishisu for implementing this feature into [CrystalDust](https://github.com/Deokishisu/CrystalDust/commit/51f995fd7821f7bd8a85272d519a34dd2604cecf).
When making a hack, it's natural to want to litter various item balls containing items throughout the world. Doing this involves making a script for the item and then assigning that script to the item ball object and setting the respective flag id for when the player picks up the item.
But what if we could unify the item logic for item balls so all they'd need is the one script? That's what this tutorial will help with getting set up.
First, we need to go into [src/script.c](https://github.com/pret/pokeemerald/blob/master/src/script.c) and add the following function anywhere in that file:
```c
void GetObjectEventTrainerRangeFromTemplate(void)
{
gSpecialVar_Result = gMapHeader.events->objectEvents[gSpecialVar_LastTalked - 1].trainerRange_berryTreeId;
}
```
This will set the value of the object's `trainerRange_berryTreeId` (`Sight Radius/Berry Tree ID` in porymap) to `VAR_RESULT.`
Next, we need to make a script making use of this function. In [data/scripts/item_balls_scripts.inc](https://github.com/pret/pokeemerald/blob/master/data/scripts/item_ball_scripts.inc), we are going to need the following script:
```asm
Common_EventScript_FindItem::
callnative GetObjectEventTrainerRangeFromTemplate
finditem VAR_RESULT
end
```
This will be the script all item balls will use when using this feature. Essentially, it gets the value of `VAR_RESULT` and uses it for the parameter of `finditem`.
With that out of the way, we can now do this with item ball objects:
![image](https://user-images.githubusercontent.com/32826900/193436571-53346610-1e82-417a-bc73-1f529e9e0353.png)
So here, we have `Sight Radius/Berry Tree ID` set to `ITEM_POTION` and the `Common_EventScript_FindItem` script set to the object will set `VAR_RESULT` to `ITEN_POTION` and give that value to the `finditem` command which results in that item being obtained when the player interacts with the ball.
NOTE: As long as the script set for the item ball object is set to `Common_EventScript_FindItem`, you can use the `Sight Radius/Berry Tree ID` field in porymap to get the item ID you're wanting. If the script is NOT set, it will not work.
At this point however, we're done. You can either change pre-existing item balls to use this method and then give yourself a bit of extra space by removing the old item ball scripts or just have any item ball going forward use this new method, it's entirely up to you.
TODO: Possibly look into using any of the Movement Radius fields in porymap to get the quantity of the respective item.