Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help How to activate an event only when having a specific item
lpolpo Offline
Junior Member

Posts: 2
Threads: 1
Joined: Jan 2019
Reputation: 0
#1
How to activate an event only when having a specific item

Hello,I am currently trying to make a custom story,but there is a problem.

Can someone please tell me how to make an event happen when passing through an area only when the Player has a specific Item?


Thank you.
01-09-2019, 04:50 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: How to activate an event only when having a specific item

For this, you need an "if" conditional statement to check to see if the item is in your inventory. HasItem is the variable you are looking for.

So assuming you already have your Collide Callback set up, you need to make the if check if you have the item in your inventory, and then carry out your event as you wish.

At its most basic, you can write it like this

PHP Code: (Select All)
void OnAreaCollide(string &in asParentstring &in asChildint alState)
{
 
    if(HasItem("lantern") == true)
 
    {
 
         //What to do if they have the lantern.
 
    }


In this instance, when the Player walks through a ScriptArea which triggers the OnAreaCollide function, it will check if the player has a lantern. If they do, the function will carry out whatever is within the parenthesis underneath it, and then proceed to do everything after. This script will also do nothing if the Player doesn't have the lantern, since I haven't written anything to accommodate for that.

The "lantern" in this case can be any item so long as the text in script matches the name of the item in the map. So if they pick up "key_study_4", and you want to test for that, then you should specify "key_study_4" within the brackets of HasItem().

If-Then-Else is a great tool for doing things if certain tasks/events have been met, and are incredibly useful tools for Custom Stories. I recommend reading up about them more on the wiki here: https://wiki.frictionalgames.com/hpl2/am...statements

Discord: Romulator#0001
[Image: 3f6f01a904.png]
01-09-2019, 06:02 PM
Find
lpolpo Offline
Junior Member

Posts: 2
Threads: 1
Joined: Jan 2019
Reputation: 0
#3
RE: How to activate an event only when having a specific item

Thank you so much !!!
01-14-2019, 01:51 PM
Find




Users browsing this thread: 1 Guest(s)