Food in Half Life 2

Tutorial collection, comprehensive listings on main site.

Food in Half Life 2

Postby Tutorial on Thu Dec 18, 2008 4:16 pm

category
General Half-Life 2/Entities

description
Edible food that regenerates player health.

keywords
food, health, edible.

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.

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.

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.

Image

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

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.

Image

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

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:

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
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Re: Food in Half Life 2

Postby Noodles on Thu Dec 18, 2008 4:39 pm

Nice one :)
'English as tuppence, changing yet changeless as canal water, nestling in green nowhere, armoured and effete, bold flag-bearer, lotus-fed Miss Havershambling, opsimath and eremite, feudal, still reactionary Rawlinson End.'
User avatar
Noodles
Pheropod
Pheropod
 
Joined: Mon May 09, 2005 3:52 pm
Location: Sweden

Re: Food in Half Life 2

Postby MasterDonut on Thu Dec 18, 2008 4:53 pm

Exactly what I needed to implement into my mod! Thanks!
User avatar
MasterDonut
Design Section Winner!
Design Section Winner!
 
Joined: Tue Aug 12, 2008 9:56 am

Re: Food in Half Life 2

Postby zombie@computer on Thu Dec 18, 2008 5:19 pm

I'd take a slightly different approach:

name the can, eg 'prop_cola'

check the "Generate output on +USE " flag

Create a trigger_hurt around the can (eg 128*128*128);

name set to 'prop_cola_health'
health to set eg -10;
parentname set to 'prop_cola' (=our can)

outputs for the trigger_hurt

onHurtPlayer 'prop_cola_health' Kill
onHurtPlayer 'prop_cola' Kill


Now add the following output to 'prop_cola':

OnPlayerUse 'prop_cola_health' Enable



Now you can kick the can around, toy with it with the grav gun, and it still gives you health when you +use it.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Food in Half Life 2

Postby KILLA-COW on Thu Dec 18, 2008 6:51 pm

zombie@computer wrote:I'd take a slightly different approach:

name the can, eg 'prop_cola'

check the "Generate output on +USE " flag

Create a trigger_hurt around the can (eg 128*128*128);

name set to 'prop_cola_health'
health to set eg -10;
parentname set to 'prop_cola' (=our can)

outputs for the trigger_hurt

onHurtPlayer 'prop_cola_health' Kill
onHurtPlayer 'prop_cola' Kill


Now add the following output to 'prop_cola':

OnPlayerUse 'prop_cola_health' Enable



Now you can kick the can around, toy with it with the grav gun, and it still gives you health when you +use it.


He's a smart'un.
KILLA-COW
Veteran
Veteran
 
Joined: Sun Jun 12, 2005 1:37 pm
Location: The Island of britania!

Re: Food in Half Life 2

Postby dissonance on Thu Dec 18, 2008 8:12 pm

KILLA-COW wrote:
zombie@computer wrote:I'd take a slightly different approach:

name the can, eg 'prop_cola'

check the "Generate output on +USE " flag

Create a trigger_hurt around the can (eg 128*128*128);

name set to 'prop_cola_health'
health to set eg -10;
parentname set to 'prop_cola' (=our can)

outputs for the trigger_hurt

onHurtPlayer 'prop_cola_health' Kill
onHurtPlayer 'prop_cola' Kill


Now add the following output to 'prop_cola':

OnPlayerUse 'prop_cola_health' Enable



Now you can kick the can around, toy with it with the grav gun, and it still gives you health when you +use it.
He's a smart'un.
Sure is.
Might I suggest adding "method one" and "method two" sections to the tutorial?
Oh, and I'd imagine you'd want to add a filter on that trigger restricting the damage to !player, just in case a headcrab wanders in on your meal.
i had fun once, and it was awful.
User avatar
dissonance
Veteran
Veteran
 
Joined: Wed Oct 10, 2007 12:35 am
Location: usa

Re: Food in Half Life 2

Postby Zipfinator on Thu Dec 18, 2008 9:31 pm

dissonance wrote:Oh, and I'd imagine you'd want to add a filter on that trigger restricting the damage to !player, just in case a headcrab wanders in on your meal.


Well you have to use the can still in zombies method. I don't think the headcrab has a keyboard.
Image
|Pipe Dream|City 17: Episode 1|
User avatar
Zipfinator
Veteran
Veteran
 
Joined: Thu Dec 21, 2006 6:03 pm
Location: California

Re: Food in Half Life 2

Postby dissonance on Thu Dec 18, 2008 9:39 pm

Zipfinator wrote:
dissonance wrote:Oh, and I'd imagine you'd want to add a filter on that trigger restricting the damage to !player, just in case a headcrab wanders in on your meal.
Well you have to use the can still in zombies method. I don't think the headcrab has a keyboard.
Derp.
I meant, when the trigger is... triggered, it's going to effect anything in it's volume, which could possibly include enemies.
i had fun once, and it was awful.
User avatar
dissonance
Veteran
Veteran
 
Joined: Wed Oct 10, 2007 12:35 am
Location: usa

Return to Tutorials

Who is online

Users browsing this forum: No registered users