Jump to content

Photo

Checking if an enemy is in it's invincibility frames?


  • Please log in to reply
4 replies to this topic

#1 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 04 January 2017 - 04:32 PM

Is there a way to check if an enemy is currently in it's invincibility frames? npc->CollDetection is true either way. Would be nice if its possible   :)


Edited by Avataro, 04 January 2017 - 04:36 PM.


#2 Jamian

Jamian

    ZC enthusiast

  • Members

Posted 04 January 2017 - 05:39 PM

If it's impossible, you could detect if the enemy was hurt, then use a counter. I'm guessing enemies are always invincible for the same amount of frames.



#3 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 04 January 2017 - 05:46 PM

As far as I know, you have to track NPC invulnerability manually. You have to check if it has taken damage in the last frame and then set up a counter to track invincibility frames.
 
const int NPC_MISC_CURHP = 0; //The NPC->Misc[] element the script logs to to update the NPC's current HP
const int NPC_MISC_INVINCIBILITY_TIMER = 1; //The NPC->Misc[] element that is logged to when an NPC takes damage
const int NPC_INVINCIBILITY_TIME = 32; //The number of frames an NPC remains iunvulnerable after being hit.

void UpdateNPCInvincibilityTime(){
	for(int a = 1; a <= Screen->NumNPCs(); a ++){ //Cycle through each NPC on the screen.
		npc nme = Screen->LoadNPC(a);
		if(nme->Misc[NPC_MISC_INVINCIBILITY_TIMER] > 0){ //Decrement the NPC invincibility counter until it hits 0 after being hit
			nme->Misc[NPC_MISC_INVINCIBILITY_TIMER] --;
		}
		if(nme->HP < nme->Misc[NPC_MISC_CURHP]){ //NPC has just been hurt, set up the counter
			nme->Misc[NPC_MISC_INVINCIBILITY_TIMER] = NPC_INVINCIBILITY_TIME;
		}
		nme->Misc[NPC_MISC_CURHP] = nme->HP; //Update the NPC's current HP reference
	}
}
This is how I handle checking for NPC invincibility frames. Call this in the global script and you can tell when NPCs have invulnerability frames, for the purposes of scripting. This does not work if the NPC was hit by a Power 0 weapon, as it normally stuns and does not give it invincibility frames.

Edited by Orithan, 04 January 2017 - 05:48 PM.


#4 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 04 January 2017 - 06:12 PM

I see. I guess that'll work for me. Thanks guys!



#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 05 January 2017 - 12:36 PM

I see. I guess that'll work for me. Thanks guys!

 

NPC invincibility is based on an internal class variable, hclk,  which is set to a value of 33​ after checking enemy defence flags with a result of being hit. This is reduced each frame by 1, and the enemy is invincible when this value is > 0.

 

If this sort of thing interests you, note that we added n->InvFrames to [2.future] 2.54 starting around Beta 44, and this seems to be something that will be retained in core ZC builds in the future. You might want to try it, and we could certainly use some testers using this stuff.

 

Other than that, I would use a value of 33, not 32, and I would perform a n->Defense[] check when setting any custom invincibility timer.

 

One thing that I will note, is that while this type of thing is fine for most quests:

if(nme->HP < nme->Misc[NPC_MISC_CURHP]){ //NPC has just been hurt, set up the counter

​If you have anything that changes npc hp, such as decreasing it, without actually being hit, or increasing it, that this might break. Poison/status effects for example, would set this, and you would not want those to give the npc temp invincibility.

 

​Checking weapons and npcs in a double-for loop, and checking defence settings versus weapon IDs, is certainly a wise idea when handling this type of event, and you would want to call that function after making those checks.

 

​If something gives the npc HP, that too can cause issues with the above function, as it could read that the npc was not damaged, even if it was. I've been down that road in the past.

 

​I'd also suggest using only one ->Misc[] index for both the timer, and the n->HP. In 2.50, you can easily run out of these using ghost.zh, or other headers.


Edited by ZoriaRPG, 05 January 2017 - 12:43 PM.

  • Avaro likes this


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users