Drains Health over time and killself

  • Thread starter Thread starter Goliath
  • Start date Start date
G

Goliath

Guest
Here is a script i want to share:

Code:
void drainHP (int quantity){
	// Drains Health over time and killself
	void self = getlocalvar("self");
	void true = getentityproperty(self, "exists");
    int  Health = getentityproperty(self, "health");
	
	if(true!=NULL()){
		changeentityproperty(self, "health", Health-quantity);
		if (Health <= 0){
			changeentityproperty(self, "animation", openborconstant("ANI_DEATH"));
		}
	}
}

It drains entity HP over time and kills it when HP = 0.
Usefull for delays and signals, like warning signal.

How to use it:

Declare command on anim like this:
@cmd drainHP 5

An example of use:

Code:
#----------WARNING SIGN
name	Warning
type	none
health	5
facing	1
nolife	1
nopain	1
falldie	1
nomove	1 1
antigravity     100
animationscript	data/scripts/oscript.c

anim idle
	loop	1
	delay   30
	offset	24 36
		frame   data/sprites/ws.png
	[color=orange]@cmd	drainHP 5[/color]
		frame   data/chars/misc/empty.png
		
anim	death
	delay   1
	offset	1 1
	@cmd killentity getlocalvar("self")
		frame   data/chars/misc/empty.png

You can control the time on level spawn, like this:

Code:
spawn	Warning
Health	50
coords	250 223 133
at		0
 
How lifespan works?
I mean what are the measures, seconds, centiseconds?
 
Ooops! You are right, too many thinks on the head, sorry for asking :'(.
 
but...if this is an animationscript, this function will run only one time, its not persistent.

But if you use it as a script (or even as SCRIPT in character header), it will be persistent

@script
void self = getlocalvar("self");
int  Health = getentityproperty(self, "health");
if(frame==1){
changeentityproperty(self, "health", Health-5);
if (Health <= 0){
killentity(self);
}
}
@end_script
 
plus, there is a problem in your code:

if (Health <= 0){
killentity(self);
}

This won't make the entity to die (playing fall/death anim), but will remove the entity instantily. And this part is even not needed, because the engine kills entities with life == 0
 
O Ilusionista said:
but...if this is an animationscript, this function will run only one time, its not persistent.

But, declaring it il all animation´s frames don´t should do the same?

O Ilusionista said:
plus, there is a problem in your code:

I had changed that line to ANI_DEATH, so entity plays its death anim.
 
But, declaring it il all animation´s frames don´t should do the same?

No. If you call it in a animationscript function, the code will be parsed ONLY on that script (unless you are changing some openborvariants).

If you call it in frame 3, for example, is the same of doing this:

if (frame==3)

The code bellow, done by BB, will be run only on the frame 1, but what makes it persistent is the loop:

@script
  void self = getlocalvar("self");
  int  Health = getentityproperty(self, "health");
  if(frame==1){
  changeentityproperty(self, "health", Health-5);
  if (Health <= 0){
  killentity(self);
  }
  }
  @end_script

Put that code in a looped animtion and you will see it working.
 
Back
Top Bottom