Frictional Games Forum (read-only)

Full Version: Crowbar/Key Script Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I'm having trouble with a script for my custom story. If you could help I would greatly appreciate it + tell me what i did wrong, as i can't see anything, although i am new to scripting. It involve a crowbar, a key and 2 door's.
Crowbar=crowbar_1
Key=Waterworks_Key
Door1=Waterworks_Door
Door2=Storage
The key goes with the Waterworks door and the crowbar goes with the storage door. Here is the script:


void OnStart()
{
AddUseItemCallback("", "crowbar_1", "Storage", "UsedCrowbarOnDoor", true);
AddUseItemCallback("", "crowbar_1", "Storage", "UsedCrowbarOnDoor", true);
AddEntityCollideCallback("crowbar_joint_1", "ScriptArea_1", "CollideAreaBreakDoor", true, 1);
}

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

void FUNCTION(string &in asItem, string &in asEntity)
{
AddTimer("", 0.2, "TimerSwitchShovel");
RemoveItem("crowbar_1");
}

void TimerSwitchShovel(string &in asTimer)
{
PlaySoundAtEntity("","puzzle_place_jar.snt", "", 0, false);
SetEntityActive("crowbar_joint_1", true);
}
void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
AddPlayerSanity(25);
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
SetSwingDoorLocked("Waterworks_Door", false, true);
AddPropImpulse("Waterworks_Door", 0, 0, -50, "World");
SetSwingDoorDisableAutoClose("Waterworks_Door", true);
SetSwingDoorClosed("Waterworks_Door", false, false);
SetMoveObjectState("Waterworks_Door", 1);
PlaySoundAtEntity("","break_wood_metal", "AreaBreakEffect", 0, false);
CreateParticleSystemAtEntity("", "ps_hit_wood", "AreaBreakEffect", false);
SetEntityActive("crowbar_joint_1", false);
SetLocalVarInt("Door", 1);
}

{

AddUseItemCallback("", "Waterworks_Key", "Waterworks_Door", "UsedKeyOnDoor", true);

}

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

}





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

}

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

}


Thanks!
,wagiwombledog
I'm going to assume that the key is not working on the door, and the crowbar is not properly prying the door open.
Regardless, this should fix your problems.

Spoiler below!

Code:
void OnStart()
{
AddUseItemCallback("", "crowbar_1", "Storage", "UsedCrowbarOnDoor", true);
AddEntityCollideCallback("crowbar_joint_1", "ScriptArea_1", "CollideAreaBreakDoor", true, 1);
AddUseItemCallback("", "Waterworks_Key", "Waterworks_Door", "UsedKeyOnDoor", true);
}

void UsedCrowbarOnDoor(string &in asItem, string &in asEntity)
{
AddTimer("", 0.2, "TimerSwitchShovel");
RemoveItem("crowbar_1");
}

void TimerSwitchShovel(string &in asTimer)
{
PlaySoundAtEntity("","puzzle_place_jar.snt", "Player", 0, false);
SetEntityActive("crowbar_joint_1", true);
}
void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
AddPlayerSanity(25);
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
SetSwingDoorLocked("Storage", false, true);
AddPropImpulse("Storage", 0, 0, -50, "World");
SetSwingDoorDisableAutoClose("Storage", true);
SetSwingDoorClosed("Storage", false, false);
SetMoveObjectState("Storage", 1);
PlaySoundAtEntity("","break_wood_metal", "AreaBreakEffect", 0, false);
CreateParticleSystemAtEntity("", "ps_hit_wood", "AreaBreakEffect", false);
SetEntityActive("crowbar_joint_1", false);
SetLocalVarInt("Door", 1);
}


void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("Waterworks_Door", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "Player", 0, false);
RemoveItem("Waterworks_Key");
}

Wait... you want the key to open a door and a crowbar to open another door? I say it because both (crowbar and key) target the same door.
(09-12-2012, 05:00 PM)The chaser Wrote: [ -> ]Wait... you want the key to open a door and a crowbar to open another door? I say it because both (crowbar and key) target the same door.
Yeah, using the crowbar on the "Storage" door would open the "Waterworks_Door."
Thank you all for your fast replies, Big Grin I'll try to be less crap with scripting in the future.