diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 985ced862f..710514cda1 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2345,23 +2345,29 @@ .2byte \itemId .endm - @ 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 take the object's template position. - .macro getobjectxy localId:req, posType:req + @ Stores the position of the given object in destX and destY. Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will take the object's template position. + .macro getobjectxy localId:req, posType:req, destX:req, destY:req callnative ScrCmd_getobjectxy .2byte \localId .2byte \posType + .2byte \destX + .2byte \destY .endm - .macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION + .macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION, destX:req, destY:req callnative ScrCmd_getobjectxy .2byte \localId .2byte \posType + .2byte \destX + .2byte \destY .endm - .macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION + .macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION, destX:req, destY:req callnative ScrCmd_getobjectxy .2byte \localId .2byte \posType + .2byte \destX + .2byte \destY .endm @ Return TRUE to dest if there is an object at the position x and y. diff --git a/include/field_specials.h b/include/field_specials.h index 85db5ba40f..f391a46ba5 100644 --- a/include/field_specials.h +++ b/include/field_specials.h @@ -33,7 +33,7 @@ void ResetFanClub(void); bool8 ShouldShowBoxWasFullMessage(void); void SetPCBoxToSendMon(u8 boxId); void PreparePartyForSkyBattle(void); -void GetObjectPosition(u32, u32); +void GetObjectPosition(u16*, u16*, u32, u32); bool32 CheckObjectAtXY(u32, u32); bool32 CheckPartyHasSpecie(u32); diff --git a/src/field_specials.c b/src/field_specials.c index 94a98812b1..8b2ac8de8d 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,26 +4278,23 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -void GetObjectPosition(u32 localId, u32 useTemplate) +void GetObjectPosition(u16* xPointer, u16* yPointer, u32 localId, u32 useTemplate) { 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; + *xPointer = objTemplate->x; + *yPointer = objTemplate->y; return; } objectId = GetObjectEventIdByLocalId(localId); objEvent = &gObjectEvents[objectId]; - *x = objEvent->currentCoords.x - 7; - *y = objEvent->currentCoords.y - 7; + *xPointer = objEvent->currentCoords.x - 7; + *yPointer = objEvent->currentCoords.y - 7; } bool32 CheckObjectAtXY(u32 x, u32 y) diff --git a/src/scrcmd.c b/src/scrcmd.c index be5c3c9346..542f3d1dfc 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2489,8 +2489,9 @@ bool8 ScrCmd_getobjectxy(struct ScriptContext *ctx) { u32 localId = VarGet(ScriptReadHalfword(ctx)); u32 useTemplate = VarGet(ScriptReadHalfword(ctx)); - - GetObjectPosition(localId,useTemplate); + u16 *pX = GetVarPointer(ScriptReadHalfword(ctx)); + u16 *pY = GetVarPointer(ScriptReadHalfword(ctx)); + GetObjectPosition(pX,pY,localId,useTemplate); return FALSE; }