Frictional Games Forum (read-only)
Key Problem - 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: Key Problem (/thread-9130.html)



Key Problem - GreyFox - 07-13-2011

Hey, Me once again with another problem but it seems easy to fix. Just to hard for me.

Anyways I Have 2 Keys and each key unlocks a different door the problem is when i unlock one door the other one unlocks as well. because I don't know how to separate the code in the script,

Code:
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("Door_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "Door_2", 0, false);
    RemoveItem("Key_2");
}

I had that first, and it said I cannot use it because that prefix was already being used. So I did this.

Code:
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");

    SetSwingDoorLocked("Door_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "Door_2", 0, false);
    RemoveItem("Key_2");
}

But that Didn't work either.
Thank you for helping in Advance
-Grey Fox (The Noob)


RE: Key Problem - SkuLLfac3 - 07-13-2011

I'm not good at scripting but I would say, the reason is, that you use the same void syntax. I would do something like that:

Code:
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");
}

void UsedKeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("Door_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "Door_2", 0, false);
    RemoveItem("Key_2");
}

Sry for my bad English but I hope you know what I mean Smile

EDIT: Of course, if you have something else in the script with "UsedKeyOnDoor" but you want the second door (Door_2) , you have to change that to "UsedKeyOnDoor2".


RE: Key Problem - xtron - 07-13-2011

The first one you posted with two different voids is wrong and will probably give you errors 'cuz you can't have a script that executes two functions. please post your void OnStart()
stuff aswell and I'll see if I can fix it Smile


RE: Key Problem - GreyFox - 07-13-2011

My Whole Script? Okay

Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
AddUseItemCallback("", "LockedDoorKey_1", "LockedDoor_1", "UsedKeyOnDoor", true);    
AddUseItemCallback("", "Key_2", "Door_2", "UsedKeyOnDoor", true);
AddEntityCollideCallback("Player", "Scare_1", "CollideScare_1", true, 1);
AddEntityCollideCallback("Player", "Doorslam_1", "CollideDoorslam_1", true, 1);
AddEntityCollideCallback("Player", "MonsterActivate", "CollideMonsterActivate", true, 1);
}

void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");

    SetSwingDoorLocked("Door_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "Door_2", 0, false);
    RemoveItem("Key_2");
}

void CollideScare_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("ScareDoor_1", true, true);
}

void CollideDoorslam_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("LockedDoor_1", true, true);
}

void CollideMonsterActivate(string &in asParent, string &in asChild, int alState)
{
    SetNPCAwake("Frank_2", true, false);
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_5", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_7", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_17", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_27", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_36", 0, "");
    SetEnemyDisabled("Frank_2", true);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

///////////////////////////
//Run when leaving map
void OnLeave()
{

}

Ignore the bottom part with all the waypoints i have to fix that Unless someone knows how to fix that? It won't activate. no error or anything but not the point.

-Grey Fox


RE: Key Problem - SkuLLfac3 - 07-14-2011

(07-13-2011, 11:20 PM)xtron Wrote: The first one you posted with two different voids is wrong and will probably give you errors 'cuz you can't have a script that executes two functions. please post your void OnStart()
stuff aswell and I'll see if I can fix it Smile

Do you mean my solution? I don't know much about it Big Grin I'm new Tongue

I still would say this:
Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
AddUseItemCallback("", "LockedDoorKey_1", "LockedDoor_1", "UsedKeyOnDoor", true);    
AddUseItemCallback("", "Key_2", "Door_2", "UsedKeyOnDoor2", true);
AddEntityCollideCallback("Player", "Scare_1", "CollideScare_1", true, 1);
AddEntityCollideCallback("Player", "Doorslam_1", "CollideDoorslam_1", true, 1);
AddEntityCollideCallback("Player", "MonsterActivate", "CollideMonsterActivate", true, 1);
}

void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");
}

void UsedKeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("Door_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "Door_2", 0, false);
    RemoveItem("Key_2");
}

void CollideScare_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("ScareDoor_1", true, true);
}

void CollideDoorslam_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("LockedDoor_1", true, true);
}

void CollideMonsterActivate(string &in asParent, string &in asChild, int alState)
{
    SetNPCAwake("Frank_2", true, false);
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_5", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_7", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_17", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_27", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_36", 0, "");
    SetEnemyDisabled("Frank_2", true);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

///////////////////////////
//Run when leaving map
void OnLeave()
{

}

I'm not sure but you can try it ^^


RE: Key Problem - Zypherzemus - 07-14-2011

Yea.. Uh... You have to change the "UsedKeyOnDoor" function name to something else. Like what SkuLL posted. "UsedKeyOnDoor2" etc.
Like so:
Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
SetEntityPlayerInteractCallback("Mansion_5", "MonsterActivate", true);
AddUseItemCallback("", "LockedDoorKey_1", "LockedDoor_1", "UsedKeyOnDoor", true);    
AddUseItemCallback("", "Key_2", "Door_2", "UsedKeyOnDoor2", true);
AddEntityCollideCallback("Player", "Scare_1", "CollideScare_1", true, 1);
AddEntityCollideCallback("Player", "Doorslam_1", "CollideDoorslam_1", true, 1);
AddEntityCollideCallback("Player", "MonsterActivate", "CollideMonsterActivate", true, 1);
}

void MonsterActivate(string &in Entity)
{
    SetEntityActive("Frank", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("LockedDoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "LockedDoor_1", 0, false);
    RemoveItem("LockedDoorKey");
}

void UsedKeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("Door_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "Door_2", 0, false);
    RemoveItem("Key_2");
}

void CollideScare_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("ScareDoor_1", true, true);
}

void CollideDoorslam_1(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("LockedDoor_1", true, true);
}

void CollideMonsterActivate(string &in asParent, string &in asChild, int alState)
{
    SetNPCAwake("Frank_2", true, false);
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_5", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_7", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_17", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_27", 0, "");
    AddEnemyPatrolNode("Frank_2", "PathNodeArea_36", 0, "");
    SetEnemyDisabled("Frank_2", true);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

///////////////////////////
//Run when leaving map
void OnLeave()
{

}

I fixed the function for "Key_2" and "Door_2". it's now "UsedKeyOnDoor2".
You also had both commands in the same callback function, which is a big "no-no". Tongue
Hope this helps.
EDIT:
Oh.. I'm not sure if the "AddUseItemCallback" command really matters if it's in either the OnStart() or OnEnter()
I was told it did, but try it out and see first. If it gives you an error, move both "AddUseItemCallback" commands as well as their callback functions down into the OnEnter() section.


RE: Key Problem - xtron - 07-14-2011

Snuffs code should do it Tongue


RE: Key Problem - GreyFox - 07-15-2011

Hey Guys, You Helped Me alot. Sorry For the Late Reply Been Gone the past two days.

Thank You!!
-Grey Fox