Frictional Games Forum (read-only)
I'm back, with a new custom story and another question! [SOLVED] - 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: I'm back, with a new custom story and another question! [SOLVED] (/thread-9372.html)



I'm back, with a new custom story and another question! [SOLVED] - Karai16 - 07-25-2011

Hey guys! I'm back after some time of not being here! ^^
I'm working on another custom story at the moment, but I'm facing some problems. You see:
Code:
void OnStart()
{
    SetEntityPlayerInteractCallback("OutsideDoor", "Checking", true);
    AddEntityCollideCallback("Player", "ScriptArea_1", "Checking2", true, 1);
}

void Checking(string &in asEntity)
{
    if (HasItem("Lantern")!=true)
    {
        SetMessage("Message", "OutsideDoorText", 0);
    }
}

void Checking2(string &in asParent , string &in asChild , int alState)
{
    if (HasItem("Lantern")==true)
    {
            SetLevelDoorLocked("OutsideDoor", false);
    }
}
This is the code of the Hallway. You can't go through a certain door as long as you don't have your lantern, which is in the bedroom. The lantern's called "Lantern". I've tested it, also with it just trying to play music instead of opening the door, but for some reason, it keeps saying that the second if statement is false, even if you have the lantern... can you help me out? I'm at a loss
Huh


RE: I'm back, with a new custom story and another question! - Tanshaydar - 07-25-2011

HasItem("Lantern") == true

== true is unneeded here, as HasItem function is a boolean function.

This happened to someone else too. So, how about unlocking the level door on lantern pickup instead of checking if player has it?


RE: I'm back, with a new custom story and another question! - Karai16 - 07-25-2011

(07-25-2011, 06:38 PM)Tanshaydar Wrote: HasItem("Lantern") == true

== true is unneeded here, as HasItem function is a boolean function.

This happened to someone else too. So, how about unlocking the level door on lantern pickup instead of checking if player has it?

Well you see, lantern is picked up in another map, So that's why I can't unlock that door yet. But if there is a way, I'm all ears ofcourse.


RE: I'm back, with a new custom story and another question! - DRedshot - 07-25-2011

I found a workaround when i ran into this problem

if(HasItem("Lantern")){}
else{
// Unlock door
}

Smile


RE: I'm back, with a new custom story and another question! - Karai16 - 07-25-2011

(07-25-2011, 11:11 PM)DRedshot Wrote: I found a workaround when i ran into this problem

if(HasItem("Lantern")){}
else{
// Unlock door
}

Smile

Well the thing is, the door has to unlock when you do have the lantern. Also, I've tried something simular before, but it doesn't work either.


RE: I'm back, with a new custom story and another question! - DRedshot - 07-25-2011

ok, I dont fully understand what you're trying to do. If you want the door to unlock when you do have the lantern, this should work:

if(HasItem("Lantern")){
// Unlock Door
}

if that doesn't work, you may not have called it Lantern.


RE: I'm back, with a new custom story and another question! - Roenlond - 07-25-2011

When you pick up the lantern in map 1, set a global variable to 1 and check if that variable is 1 when you click on the door.


RE: I'm back, with a new custom story and another question! - Karai16 - 07-26-2011

(07-25-2011, 11:51 PM)Roenlond Wrote: When you pick up the lantern in map 1, set a global variable to 1 and check if that variable is 1 when you click on the door.

Okay, I did that, but it still won't open the door... Here are the scripts:

Hallway: (The map where the game starts (atm) and where the door is that needs to be unlocked)
Code:
void OnGameStart()
{
    SetGlobalVarInt("LanternVar", 1);
}

void OnStart()
{
    SetEntityPlayerInteractCallback("OutsideDoor", "Checking", true);
    AddEntityCollideCallback("Player", "ScriptArea_1", "Checking2", true, 1);
}

void Checking(string &in asEntity)
{
    if (GetGlobalVarInt("LanternVar") != 2)
    {
        SetMessage("Message", "OutsideDoorText", 0);
    }
}

void Checking2(string &in asParent , string &in asChild , int alState)
{
    if (GetGlobalVarInt("LanternVar") == 2)
    {
            SetLevelDoorLocked("OutsideDoor", false);
    }
}

Bedroom: (The map where you get the lantern)
Code:
void OnStart()
{
    SetEntityPlayerInteractCallback("Lantern", "Setvar", true);
}

void Setvar(string &in asEntity)
{
    AddGlobalVarInt("LanternVar", 1);
}
and for the record, yes, I am sure I called the lantern "Lantern"... I tried, but the door still won't open. Huh


RE: I'm back, with a new custom story and another question! - Anxt - 07-27-2011

Ok, here's what you do:

Since you already have your GlobalVarInt set up, use an if statement in your hallway map to unlock the door. So, for example:

void OnEnter()
{
if(GetGlobalVarInt("LanternVar")==1)
{ SetLevelDoorLocked(blahblahblah);
}
}

Here's where I suspect the problem is: You have your LanternVar set to 1 at the start of the game. Set it to 0. Then, when you get the lantern, adding 1 to it will make it 1, thus making the function I have outlined for you above work properly. Hope that helped Smile


RE: I'm back, with a new custom story and another question! - Karai16 - 07-27-2011

(07-27-2011, 01:06 AM)Anxt Wrote: Ok, here's what you do:

Since you already have your GlobalVarInt set up, use an if statement in your hallway map to unlock the door. So, for example:

void OnEnter()
{
if(GetGlobalVarInt("LanternVar")==1)
{ SetLevelDoorLocked(blahblahblah);
}
}

Here's where I suspect the problem is: You have your LanternVar set to 1 at the start of the game. Set it to 0. Then, when you get the lantern, adding 1 to it will make it 1, thus making the function I have outlined for you above work properly. Hope that helped Smile

Thanks anxt! It's working completely fine now Smile