Page 1 of 1

[ACS] Script to see allied health?

Posted: Sun Dec 31, 2017 11:28 pm
by FranckyFox2468
I figured this was already done but i am not exactly sure where to look at and i figured you guys would be the best place to ask.

Is there, perhaps or perhaps not as part of an established mod maybe, a script that allows to see an allied (or same team) player or monster's health (or perhaps someone with a specific inventory/specie) when aiming at them? But does not apply to enemies?

Cause i figured that if i make a mod with a support character/class, it would be kinda awkward to not be able to tell if someone actually needs healing or not. Because even with a function to ask for healing, some might just spam it regardless of if they actually need it or not.

[ACS] Re: Script to see allied health?

Posted: Sun Dec 31, 2017 11:50 pm
by Fabysk
Not sure how to display the health on screen when facing an ally or monster. Not sure if that's possible from my knowledge.

Code: Select all

script 1 ENTER
{
	int health = GetActorProperty(1, APROP_HEALTH);
	While(TRUE)
	{
		HudMessage(d:health;
		HUDMSG_PLAIN, 1, CR_GREEN, 3.0, 0.30, 5.0);
		Delay(1);
	}
}
You can also look here for an alternative of what you're looking for.
https://zdoom.org/wiki/Hudmessageonactor

[ACS] Re: Script to see allied health?

Posted: Mon Jan 01, 2018 12:31 am
by Kaminsky
Here's a simple script that allows players to check the current health of whatever actor they're looking at:

Code: Select all

Script "CheckTargetHealth" Enter
{
	int player = PlayerNumber();
	
	int health;
	int maxHealth;
	
	// Keep looping while the player is alive.
	while(GetActorProperty(0, APROP_HEALTH) > 0)
	{
		// Check if the player has a target (the actor in their line of sight).
		if(SetActivatorToTarget(0))
		{
			// Now the player's target is the activator of this script.
			// Check if the target has an item in their inventory (called "ConditionItem" in this case) that allows the player to see their health.
			if(CheckInventory("ConditionItem"))
			{
				health = GetActorProperty(0, APROP_HEALTH);
				maxHealth = GetActorProperty(0, APROP_SPAWNHEALTH);
				
				// Set the activator of the script back to the player.
				SetActivatorToPlayer(player);
				
				// Preview the health of the target in the middle of the player's screen for approximately one tic (1/35 of a second).
				HudMessage(s:"Target Health: ", d:health, s:"/", d:maxHealth; HUDMSG_PLAIN, 0, CR_RED, 0.5, 0.5, 0.03);
			}
			
			// Set the activator to the player if it hasn't been done already.
			SetActivatorToPlayer(player);
		}
	}
	
	Delay(1);
}
The example above will work only when the player joins the game, so you may have to change the script type to whatever's best for you. This script should be able to work as a clientsided script too, if the amount of network traffic is a concern, as long as you include "Clientside" at the end of the script definition.

[ACS] Re: Script to see allied health?

Posted: Mon Jan 01, 2018 2:56 am
by FranckyFox2468
Thanks guys, ill be sure to check these when i get around them :D

[ACS] Re: Script to see allied health?

Posted: Sat Sep 08, 2018 6:42 pm
by FranckyFox2468
Kaminsky wrote:
Mon Jan 01, 2018 12:31 am
Here's a simple script that allows players to check the current health of whatever actor they're looking at:

Code: Select all

Script "CheckTargetHealth" Enter
{
	int player = PlayerNumber();
	
	int health;
	int maxHealth;
	
	// Keep looping while the player is alive.
	while(GetActorProperty(0, APROP_HEALTH) > 0)
	{
		// Check if the player has a target (the actor in their line of sight).
		if(SetActivatorToTarget(0))
		{
			// Now the player's target is the activator of this script.
			// Check if the target has an item in their inventory (called "ConditionItem" in this case) that allows the player to see their health.
			if(CheckInventory("ConditionItem"))
			{
				health = GetActorProperty(0, APROP_HEALTH);
				maxHealth = GetActorProperty(0, APROP_SPAWNHEALTH);
				
				// Set the activator of the script back to the player.
				SetActivatorToPlayer(player);
				
				// Preview the health of the target in the middle of the player's screen for approximately one tic (1/35 of a second).
				HudMessage(s:"Target Health: ", d:health, s:"/", d:maxHealth; HUDMSG_PLAIN, 0, CR_RED, 0.5, 0.5, 0.03);
			}
			
			// Set the activator to the player if it hasn't been done already.
			SetActivatorToPlayer(player);
		}
	}
	
	Delay(1);
}
The example above will work only when the player joins the game, so you may have to change the script type to whatever's best for you. This script should be able to work as a clientsided script too, if the amount of network traffic is a concern, as long as you include "Clientside" at the end of the script definition.
Yeah so i got around it cause i got around starting to work on the character i intended to make use of this and... first of all even the wiki has no such function as "SetActivatorToPlayer" and my script compiler had no idea what this was. Second, the original set position the delay it either nearly crashes my game or crashes the script as a "runaway" script. I came around changing its place but it causes the issue where the health is displayed for a single tic and then never ever reappears again.

Here's my modified script, the //// bits were to disable the item check requirement to test on any characters beforehand

Code: Select all

Script "CheckTargetHealth" Enter
{
	int playernum = ActivatorTID ();
	
	int health;
	int maxHealth;
	
	// Keep looping while the player is alive.
	while(GetActorProperty(0, APROP_HEALTH) > 0)
	{
		// Check if the player has a target (the actor in their line of sight).
		if(SetActivatorToTarget(0))
		{
			// Now the player's target is the activator of this script.
			// Check if the target has an item in their inventory (called "ConditionItem" in this case) that allows the player to see their health.
			////if(CheckInventory("ConditionItem"))
			////{
				health = GetActorProperty(0, APROP_HEALTH);
				maxHealth = GetActorProperty(0, APROP_SPAWNHEALTH);
				
				// Set the activator of the script back to the player.
				SetActivator(playernum);
				
				// Preview the health of the target in the middle of the player's screen for approximately one tic (1/35 of a second).
				HudMessage(s:"Target Health: ", d:health, s:"/", d:maxHealth; HUDMSG_PLAIN, 0, CR_RED, 0.5, 0.5, 0.03);
			////}
			
			// Set the activator to the player if it hasn't been done already.
			SetActivator(playernum);
		}
		SetActivator(playernum);
		Delay(1);
	}
}
EDIT: Apparently its cause a "Restart;" needed to be added below the delay. Ah well. Still, thanks for the starting point/basis, helped a lot