Tutorials

Food in Half Life 2



After playing Fallout 3, I set myself the little goal of making edible food which regenerates health when you eat it. This tutorial should show you how to do this, and it is quite easy to expand for many food sources with different properties. It's also a viable way for custom health packs.

Let's make a new project, and start off with a simple room. Let's put a table in, we want to be hygienic after all.

news post image

Okay. In this case I'm going to use a soda can, to restore, let's say, 10 health. Put this on your table as a prop_physics.

news post image

Now, let's make a func_button so it envelopes the can, and call it something like (quite creatively) "001Food_Button". Texture it with the Invisible tool texture, or something of similar function. You'll want to parent this to the can.

Next, we need to create a trigger_hurt that fills the entire room. This is quite important: if the player is not in the volume of the trigger_hurt, they won't get healed. Let's call it something like Trigger_Food and put the settings in as shown below.

news post image

Now let's go back to our func_button and make these outputs:

news post image

The delay on the trigger_food and the value for the SetDamage are what determine how much the food will heal the player. Honestly, these values takes some experimentation to get right, but the shown values will give you 10 health. The "kill" outputs make sure you can't eat the food more than once, and the final output resets the trigger_hurt so you don't keep getting healed.

Well, now you have food! Compile, go up to your can and press E to get a good dose of healing goodness! (you want to damage yourself first... grenades are always fun!)

The End Of The Basics

Okay, so that's the end of the basics. But we can still go a little further with this... How will the player know that a food is edible? How will they know how much HP they will get? The answer lies in two entities: Trigger_Look and Game_Text.

Trigger_look is an insanely useful trigger that fire when the player is in it's volume and is looking at a target entity. Game_text allows strings to be shown on the UI.

Lets make a trigger_look that surrounds the food, and call it something like "001FoodTextTrigger". We also want to parent this to our prop_physics soda can, as well as make the soda can the Look Target as shown below. You also need to untick the "fire once only" flag.

news post image

Now let's make a Game_Text and put it somewhere nearby. Let's call it "001FoodMessage", and chuck in these settings:

news post image

For the Text Message lets put "Press E to Eat - 10 HP [Soda Can]" or something like that. The X and Y fields determine where the message appears on the UI. With these values it will appear top right.

Now on our trigger_look, lets make another output:

news post image

Okay, now fire it up, and you should get that message when you look at the soda can (remember, you have to be in the trigger_look volume).

Have fun cooking up a storm!

- cow_trix

View comments ( 7 )

Back to top