Detecting when an enemy bomb explodes
#1
Posted 01 February 2017 - 03:25 PM
#2
Posted 01 February 2017 - 04:01 PM
Check for enemy explosion weapons?
#3
Posted 01 February 2017 - 04:03 PM
//One viable way... int isExplosion() int q; eweapon e; for ( q = Screen->NumEWeapons(); q > 0; q++ ) { e = Screen->LoadEWeapon(q); if ( e->ID == EW_BOMBBLAST ) return q; return -1; } } //This is a better approach bool isExplosion(eweapon e){ if ( e->ID == EW_BOMBBLAST ) return true; return false; } . //Then call in a for loop: for ( int q = Screen->NumEWeapons(); q > 0; q-- ) { eweapon e = Screen->LoadEWeapon(q); if ( isExplosion(e) { //do what you want here } } //Or, try to get the pointer of an enemy explosion eweapon isExplosion(){ for ( int q = Screen->NumEWeapons; q > 0; q-- ) { eweapon e = Screen->LoadEWeapon(q); if ( e->ID == EW_BOMBBLAST ) return e; } } // I do not like this method, as it is prone to errors if you are not careful
Edited by ZoriaRPG, 01 February 2017 - 04:04 PM.
- Mitchfork likes this
#4
Posted 01 February 2017 - 06:33 PM
I want to have a script that executes code when an enemy bomb explodes and would know the coordinates of the enemy bomb on-screen. Is there any way to check for this?
I *believe* the bomb eweapon will die, then the explosion eweapon would be created. Assuming you haven't gotten rid of the eweapon some other way or left the screen I would say it's safe to say if the bomb eweapon goes invalid(or some sort of deadstate), then the explosion will start happening.
Edited by SUCCESSOR, 01 February 2017 - 06:34 PM.
#5
Posted 02 February 2017 - 01:40 AM
Thanks everyone, did not think of cycling through the EWeapon indices like that.
#6
Posted 02 February 2017 - 03:40 PM
I've tried the following:
int bombDeadState(eweapon e){ if (e->ID == EW_BOMB) return e->DeadState; return -1; } void bomby() { for (int q = Screen->NumEWeapons(); q>0; q--) { eweapon e = Screen->LoadEWeapon(q); if(bombDeadState(e) == 0) { //insert the explosion drawing script here } } }
It compiles, but it doesn't seem to work. Is checking the DeadState a valid way to get this behavior working?
#7
Posted 02 February 2017 - 06:39 PM
It compiles, but it doesn't seem to work. Is checking the DeadState a valid way to get this behavior working?
I couldn't say. Possibly not. It may not change the deadstate at all. Try checking if EW_BOMB stops being valid and if that works for your needs.
Instead of running a script WHILE an explosion is on screen, set a bool value such as hasExploded to trigger what you are trying to do, so it only happens once.
Edited by SUCCESSOR, 02 February 2017 - 06:47 PM.
#8
Posted 02 February 2017 - 07:20 PM
How do you suggest checking that it's valid? I thought that was what DeadState was supposed to indicate?
#9
Posted 02 February 2017 - 07:38 PM
Sorry for the vague help. I've been at school and still am.
eweapon->isValid()
Edited by SUCCESSOR, 02 February 2017 - 09:31 PM.
#10
Posted 02 February 2017 - 10:34 PM
Okay rereading this my advice was terrible and didn't really offer a solution to you problem. I thought you were already keeping track of a bomb and therefor checking if it disappeared would have been an easy solution. If you are keeping track of multiple bombs is a different task indeed.
You need a way to make sure the same explosion isn't being recognized twice. I think the simplest way in ZS is to set a Misc[] value and check for that before counting explosions.
Edited by SUCCESSOR, 02 February 2017 - 10:38 PM.
#11
Posted 03 February 2017 - 12:50 AM
So there was some testing and I realized that this approach would not work because I want the script to only execute once when the bomb explosion happens. Cycling through and checking for bomb explosions activates every frame the explosion is active.
I've tried the following:int bombDeadState(eweapon e){ if (e->ID == EW_BOMB) return e->DeadState; return -1; } void bomby() { for (int q = Screen->NumEWeapons(); q>0; q--) { eweapon e = Screen->LoadEWeapon(q); if(bombDeadState(e) == 0) { //insert the explosion drawing script here } } }It compiles, but it doesn't seem to work. Is checking the DeadState a valid way to get this behavior working?
Don't use the DeadState at all.
Do this, in the code that you want to perform exactly one time:
if e->Misc[15] == 0 ) { e->Misc[15] = 1; //do things } //Example void bomby() { for (int q = Screen->NumEWeapons(); q>0; q--) { eweapon e = Screen->LoadEWeapon(q); if(e->ID == EW_BOMBBLAST ){ //ZScript does not short circuit, hence the nested statements... if ( e->Misc[15] == 0) { e->Misc[15] = 1; //insert the explosion drawing script here } } } }That will flag the weapon not to do that thing, a second time.
Edited by ZoriaRPG, 03 February 2017 - 12:53 AM.
#12
Posted 03 February 2017 - 01:06 AM
Ah, thanks guys, I forgot I could store arbitrary data with most ZScript classes. It's been a while since I've touched ZScript.
Through testing, I have also found out that when an enemy bomb explodes in ZC, the bomb explosion has the same eweapon pointer as the bomb that created it. I was using this to build a much less elegant solution to this. Didn't end up being useful, but maybe it's good info for anybody doing stuff with bombs later. It means isValid() doesn't work but you could compare when the ID changes.
#13
Posted 03 February 2017 - 05:36 AM
Ah, thanks guys, I forgot I could store arbitrary data with most ZScript classes. It's been a while since I've touched ZScript.
Through testing, I have also found out that when an enemy bomb explodes in ZC, the bomb explosion has the same eweapon pointer as the bomb that created it. I was using this to build a much less elegant solution to this. Didn't end up being useful, but maybe it's good info for anybody doing stuff with bombs later. It means isValid() doesn't work but you could compare when the ID changes.
Did the code that I posted, which did in fact, specifically do ID matching, not work for your application?
eLitBomb does indeed, change to eBoom internally. It is subtly replaced when the LitBomb timer reaches 0. This means that its screen index does not change, although there are other ways to flag, or otherwise determine if a change occurs.
Edited by ZoriaRPG, 03 February 2017 - 05:38 AM.
#14
Posted 03 February 2017 - 09:53 AM
#15
Posted 03 February 2017 - 04:59 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users