Frictional Games Forum (read-only)
[SCRIPT] How to activate an event only when having a specific item - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] How to activate an event only when having a specific item (/thread-56190.html)



How to activate an event only when having a specific item - lpolpo - 01-09-2019

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.


RE: How to activate an event only when having a specific item - Romulator - 01-09-2019

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:
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/amnesia/script_language_reference_and_guide/control_flow_-_conditional_statements


RE: How to activate an event only when having a specific item - lpolpo - 01-14-2019

Thank you so much !!!