About NPCs showing their health (and name if possible) Created 4 years ago2020-06-05 18:45:26 UTC by Alexis_of_Steel Alexis_of_Steel

Created 4 years ago2020-06-05 18:45:26 UTC by Alexis_of_Steel Alexis_of_Steel

Posted 4 years ago2020-06-05 18:45:26 UTC Post #344366
Hello guys. Well I'm sorry if I sound kinda annoying, but you helped me some time ago. I'm very thankful with you. Now, I'm wondering again if you can help me one more time.
I can't figure out how to get NPCs show up their health points and name in vanilla Half-Life, just like they do in Sven Co-op. I wonder if you guys know how to do it... I think I'm gonna have to edit cl_dll, but certainly Idk.
Thanks in advance,
Alexis.
Posted 4 years ago2020-06-05 20:55:06 UTC Post #344367
NPC health and names showing up on the HUD is not a feature in vanilla Half-Life. It was added by Sven Co-op. I definitely think it's possible to add it to Half-Life, though you are going to have to do it in code. You should set up the Half-Life SDK and study some of the other HUD code to figure out how to do it.
Dr. Orange Dr. OrangeSource good.
Posted 4 years ago2020-06-05 23:58:19 UTC Post #344368
I just couldn't get it. :\
Posted 4 years ago2020-06-07 18:04:37 UTC Post #344378
Take a look at impulse 102 -- when called, it prints some information about the entity in front of the player to the console. If you can call a modified impulse 102 function in the player's UpdateClientData function (called by the player's PreThink function), you'll be set on the server side. I threw this code together in about 5 minutes. It isn't exactly what you're looking for, but it's a good place to start off. It's just what I described: impulse 102 (alive monster entities only) called every think so you'll need to edit it for your needs.

In player.h:

class CBasePlayer : public CBaseMonster
{
public:
	CBaseEntity *pAlexisEntity;
	void AlexisEntityInfo(void);
...
}
In player.cpp:

void CBasePlayer::AlexisEntityInfo(void) {
	//Give me the classname and targetname of this entity.
	pAlexisEntity = FindEntityForward( this );
	if ( pAlexisEntity && pAlexisEntity->IsAlive() && pAlexisEntity->pev->flags & FL_MONSTER)
	{
		ALERT ( at_console, "Classname: %s", STRING( pAlexisEntity->pev->classname ) );
			
		if ( !FStringNull ( pAlexisEntity->pev->targetname ) )
		{
			ALERT ( at_console, " - Targetname: %s\n", STRING( pAlexisEntity->pev->targetname ) );
		}
		else
		{
			ALERT ( at_console, " - TargetName: No Targetname\n" );
		}

		ALERT ( at_console, "Model: %s\n", STRING( pAlexisEntity->pev->model ) );

		if ( pAlexisEntity->pev->globalname )
			ALERT ( at_console, "Globalname: %s\n", STRING( pAlexisEntity->pev->globalname ) );
	}

}
In player.cpp CBasePlayer::UpdateClientData()

void CBasePlayer :: UpdateClientData( void )
{
	AlexisEntityInfo();
...
}
From here, you'll need to pull the entity's health information and classname, then send them in messages to the client DLL. Take a look at the LinkUserMessages function in player.cpp, the player's health message variable gmsgHealth, and its associated message in the same UpdateClientData function as a guide:

MESSAGE_BEGIN( MSG_ONE, gmsgHealth, NULL, pev );
	WRITE_BYTE( iHealth );
MESSAGE_END();
EDIT: Forgot to mention, this doesn't cover getting the message on the client DLL and printing the information. I'll let someone with more experience with the client chime in.
You must be logged in to post a response.