Frictional Games Forum (read-only)

Full Version: Key to Unlock Chest
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Alright, so thanks to you wonderful people on this forum, I've been able to start my own custom story with very little knowledge to begin with. Anyhow, I can't seem to find a way to allow a key to unlock a chest and was just wondering if anybody here knows how to do it.
You have to add a useitemcallback
Code:
/
AddUseItemCallback("can be empty", "key name", "chest name", "function name to call", true/false for removing the callback);
And then you have the function it calls look something like
Code:
void MyFunc(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("name of chest", false, true);
//if you want the item removed after use,
RemoveItem("name of key");
}
Ah, of course. I didn't realize that the chest counted as a swing door. Thank you very much.
(07-22-2011, 07:30 AM)Obliviator27 Wrote: [ -> ]Ah, of course. I didn't realize that the chest counted as a swing door. Thank you very much.

No problem, cabinets/closets also count as swing doors, should you want to unlock one of those in the future.
Right, so I now have a new, fun problem. Odds are the problem is right in front of my eyes, but I'll let you guys see for yourselves. Basically, I have all the script for opening the chest. However, it refuses to be locked in the first place.

void OnStart()
{
FadeIn(0);
AddPlayerHealth(100);
SetPlayerLampOil(30);
SetSwingDoorLocked("MedChest", true, true);
AddUseItemCallback("", "MedChestKey", "MedChest", "UnlockMedicineChest", true);
}
void UnlockMedicineChest(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("MedChest", false, true);
RemoveItem("MedChestKey");
}

All in-game file names correspond properly.
I'm not sure if a chest counts as a swingdoor Undecided

But I think it is Big Grin cause else I don't remember me another unlock command xD

Whatever Tongue

Add me if u have questions.
Msn: ferry_hooligan@live.nl
Steam: ferryadams1
(07-22-2011, 09:01 AM)Obliviator27 Wrote: [ -> ]Right, so I now have a new, fun problem. Odds are the problem is right in front of my eyes, but I'll let you guys see for yourselves. Basically, I have all the script for opening the chest. However, it refuses to be locked in the first place.

void OnStart()
{
FadeIn(0);
AddPlayerHealth(100);
SetPlayerLampOil(30);
SetSwingDoorLocked("MedChest", true, true);
AddUseItemCallback("", "MedChestKey", "MedChest", "UnlockMedicineChest", true);
}
void UnlockMedicineChest(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("MedChest", false, true);
RemoveItem("MedChestKey");
}

All in-game file names correspond properly.

Hello Big Grin

I'm no expert, but I think it is because you have an extra(unecessary?) true on the SetSwingDoorLocked.

I did [ b] true [ /b] around the true you could remove^^

Hope it helped, RokotainAngel
-----
(07-22-2011, 10:40 AM)Rokotain Wrote: [ -> ]
(07-22-2011, 09:01 AM)Obliviator27 Wrote: [ -> ]Right, so I now have a new, fun problem. Odds are the problem is right in front of my eyes, but I'll let you guys see for yourselves. Basically, I have all the script for opening the chest. However, it refuses to be locked in the first place.

void OnStart()
{
FadeIn(0);
AddPlayerHealth(100);
SetPlayerLampOil(30);
SetSwingDoorLocked("MedChest", true, true);
AddUseItemCallback("", "MedChestKey", "MedChest", "UnlockMedicineChest", true);
}
void UnlockMedicineChest(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("MedChest", false, true);
RemoveItem("MedChestKey");
}

All in-game file names correspond properly.

Hello Big Grin

I'm no expert, but I think it is because you have an extra(unecessary?) true on the SetSwingDoorLocked.

I did [ b] true [ /b] around the true you could remove^^

Hope it helped, RokotainAngel

I dont see the need for setting the player health to 100 and I think the fade in thing is: FadeIn(1.0f);
(07-22-2011, 01:27 PM)Swistrobl Wrote: [ -> ]I think the game actually considers chests equal to levers. If they were swingdoors, wouldn't there at least be a "Locked" checkbox in the entity attributes menu?

I checked and I was wrong actually, they are counted as levers.

Try adding SetLeverStuckState("chestname", 1, true); in OnStart(), or set it to min stuck state in the editor.
And then, add SetLeverStuckState("chestname", 0, true); instead of SetSwingDoorLocked and see if that works.

I apologize for the confusion Sad
Pages: 1 2