https://github.com/pret/pokeruby/blob/d9e59a388c7c4b2464769963b3d58980ce742f70/data/maps/events/IslandCave.inc
IslandCave_MapObjects:: @ 838E674
object_event 1, MAP_OBJ_GFX_REGICE, 0, 8, 0, 7, 0, 3, 8, 0, 0, 0, 0, 0, 0, IslandCave_EventScript_15EF9D, 936, 0, 0
note the 'spawn' flag at the end
should work for most legendary encounters
SkyPillar_Top_MapObjects:: @ 838EE50
object_event 1, MAP_OBJ_GFX_RAYQUAZA, 0, 14, 0, 6, 0, 3, 8, 17, 0, 0, 0, 0, 0, SkyPillar_Top_EventScript_15F316, 773, 0, 0
^ rayquaza
====
https://github.com/pret/pokeruby/blob/9ba9993be18af162239838cfefe23f535e291ac0/data/scripts/maps/CaveOfOrigin_B4F.inc
https://github.com/pret/pokeruby/blob/d9e59a388c7c4b2464769963b3d58980ce742f70/data/maps/events/CaveOfOrigin_B4F.inc
CaveOfOrigin_B4F_MapObjects:: @ 838D880
object_event 1, 248, 0, 9, 0, 10, 0, 3, 8, 0, 0, 0, 0, 0, 0, 0x0, 825, 0, 0
Possible that flag 825 has something to do with the Kyogre/Groudon trigger spawn, can't see any other reference though.
CaveOfOrigin_B4F_MapCoordEvents:: @ 838D8A0
coord_event 9, 13, 3, 0, 0x409b, 0, 0, CaveOfOrigin_B4F_EventScript_15DDD7
15DDD7 is the map calling the Kyogre/Groudon event, looks like 0x409b (event constant) should be set to 0 to reset the event?
https://github.com/pret/pokeruby/blob/9ba9993be18af162239838cfefe23f535e291ac0/data/scripts/maps/CaveOfOrigin_B4F.inc#L75
Edit: can confirm that setting the above constant to 0 allows you to rebattle (sprite doesn't show, but triggers the event when you stand in front of it)