Frictional Games Forum (read-only)
[SCRIPT] If HasItem Help - 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] If HasItem Help (/thread-48577.html)



If HasItem Help - 3gamers - 05-29-2016

Have a script area set up in a dark room. When the Player enters the script area without the lantern in their inventory then I want to play the voice over warning the Player to turn around.

Conversely, if the Player has the lantern when entering the script area, I want the level door to 'unlock'.

Here is the script I have, I'm not sure if it will even work, but the only error I'm getting in 'Unexpected end of line'.

void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea_needlight", "Needlantern", "true", 1);
}

void Needlantern(string& asParentName, string& asChildName, string& asFunction, bool abDeleteOnCollide, int alStates)
{
if (bool HasItem"lantern")
{
SetLevelDoorLocked("leveldoortomain", false);
}
else if (bool HasItem"lantern")
{
PlaySoundAtEntity("", "VOICEOVERFILEHERE.ogg", "Player", 0, false);
}
}

Thankful for any comments.


RE: If HasItem Help - Darkfire - 05-29-2016

You used the function "GetSomething" wrong. The "bool" means that the function will retrieve a true or false result. There are also "int" and "float" which are for numbers.

To work it should look like
if( HasItem("lantern") == true ) ///or if( HasItem("lantern") == false ) depending on what you want to do
{
///rest of stuff
}


RE: If HasItem Help - TimProzz - 06-02-2016

Don't put "bool" in front of it. It's just there to show you what it returns. In this case a boolean.

if(HasItem("lantern") == true)
{
SetLevelDoorLocked("leveldoortomain", false);
} else {
PlaySoundAtEntity("", "VOICEOVERFILEHERE.ogg", "Player", 0, false);
}