Hpl2:Tutorials:scripting:triggering monsters on entities

From Frictional Wiki
Jump to navigation Jump to search

In this tutorial, JenniferOrange will show you how to trigger a monster when the player picks up an entity.


Setting Up The Room(s)


You're going to need a room to hold the entity, and another room separated by a door to hold the monster. Go ahead and build yourself a quick room(s) or map. Place the entity you'd like the monster to be triggered by somewhere in one of the rooms. For example, let's make the monster be triggered when the player picks up a key. Place a key on a table in the room. Go ahead and re-name the key to anything you like; I named mine key_1. Now, in a different room, place a monster anywhere you'd like. Remember, if you place him very close to the door, when the player picks up the key he will immediately start breaking the door down. Likewise if you place him a little further away, the monster still has to walk to the door. I placed my monster a little ways away from the door. Now re-name your monster to anything you'd like. I named mine monster_ grunt. Make sure you un-check the Active box, to make him un-active. Now you're done setting up the rooms! You just have to script it.


Scripting It


Open your maps .hps file. The first thing we need to do is script the key to unlock a door somewhere else. Choose the door you'd like the key to unlock, BUT NOT THE DOOR THE MONSTER BREAKS DOWN, BECAUSE IT'S POINTLESS, and re-name it to whatever you'd like. I named mine locked_door1. We need to make an AddUseItemCallBack for the key.


<plugin title="stet" ></plugin>


void OnStart()
{
  AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true);


Now we have to make an EntityCallBackFunc for triggering the monster when we pickup the key.


void OnStart()
{  
   AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true);
   SetEntityCallbackFunc("key_1", "OnPickup");
}


OnPickup is the name of the function we are going to call. Now we can finish scripting the key..

void OnStart()
{  
  AddUseItemCallback("key_1", "locked_door1", "UsedKeyOnDoor", true);
  SetEntityCallbackFunc("key_1", "OnPickup");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
  SetSwingDoorLocked("locked_door1", false, true);
  PlaySoundAtEntity("", "unlock_door.snt", "locked_door1", 0, false);
  RemoveItem("key_1");
}


You can change the name of my door, locked_door1, to the name of your locked door, which is NOT THE DOOR THE MONSTER BREAKS DOWN.


Now we can finish up our EntityCallbackFunc!


void OnStart()
{  
  AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true);
  SetEntityCallbackFunc("key_1", "OnPickup");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
  SetSwingDoorLocked("locked_door1", false, true);
  PlaySoundAtEntity("", "unlock_door.snt", "locked_door1", 0, false);
  RemoveItem("key_1");
}
void OnPickup(string &in asEntity, string &in type)
{
  SetEntityActive("monster_grunt", true);
  ShowEnemyPlayerPosition("monster_grunt");
}


Make sure the callback function is the same name. (OnPickup) The script shows that after you pick up the key_1, monster_grunt will activate, and I added ShowEnemyPlayerPosition, which will show the grunt where the player is, so he doesn't wander aimlessly in the other room. Make sure there's a closet in that room too, you'll need somewhere to hide! (unless you make him a hallucination) That's it for your .hps file! You can finish scripting your key in your extra_english.lang file by using Xtrons tutorial on how to make an item unlock a door, which you can find here:


http://wiki.frictionalgames.com/hpl2/tutorials/script/scripting_by_xtron_-_item_that_unlocks_a_door


Thanks for tuning in to this tutorial!


Created by JenniferOrange