Refer here.
checkflag / setflag / clearflag do exactly what their names imply:
checkflag: is flag set (on/off)
setflag: sets the flag (on)
clearflag: un-sets the flag (off)
The script that Rayquaza uses should be obvious based of what is highlighted:
SkyPillar_Top_EventScript_239722:: @ 8239722
lockall
waitse
playmoncry SPECIES_RAYQUAZA, 2
delay 40
waitmoncry
setwildbattle SPECIES_RAYQUAZA, 70, ITEM_NONE
setflag FLAG_SYS_CTRL_OBJ_DELETE
special BattleSetup_StartLegendaryBattle
waitstate
clearflag FLAG_SYS_CTRL_OBJ_DELETE
specialvar VAR_RESULT, sub_8138B80
compare VAR_RESULT, 1
goto_eq SkyPillar_Top_EventScript_239768
compare VAR_RESULT, 4
goto_eq SkyPillar_Top_EventScript_239771
compare VAR_RESULT, 5
goto_eq SkyPillar_Top_EventScript_239771
setflag FLAG_0x1C0
releaseall
end
Flag 0x1C0 is set when you're done battling, hence preventing him from appearing further.
If you search the name of the script, you can see which entity uses it.:
https://github.com/pret/pokeemerald/blob/24f6484643ed3d7115fd4ebd92f254f224f1ca97/data/maps/SkyPillar_Top/events.inc#L3
SkyPillar_Top_EventObjects: @ 8537170
object_event 1, EVENT_OBJ_GFX_RAYQUAZA_2, 0, 14, 7, 3, MOVEMENT_TYPE_FACE_DOWN, 1, 1, 0, 0, 0x0, 773
object_event 2, EVENT_OBJ_GFX_RAYQUAZA_1, 0, 14, 6, 3, MOVEMENT_TYPE_FACE_DOWN, 1, 1, 0, 0, SkyPillar_Top_EventScript_239722, 80
If you look at the last parameter for the entity that uses the script (as already described here), it appears its spawn flag is 80d (0x050), this flag is used to hide the entity.
Again, like the linked thread, play with the event flags (0x50 & 0x1C0) until you get a result.