Difference between revisions of "Hpl2:Tutorials:script:random scares"

From Frictional Wiki
Jump to navigation Jump to search
(Upload from wiki)
 
m (Syntax highlighting fix)
 
Line 1: Line 1:
 
This is a script that allows you to make your scares to be randomized, meaning that each playthrough will have different scares.
 
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!
 
Let's get started!
 
  
 
=== Random Scares ===
 
=== Random Scares ===
  
 
+
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="">
 
 
void OnStart()
 
void OnStart()
 
{
 
{
AddEntityCollideCallback("Player", "ScriptArea_1", "PlrCollideSwitch", true, 1);
+
    AddEntityCollideCallback("Player", "ScriptArea_1", "PlrCollideSwitch", true, 1);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
This is the Entity-Collide callback which will start the script.
 
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.
 
If you already have the void OnStart() then just copy-paste the AddEntityCollideCallback line.
 
  
 
Let's break this one on one.
 
Let's break this one on one.
  
 
+
#"Player" is the entity that collides the second entity.
"Player" is the entity that collides the second entity.
+
#"ScriptArea_1" is the entity that gets collided by the first one.
 
+
#"PlrCollideSwitch" will be the function it will do.
 
 
"ScriptArea_1" is the entity that gets collided by the first one.
 
 
 
 
 
"PlrCollideSwitch" will be the function it will do.
 
 
 
  
 
After that, wrote the following code at the bottom of the void OnStart().
 
After that, wrote the following code at the bottom of the void OnStart().
  
 
+
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="">
 
 
void PlrCollideSwitch(string &in asParent, string &in asChild, int alState)
 
void PlrCollideSwitch(string &in asParent, string &in asChild, int alState)
 
{
 
{
int x = RandInt(1, 5)
+
  int x = RandInt(1, 5)
switch(x)
+
  switch(x)
{
+
  {
case 1:
+
  case 1:
//Scare 1
+
  //Scare 1
    break;
+
      break;
case 2:
+
  case 2:
//Scare 2
+
  //Scare 2
    break;
+
      break;
case 3:
+
  case 3:
//Scare 3
+
  //Scare 3
    break;
+
      break;
case 4:
+
  case 4:
//Scare 4
+
  //Scare 4
    break;
+
      break;
case 5:
+
  case 5:
//Scare 5
+
  //Scare 5
    break;
+
      break;
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
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;
 
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;.
 
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.
 
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.
 
You can find me at Frictional Games Forum under the same name.
 
  
 
- JustAnotherPlayer
 
- JustAnotherPlayer

Latest revision as of 19:02, 23 July 2020

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