Frictional Games Forum (read-only)
[SCRIPT] [SOLVED] Checking for multiple items - 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] [SOLVED] Checking for multiple items (/thread-25157.html)



[SOLVED] Checking for multiple items - Pshyched - 04-25-2014

I am trying to code a way to check for multiple items. The obvious way is not working so Im hoping someone may know a way to check for multiple items before finishing it.

Is there an If / Then / Else function within the HPL2 engine script anyway, if so it would make things easier..

I basically want them to try the key, if the player has not got the other keys in their inventory then it just pops up a message saying "I should grab those keys before I leave" and then does nothing else. Once the player has the keys, it does the normal action that I already coded.

Spoiler below!
Code:
    void LeavingHouse(string &in asItem, string &in asEntity)
    {
        if(HasItem("BarricadeLockKey")==true)
        and
        if(HasItem("CarterIslandEntranceKey")==true)
        
        {
            SetLevelDoorLocked("HouseDoor", false);
            PlaySoundAtEntity("", "unlock_door", "HouseDoor", 0, false);
            CompleteQuest("LeaveHouse","LeaveHouse");
        }
    }




RE: Checking for multiple items - Mudbill - 04-25-2014

There is an "else" keyword you can use. It's very simple.

PHP Code:
void LeavingHouse(string &in asItemstring &in asEntity)
{
    if(
HasItem("BarricadeLockKey") == true
    
&& HasItem("CarterIslandEntranceKey") == true)
    {
        
SetLevelDoorLocked("HouseDoor"false);
        
PlaySoundAtEntity("""unlock_door""HouseDoor"0false);
        
CompleteQuest("LeaveHouse","LeaveHouse");
    }
    else 
SetMessage("MessageCategory""GrabKeys"3);


It's pretty much just like that. Add the proper message category and entry in your .lang file. You can make else into a block if you want to use more than 1 line.


RE: Checking for multiple items - Pshyched - 04-25-2014

You've been a great help to me these past few days, Thank you Mudbill!

EDIT:

I tried this, it works fine. But then it never let's me use the House Key on the door again. It just says you cannot use this item in this way!

Second Edit:

Fixed it, I just made it so the CallBack does not destroy after being used once.