Frictional Games Forum (read-only)

Full Version: [SOLVED] Checking for multiple items
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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");
        }
    }

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.
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.