Hpl2:Tutorials:script:random scares

From Frictional Wiki
Revision as of 18:02, 23 July 2020 by Darkfire (talk | contribs) (Syntax highlighting fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is a script that allows you to make your scares to be randomized, meaning that each playthrough will have different scares.

Let's get started!

Random Scares

void OnStart()
{
    AddEntityCollideCallback("Player", "ScriptArea_1", "PlrCollideSwitch", true, 1);
}

This is the Entity-Collide callback which will start the script.

If you already have the void OnStart() then just copy-paste the AddEntityCollideCallback line.

Let's break this one on one.

  1. "Player" is the entity that collides the second entity.
  2. "ScriptArea_1" is the entity that gets collided by the first one.
  3. "PlrCollideSwitch" will be the function it will do.

After that, wrote the following code at the bottom of the void OnStart().

void PlrCollideSwitch(string &in asParent, string &in asChild, int alState)
{
   int x = RandInt(1, 5)
   switch(x)
   {
   case 1:
   //Scare 1
       break;
   case 2:
   //Scare 2
       break;
   case 3:
   //Scare 3
       break;
   case 4:
   //Scare 4
       break;
   case 5:
   //Scare 5
       break;
}

This is the Switch-Statement that will determine what scare produced. In each Case #, write a specific code that will execute your scare. Make sure that piece of code is BEFORE the break;

You don't need curly brackets ({}) to envelope each case. You need a break;. A code will be executed BEFORE it hit the break;.

Hope this can make your custom story to be fully replayable and unique.

You can find me at Frictional Games Forum under the same name.

- JustAnotherPlayer