Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Yugiboy85

[Zdoom] Boss health [Resolved]

Recommended Posts

Hey, so, I have this script that I based off of kdizd's z1m8 (minus the healthbar) and for some reason, it just doesn't want to do the trick.

Basically, the idea is to have a cyberdemon get 10000 health (via setactorproperty) and, as different levels of his health decreases (getactorproperty), some stuff happens. It works fine in kdizd and I copied the script exactly like it was (I obviously changed it to adapt it to my test map) but when I test it in game, nothing happens the way I pictured it :/

Here is a copy of the script:

Script 2 (void)
{
	SetActorProperty(1,APROP_Health,10000);
	if(GetActorProperty(1,aprop_health)<9500)
	{
		print(s:"phase one complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_IMP,0,3);
		ACS_Execute(3,0);
	}
    if(GetActorProperty(1,aprop_health)<8500)
	{
		print(s:"phase two complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_DEMON,0,3);
		ACS_Execute(3,0);
	} 
	if(GetActorProperty(1,aprop_health)<7500)
	{
		print(s:"phase three complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_CACODEMON,0,3);
		ACS_Execute(3,0);
	} 
	if(GetActorProperty(1,aprop_health)<6500)
	{
		print(s:"phase four complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_HELLKNIGHT,0,3);
		ACS_Execute(3,0);
	}
	if(GetActorProperty(1,aprop_health)<5500)
	{
		print(s:"phase five complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_BARON,0,3);
		ACS_Execute(3,0);
	}
	if(GetActorProperty(1,aprop_health)<4500)
	{
		print(s:"phase six complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_REVENANT,0,3);
		ACS_Execute(3,0);
	}
	if(GetActorProperty(1,aprop_health)<3500)
	{
		print(s:"phase seven complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_ARACHNOTRON,0,3);
		ACS_Execute(3,0);
	}
	if(GetActorProperty(1,aprop_health)<2500)
	{
		print(s:"phase eight complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_MANCUBUS,0,3);
		ACS_Execute(3,0);
	}
	if(GetActorProperty(1,aprop_health)<1500)
	{
		print(s:"phase nine complete");
		SetActorProperty(1,aprop_dormant,1);
		floor_raisebyvalue(2,256,128);
		delay(105);
		thing_spawnfacing(2,T_VILE,0,4);
		ACS_Execute(4,0);
	}
	if(GetActorProperty(1,aprop_health)==0)
	{
		print(s:"phase ten complete");
		delay(105);
		terminate;
	}   
}
And, here is a copy of kdizd's script (uses a healthbar):
script 113 (void) //Magmantis health bar
{
	setfont("hlthbar1");
	if(getactorproperty(74,APROP_HEALTH)<11600)
	{
		setfont("hlthbar2");
	}
	if(getactorproperty(74,APROP_HEALTH)<11200)
	{
		setfont("hlthbar3");
	}
	if(getactorproperty(74,APROP_HEALTH)<10800)
	{
		setfont("hlthbar4");
	}
	if(getactorproperty(74,APROP_HEALTH)<10400)
	{
		setfont("hlthbar5");
	}
	if(getactorproperty(74,APROP_HEALTH)<10000)
	{
		setfont("hlthbar6");
	}
	if(getactorproperty(74,APROP_HEALTH)< 9600)
	{
		setfont("hlthbar7");
	}
	if(getactorproperty(74,APROP_HEALTH)< 9200)
	{
		setfont("hlthbar8");
	}
	if(getactorproperty(74,APROP_HEALTH)< 8800)
	{
		setfont("hlthbar9");
	}
	if(getactorproperty(74,APROP_HEALTH)< 8400)
	{
		setfont("hlthbr10");
	}
	if(getactorproperty(74,APROP_HEALTH)< 8000)
	{
		setfont("hlthbr11");
	}
	if(getactorproperty(74,APROP_HEALTH)<7600)
	{
		setfont("hlthbr12");
	}
	if(getactorproperty(74,APROP_HEALTH)<7200)
	{
		setfont("hlthbr13");
	}
	if(getactorproperty(74,APROP_HEALTH)<6800)
	{
		setfont("hlthbr14");
	}
	if(getactorproperty(74,APROP_HEALTH)<6400)
	{
		setfont("hlthbr15");
	}
	if(getactorproperty(74,APROP_HEALTH)<6000)
	{
		setfont("hlthbr16");
	}
	if(getactorproperty(74,APROP_HEALTH)<5600)
	{
		setfont("hlthbr17");
	}
	if(getactorproperty(74,APROP_HEALTH)<5200)
	{
		setfont("hlthbr18");
	}
	if(getactorproperty(74,APROP_HEALTH)<4800)
	{
		setfont("hlthbr19");
	}
	if(getactorproperty(74,APROP_HEALTH)<4400)
	{
		setfont("hlthbr20");
	}
	if(getactorproperty(74,APROP_HEALTH)<4000)
	{
		setfont("hlthbr21");
	}
	if(getactorproperty(74,APROP_HEALTH)<3600)
	{
		setfont("hlthbr22");
	}
	if(getactorproperty(74,APROP_HEALTH)<3200)
	{
		setfont("hlthbr23");
	}
	if(getactorproperty(74,APROP_HEALTH)<2800)
	{
		setfont("hlthbr24");
	}
	if(getactorproperty(74,APROP_HEALTH)<2400)
	{
		setfont("hlthbr25");
	}
	if(getactorproperty(74,APROP_HEALTH)<2000)
	{
		setfont("hlthbr26");
	}
	if(getactorproperty(74,APROP_HEALTH)<1600)
	{
		setfont("hlthbr27");
	}
	if(getactorproperty(74,APROP_HEALTH)<1200)
	{
		setfont("hlthbr28");
	}
	if(getactorproperty(74,APROP_HEALTH)<600)
	{
		setfont("hlthbr29");
	}
	if(getactorproperty(74,APROP_HEALTH)==0)
	{
		setfont("hlthbr30");
		hudmessage(s: "A"; HUDMSG_FADEOUT, 1, CR_UNTRANSLATED, 0.67, -0.1, 6, 5.0, 2);
		delay(35);
		terminate;		
	}
	hudmessage(s: "A"; 1, 1, CR_UNTRANSLATED, 0.67, -0.1, 6, 5.0);
	delay(1);
	restart;
}  
Hmm, I seem to have not put the restart at the end. Maybe it comes from here? If this is the case, than, I feel quite stupid xD

Anyways, here is the test wad (I would really like to get it to work since I want to implement something like that in my upcoming wad). Thank you in advance.

EDIT: Forgot to link the test wad, herpaderp...

http://www.mediafire.com/download/eb1orf5k06zsj9l/test.wad

Share this post


Link to post

Your script's logic was conceptually broken on multiple places, but I believe I understood what the intention was, so I modified it like this, and it worked for me after I recompiled the script:

Script 2 (void)
{
	SetActorProperty(1,APROP_Health,10000);
	while(GetActorProperty(1,aprop_health)>=9500) delay(1);
	print(s:"phase one complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_IMP,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=8500) delay(1);
	print(s:"phase two complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_DEMON,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=7500) delay(1);
	print(s:"phase three complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_CACODEMON,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=6500) delay(1);
	print(s:"phase four complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_HELLKNIGHT,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=5500) delay(1);
	print(s:"phase five complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_BARON,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=4500) delay(1);
	print(s:"phase six complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_REVENANT,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=3500) delay(1);
	print(s:"phase seven complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_ARACHNOTRON,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=2500) delay(1);
	print(s:"phase eight complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_MANCUBUS,0,3);
	ACS_Execute(3,0);
	while(GetActorProperty(1,aprop_health)>=1500) delay(1);
	print(s:"phase nine complete");
	SetActorProperty(1,aprop_dormant,1);
	floor_raisebyvalue(2,256,128);
	delay(105);
	thing_spawnfacing(2,T_VILE,0,4);
	ACS_Execute(4,0);
	while(GetActorProperty(1,aprop_health)>=0) delay(1);
	print(s:"phase ten complete");
	// delay(105);
	// Do some final action here, like exit the level or something
}
This code is much better readable in SLADE3's ACS editor, because each "while" command is highlighted as blue, which visually separates the individual blocks.

Share this post


Link to post

Ah, must've used an old script as the base then. I guess some stuff has evolved since kdizd. But even then, the base script (the kdizd one) still works which is weird. I'll check the modifications out fista, thx :)

EDIT: Well, that did the trick. Thank you scifista :)

Share this post


Link to post
The_Trigger said:

Ah, must've used an old script as the base then. I guess some stuff has evolved since kdizd. But even then, the base script (the kdizd one) still works which is weird.

It is not weird at all. Even though you might get an impression that your script was conceptually the same as the kdizd's one, there were important differences: Firstly, you intended each of the blocks to be performed only once, right after the boss's health drops below the respective value, but the KDIZD's script actually performs the actions inside all of the same blocks (until the first one where the condition is not true) again and again. Since the KDIZD's blocks merely change fonts, it didn't matter, but in your script, it would matter. That was also one of the reasons why you couldn't just keep restarting your script, too - the other reason is that you set the boss's health at the beginning of the script.

I modified your script to run linearly and halt at certain points until the current health-related condition is met - that was the simplest possible but effective solution to that problem.

Share this post


Link to post

Yes, the code written within curly brackets including the brackets themselves was what I was referring to as blocks. I also used the same word to refer to the sections of code in my modified script that corresponded to blocks in your original script, which might not be technically correct, but should be clear anyway.

Share this post


Link to post

Your original script didn't work because you forgot to copy a very important pair of instructions from your model:

	delay(1);
	restart;
if the script runs only only on one tic, it'll never keep monitoring the boss's health. You need the script to run again and again every tic, that's why there is a delay(1) instruction (wait next tic) and then restart.

This is also why the KDIZD script explicitly uses terminate, instead of letting the script reach its end normally.

Share this post


Link to post
Gez said:

Your original script didn't work because you forgot to copy a very important pair of instructions from your model: "delay(1); restart;"

AND for the other reasons I've explained, so that simply adding "delay(1); restart;" to the end of his original script wouldn't really help him. I'm saying this just to prevent possible misundestanding that it would.

Share this post


Link to post

The biggest issue with a restart would be that the SetActorProperty(1,APROP_Health,10000); command would be rerun every time, so the monster would be basically invulnerable. The second issue would be that the if should be else if, and listed in the opposite order (smallest first), so that they don't repeatedly run all the blocks that apply (the original KDIZD script has the same issue, but it's less of a problem in this case given all it does is select the picture for a HudMessage).

Share this post


Link to post
Gez said:

The second issue would be that the if should be else if, and listed in the opposite order (smallest first), so that they don't repeatedly run all the blocks that apply

Actually, that would also not suffice for a solution, because the first block where the "if" condition was met would still get executed repeatedly. Some kind of extra variable check would have to be added to every "if" statement.

But anyway, why run the script repeatedly through all the "if" commands everytime, when only one is needed per a phase? My solution is much more efficient in this regard.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×