I need a enemy HP bar script (ACS) for enemies with multiple TIDS

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
Fat_Angus
Posts: 75
Joined: Mon Jun 12, 2017 5:52 pm

I need a enemy HP bar script (ACS) for enemies with multiple TIDS

Post by Fat_Angus »

I am trying to implement an RPG style HP bar for enemies, and I have a bit of ACS code that works well assuming all enemies have the same TID, but fails when pointed at enemies with different TIDs:

Code: Select all

script 395 ENTER
{
	
	while (!hpdie){
	
	int hppick = UniqueTID;
	if (PickActor(0,GetActorAngle(0),GetActorPitch(0),768.00,hppick )){
		SetFont("BIGFONT");
		HudMessage(s:GetActorClass(hppick), s: "\n", d:GetActorProperty(hppick,APROP_Health), s:"/", d:GetActorProperty(hppick, APROP_SpawnHealth); HUDMSG_PLAIN,1,CR_GRAY,1.5,0.2,1873,3192,256);
			}
		Thing_ChangeTID(hppick,0);
		delay (1);
		}
	delay(1);
	
}
I have tried a number of suggestions by others, but they don't work. Does anybody know how to get this code to read multiple TIDS? My ACS knowledge is very rusty and I am pressed for time at the moment. Thanks very much :).
Fat_Angus
Posts: 75
Joined: Mon Jun 12, 2017 5:52 pm

Re: I need a enemy HP bar script (ACS) for enemies with multiple TIDS

Post by Fat_Angus »

Came up with something that works, here it is as a reference for others.

Code: Select all

// SCRIPT FOR DISPLAYING HP STATS FOR HIGHLIGHTED ENEMIES
		
script 395 ENTER
{
	while (!hpdie){
	int old_id = (PickActor(0,GetActorAngle(0),GetActorPitch(0),768.00,0,MF_SHOOTABLE,0,PICKAF_RETURNTID));
	int new_id = UniqueTID();
	if (PickActor(0,GetActorAngle(0),GetActorPitch(0),768.00,new_id,MF_SHOOTABLE,0,PICKAF_FORCETID)){
		SetFont("BIGFONT");
		HudMessage(s:GetActorClass(new_id), s: "\n", d:GetActorProperty(new_id,APROP_Health), s:"/", d:GetActorProperty(new_id, APROP_SpawnHealth); HUDMSG_PLAIN,1,CR_GRAY,1.5,0.2,1873,3192,256);
			}
		Thing_ChangeTID(new_id,old_id);
		delay (1);
		}
	delay(1);
	
}
Post Reply

Return to “Scripting”