User Tools

Site Tools


Sidebar

hpl2:tutorials:script:disable_gravity_tutorial

Beginner Scripting Tutorial 1

This is an easy tutorial for beginners. It is not intended to teach you new techniques but more to show you all the neat stuff you can do with the functions and the HPL2 engine.

In this tutorial you will learn how to make entities 'float' or rather make them seem to be very very light. Possible uses could be for some strange sanity effects or even simulating an underwater environment!

Getting started

Start by creating a new level in the level editor and then saving the map. There are no real limits, but keep it simple and include some movable entities you can use the script on. In my little room they are the skull and two books. You should include another entity you do not use the effect on, so you can compare their characteristics!

My room looks like this:

Link

After you have saved your map, create a .hps file with the same name. This is where we will do all the scripting, add the default script there. I have removed the if-clause in my example, it is not needed.

////////////////////////////
// Run first time starting map
void OnStart()
{   
   GiveItemFromFile("lantern", "lantern.ent");
 
   for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");    
}
 
////////////////////////////
// Run when entering map
void OnEnter()
{
 
}
 
////////////////////////////
// Run when leaving map
void OnLeave()
{
 
}

The scripting

Now we will do the actual scripting! The floating effect is based on timer functions, and one of these we will add in OnStart() so it is immediately called when the level loads! The syntax for timer function looks like this:

//Function syntax: Func(string &in asTimer)
void  AddTimer(string& asName, float afTime, string& asFunction);

The first string asName is the name of our timer, afTime is the time when the timer will call the function in asFunction after the timer is executed. Adding our timer in OnStar

hpl2/tutorials/script/disable_gravity_tutorial.txt · Last modified: 2011/02/15 21:17 by l1ght5h0w