Skip to content

Set Up Item Balls on a Map Without Needing New Scripts

Josh edited this page Oct 2, 2022 · 3 revisions

Credits to Deokishisu for implementing this feature into CrystalDust.

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 and add the following function anywhere in that file:

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, we are going to need the following script:

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

So here, we have Sight Radius/Berry Tree ID set to ITEM_POTION and the Common_EventScript_FindItem script will set it to VAR_RESULT and give it to the finditem command which results in the 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 however, it will not work.

At this point though, 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.

Clone this wiki locally