Need to start some were in modding right? Why not try the Half-Life modding Kit. This Kit is designed to have all the tools you need to start your own Half-Life mod, simple mods can be made or advance ones like Base Defense with this small set of tools. If you want to start modding Half-Life you should try this.

Post tutorial Report RSS Adding New Skill Healths

In this tutorial we will learn how to add new Skill Health links to add to new custom monsters.

Posted by on - Intermediate Server Side Coding

So lets first get started with a little information about what Skill Health is and how it works. If you really don't care just skip this part I won't judge. But it is important to understand how your code works. So first off we will work in the server side part of the code. The reason this is done on server side is so that servers have the values of the monsters, if the clients had the values every player could have a different value for a monster. The way the skill health works is tells the server that the monster has this set link such as zombies have "gSkillData.zombieHealth" which tells the server to go access the zombie health values. But really there are 3 values to access, hard mode, normal mode, and easy mode. Now that's enough learning lets do the coding.

So lets start off by going to your custom monster I am going to use a zombie barney that I codded but all monsters will be the same. Go to your spawn function and you will see this

//=========================================================
// Spawn
//=========================================================
void CZombieB :: Spawn()
{
	Precache( );

	SET_MODEL(ENT(pev), "models/zombiebarney.mdl");
	UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );

	pev->solid			= SOLID_SLIDEBOX;
	pev->movetype		= MOVETYPE_STEP;
	m_bloodColor		= BLOOD_COLOR_GREEN;
	pev->health			= gSkillData.zombieHealth;
	pev->view_ofs		= VEC_VIEW;// position of the eyes relative to monster's origin.
	m_flFieldOfView		= 0.5;// indicates the width of this monster's forward view cone ( as a dotproduct result )
	m_MonsterState		= MONSTERSTATE_NONE;
	m_afCapability		= bits_CAP_DOORS_GROUP;
    pev->rendercolor = Vector( 255, 0, 0 ); // color
	MonsterInit();
}

This is all the information the server needs to spawn a zombie, what we are interested in is the "pev->health" as you can see it is set as "gSkillData.zombieHealth" this is the default zombie health but we want a new health right? Lets change it to "gSkillData.zombiebarneyHealth" You can use what ever you want just remember what you used. Now lets go to "gamerules.cpp" and search "gSkillData.zombieHealth" it should be around line 200. You will see the link to cvar.

	// Zombie
	gSkillData.zombieHealth = GetSkillCvar( "sk_zombie_health");
	gSkillData.zombieDmgOneSlash = GetSkillCvar( "sk_zombie_dmg_one_slash");
	gSkillData.zombieDmgBothSlash = GetSkillCvar( "sk_zombie_dmg_both_slash")

This simply links the little name we added before to the actual values which we will add next. Just copy the " gSkillData.zombieHealth = GetSkillCvar( "sk_zombie_health");" and add your custom values like this.

// Zombie
	gSkillData.zombiebarneyHealth = GetSkillCvar( "sk_zombiebarney_health");

Remember how I said that there are 3 values, 1 for each game difficulty? We need to add them in now. Open "game.cpp" and search "sk_zombie_health" which is around line 270. You will see part of are 3 values.

// Zombie
cvar_t	sk_zombie_health1 = {"sk_zombie_health1","0"};
cvar_t	sk_zombie_health2 = {"sk_zombie_health2","0"};
cvar_t	sk_zombie_health3 = {"sk_zombie_health3","0"};

The "0" is not the health so do not change it. I am not quite sure what the "0" is but I think it sets default health to 0. Copy and Paste this and change them to what ever value you used last time. For example mine will look like this.

// Zombie Barney
cvar_t	sk_zombiebarney_health1 = {"sk_zombiebarney_health1","0"};
cvar_t	sk_zombiebarney_health2 = {"sk_zombiebarney_health2","0"};
cvar_t	sk_zombiebarney_health3 = {"sk_zombiebarney_health3","0"};

Now if you search "sk_zombie_health" again it will take you to around line 750 and you will see.

	// Zombie
	CVAR_REGISTER ( &sk_zombie_health1 );// {"sk_zombie_health1","0"};
	CVAR_REGISTER ( &sk_zombie_health2 );// {"sk_zombie_health3","0"};
	CVAR_REGISTER ( &sk_zombie_health3 );// {"sk_zombie_health3","0"};

