diff --git a/asm/macros/event.inc b/asm/macros/event.inc index f3fa3a4027..b2a2d46159 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2347,21 +2347,21 @@ @ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will takje the object's template position. .macro getobjectxy localId:req, posType:req - setvar VAR_0x8000, \localId - setvar VAR_0x8001, \posType - special GetObjectPosition + callnative GetObjectPosition + .2byte \localId + .2byte \posType .endm - .macro getobjecttemplatexy localId:req - setvar VAR_0x8000, \localId - setvar VAR_0x8001, TEMPLATE_POSITION - special GetObjectPosition + .macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION + callnative GetObjectPosition + .2byte \localId + .2byte \posType .endm - .macro getobjectcurrentxy localId:req - setvar VAR_0x8000, \localId - setvar VAR_0x8001, CURRENT_POSITION - special GetObjectPosition + .macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION + callnative GetObjectPosition + .2byte \localId + .2byte \posType .endm @ checks if there is any object at a given position diff --git a/data/specials.inc b/data/specials.inc index 54a5218c37..3232dca7af 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -554,7 +554,6 @@ gSpecials:: def_special Script_GetChosenMonDefensiveEVs def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs - def_special GetObjectPosition def_special CheckObjectAtXY def_special Script_GetSetPokedexFlag def_special CheckPartyHasSpecie diff --git a/src/field_specials.c b/src/field_specials.c index d26f9219cf..3c27ade570 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,30 +4278,6 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -void GetObjectPosition(void) -{ - u32 localId = gSpecialVar_0x8000; - u32 useTemplate = gSpecialVar_0x8001; - u32 objectId; - struct ObjectEvent* objEvent; - - u16 *x = &gSpecialVar_0x8007; - u16 *y = &gSpecialVar_0x8008; - - if (useTemplate) - { - const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); - *x = objTemplate->x; - *y = objTemplate->y; - return; - } - - objectId = GetObjectEventIdByLocalId(localId); - objEvent = &gObjectEvents[objectId]; - *x = objEvent->currentCoords.x - 7; - *y = objEvent->currentCoords.y - 7; -} - bool32 CheckObjectAtXY(void) { u32 x = gSpecialVar_0x8005 + 7; diff --git a/src/scrcmd.c b/src/scrcmd.c index 7062721a94..7bcedb89bb 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2481,3 +2481,28 @@ void RemoveAllItem(struct ScriptContext *ctx) gSpecialVar_Result = count; RemoveBagItem(itemId, count); } + +void GetObjectPosition(struct ScriptContext *ctx) +{ + u32 localId = VarGet(ScriptReadHalfword(ctx)); + u32 useTemplate = gSpecialVar_0x8001; + u32 objectId; + struct ObjectEvent* objEvent; + + u16 *x = &gSpecialVar_0x8007; + u16 *y = &gSpecialVar_0x8008; + + if (useTemplate) + { + const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); + *x = objTemplate->x; + *y = objTemplate->y; + return; + } + + objectId = GetObjectEventIdByLocalId(localId); + objEvent = &gObjectEvents[objectId]; + *x = objEvent->currentCoords.x - 7; + *y = objEvent->currentCoords.y - 7; +} +