lllllllllllllll, on 19 October 2022 - 03:42 PM, said:
When "enemy" gets blown up by an rpg, trying to check its extra will throw the same error won't it?
Assuming that when it dies via the RPG it immediately does a killit, then yes. So you'd need to handle this situation in the enemy code. The really easy solution is to have it instead play a "gonnaexplode" action and do the killit when that action plays, so it is destroyed on the next frame. This would allow the orbitsprites to check their PARENT's .extra, see that it's 0 or lower, and perform their logic.
The more complex solution is doing it from within the enemy sprite before it does the killit. Something like this:
for ACTORI sprofstat STAT_ACTOR
{
ife actorvar[ACTORI].PARENT THISACTOR
// some code to handle parent death
}
[ . . .]
killit
This loops through all sprites with the STAT_ACTOR statnum (which is faster than looping through allsprites), and if the sprite we found has its PARENT value set to ourselves, then we found one of our projectiles and you can set some flags or pass other data where it will switch logic on the next game tic. There's more you can do here, abusing .vm_sprite to step into the orbitsprites and run code as them directly, but that's kinda a really advanced method to explain logically and probably way overkill for this application.
As for the self damage, if they are still somehow managing to self damage then you should check the .htpicnum that gets through and manages to damage them. You could also check the picnum of .htowner and see what actor is damaging them, and nullify damage from that source. Or check the .htowner's .PARENT actorvar for the enemy sprite picnum. I don't know if that makes sense, here's some example:
geta[sprite[].htowner].picnum TEMP // picnum of .htowner
geta[actorvar[sprite[].htowner].PARENT].picnum TEMP //picnum of .htowner's PARENT
That second one is dangerous, you need to validate PARENT first. You should make sure .htowner is valid before running either of these too.