This simply registers the health as a CVAR so that we can use it. I do not know why valve has the comments on the side but I think that at one point the what we last did was done here to. copy and paste this and change it to your custom code, for example mine would be this.

	// Zombie Barney
	CVAR_REGISTER ( &sk_zombiebarney_health1 );
	CVAR_REGISTER ( &sk_zombiebarney_health2 );
	CVAR_REGISTER ( &sk_zombiebarney_health3 );

I took out the comments because they do not do anything. Remember any thing marked by 2 "/" or a set of "/**/" are comments and do not affect the code in any way. Now that last part of coding we need to do will be in "gamerules.cpp" Again search for "sk_zombie_health" and it will take you to around line 220. Here you will see.

// Zombie
	gSkillData.zombieHealth = GetSkillCvar( "sk_zombie_health");

What this piece of code does is real simple, it tells the server that the "gSkillData.zombieHealth" uses the Cvar "sk_zombie_health". Change these to your custom values. Mine will be this.

// Zombie Barney
	gSkillData.zombiebarneyHealth = GetSkillCvar( "sk_zombiebarney_health");

Now compile you dll. If you Spawn your custom monster in the game now it will have the health we set but somethings not right is it? The monster has 1 health so any damage will kill it. What we need to do is edit our "skill.cfg" file that is inside our mod folder. If you do not have one of these in your mod folder copy and paste it from the valve folder. The skill.cfg holds all the information for weapons and monsters that use skill damage or health. This allows the game to change the values based on the difficulty chosen by the player. In the standard Half-Life different difficulties just change how much health the monsters have and nothing else. Some mods like to change health and damage of the weapons, and in the Spirit Of Half-Life Engine you can even set certain monsters or items to only spawn on certain difficulties. If you start your maps from the console by typing "map yourmapname" I think it sets the difficulty o normal. If you open you skill.cfg and search "sk_zombie_health" you will find this.

// Zombie
sk_zombie_health1	"50"
sk_zombie_health2	"50"
sk_zombie_health3	"100"

These are the set health values for each difficulty. "sk_zombie_health1" is easy, "sk_zombie_health2" is normal and "sk_zombie_health3" is hard. Copy and paste this to your custom values mine would be this.

// Zombie Barney
sk_zombiebarney_health1	"60"
sk_zombiebarney_health2	"60"
sk_zombiebarney_health3	"110"

Now I did not set my values to much higher because default zombies take 70% bullet damage, my custom zombie takes P I will cover how to change these in a later tutorial. But that is it. If you start you game now your custom monster will have its own set health. Hope this tutorial helped, I could never find a tutorial on how to add these custom health but it was real easy right? Lets just cover 1 other thing you can do real fast. If you instead don't want to do all this work and want your monster to have 1 health value over all difficulties just go back to your spawn function and change the "gSkillData.zombieHealth" to a number value for example.

//=========================================================
// Spawn
//=========================================================
void CZombieB :: Spawn()
{
	Precache( );

	SET_MODEL(ENT(pev), "models/zombiebarney.mdl");
	UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );

	pev->solid			= SOLID_SLIDEBOX;
	pev->movetype		= MOVETYPE_STEP;
	m_bloodColor		= BLOOD_COLOR_GREEN;
	pev->health			= 100;
	pev->view_ofs		= VEC_VIEW;// position of the eyes relative to monster's origin.
	m_flFieldOfView		= 0.5;// indicates the width of this monster's forward view cone ( as a dotproduct result )
	m_MonsterState		= MONSTERSTATE_NONE;
	m_afCapability		= bits_CAP_DOORS_GROUP;
    pev->rendercolor = Vector( 255, 0, 0 ); // color
	MonsterInit();
}

This way the custom monster will always have 100 health. I do not recommend doing it this way but it works and it is extremely fast to do. More tutorials can be found on Halflifemoddingkit.weebly.com

The website is a bit of a mess right now but I am working on updating it

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Icon
Half-Life
Game
Half-Life
Creator
badsniper365
Contact
Send Message
Release date
Mod watch
Follow
Tutorial
Tags
Tutorial
Browse
Tutorials
Report
Report
Share
Related Games
Half-Life
Half-Life First Person Shooter