Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support


Post Reply 
 
Thread Rating:
  • 3 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] Use crowbar to open a door
Author Message
SilentStriker Offline
Posting Freak

Posts: 950
Joined: Jul 2011
Reputation: 42
Post: #1
[Tutorial] Use crowbar to open a door

Hello everyone! Because alot of people has been asking how to open a door with a crowbar and get all the flashy effects of pulling and particles etc, here is a tutorial on how to do it! Smile

Important thing: All the items and things name can be changed they don't need to be named the same as I have in this tutorial but if you change the name remember to change inside the script!

Step 1: Choose the door of your liking on which you will use the crowbar, Then create the following so it looks like this:

[Image: 2011cz.png]

The AreaUseCrowbar is the tall script area, and should be placed in the aligned with the doors side.

The AreaBreakEffect is the little box placed near the handle of the door, you can place it a bit to the left of the handle and it should look good
It is used to make a dust effect when the door is unlocked

The BreakDoor script area is the big square on the right, It is there because when the crowbar hits the area it calls the function which opens the door.

The Crowbar_joint should be placed where the area is on the AreaUseCrowbar and should be sized up to 1.2, 1.2, 1.2. You can test how far in you want to crowbar to be Smile

The crowbar_dyn should be placed a bit to the right of the crowbar_joint and should be placed so the head of the crowbar is a little bit inside the BreakDoor area. And it should also be sized to 1.2, 1.2, 1.2
And is activated when the crowbar_joint hits the BreakDoor area and if you want the crowbar to break change the Entity file of the crowbar_dyn to Crowbar_broken

Remember: Make the crowbars inactive in the level editor

Step 2: And when all that is done it is time for the script. This is almost the same script (I removed some unecessary stuff) that Frictional games uses in Amnesia: TDD

PHP Code: (Select All)
////////////////////////////
// Run first time starting map
void OnStart()
{
//Makes it able for the Crowbar_joint to collide with the area in my case I call it BreakDoor
AddEntityCollideCallback("NAMEOFTHECROWBAR_JOINT""NAMEOFTHEAREA""CollideAreaBreakDoor"true1);

//Makes it able for the item crowbar to be used in the world, this one calls the callback if you place the crowbar on the door
AddUseItemCallback("crowbarondoor""NAMEOFTHECROWBAR""NAMEOFTHEDOOR""UseCrowbarOnDoor"true);

//Same as above but this one creates the callback if you place the crowbar in the area in my case the AreaUseCrowbar. 
//Remember that they call the same function so it doesn't matter where you use your crowbar
AddUseItemCallback("crowbaronframe""NAMEOFTHECROWBAR""NAMEOFTHEAREA""UseCrowbarOnDoor"true);
}

////////////////////
//BEGIN BREAK DOOR//

//The function called from the AddUseItemCallback
void UseCrowbarOnDoor(string &in asItemstring &in asEntity)
{
//Calls a timer that places the crowbar in the door frame.
AddTimer(asEntity0.2"TimerAttachCrowbar");

//Plays a sound of the player crouching. 
PlaySoundAtEntity("pickupcrow","player_crouch.snt""Player"0.05false);

//Removes the Crowbar.
RemoveItem(asItem);
}

//The timer we called before
void TimerAttachCrowbar(string &in asTimer)
{
//Plays the sound of the player putting the crowbar in the doorframe
PlaySoundAtEntity("attachcrowbar","puzzle_place_jar.snt""Player"0false);

//Sets the crowbar_joint active
SetEntityActive("NAMEOFTHECROWBAR_JOINT"true);
}

//The function we called from the AddEntityCollideCallback
void CollideAreaBreakDoor(string &in asParentstring &in asChildint alState)
{
//Gives a small boost of sanity
GiveSanityBoostSmall();

//Plays music because you completed the puzzle
PlayMusic("10_puzzle01.ogg"false0.70.110false);

//Unlocks the door
SetSwingDoorLocked("NAMEOFYOURDOOR"falsefalse);

//Makes the door not auto close on itself
SetSwingDoorDisableAutoClose("NAMEOFYOURDOOR"true);

//Opens the door slightly
SetSwingDoorClosed("NAMEOFYOURDOOR"false,false);

//Plays the sound of wood breaking.
PlaySoundAtEntity("break","break_wood_metal""NAMEOFYOURBREAKEFFECTAREA"0false);

//Creates a small dust smoke
CreateParticleSystemAtEntity("breakps""ps_hit_wood""NAMEOFYOURBREAKEFFECTAREA"false);

//Adds a impulse on the door. This may need some adjusting since your door may be facing another direction than mine
AddPropImpulse("NAMEOFYOURDOOR"003"world");

//Sets your crowbar_joint inactive
SetEntityActive("NAMEOFYOURCROWBAR_JOINT"false);

//Sets your dynamic crowbar active, In this case it's the Broken crowbar that will fall to the ground.
//You can use the crowbar_dyn then it will fall to the ground without being broken
SetEntityActive("NAMEOFYOURDYNAMICCROWBAR"true);

//Creates a timer that will make the door open slightly
AddTimer("pushdoor"0.1"TimerPushDoor"); 

//A debug showing that the door is open
AddDebugMessage("Break door!"false); 
}

//A timer that is going to push the door open
void TimerPushDoor(string &in asTimer)
{
//Adds a impulse on the door so it opens. Needs to be adjusted according to where your door is facing
AddPropImpulse("NAMEOFYOURDOOR", -12, -4"world");

//Creates a Timer so the door can auto close again.
AddTimer("doorclose"1.1"TimerDoorCanClose");
}
//Timer we just called
void TimerDoorCanClose(string &in asTimer)
{
//Makes the door able to auto close.
SetSwingDoorDisableAutoClose("NAMEOFYOURDOOR"false);
}

//END BREAK DOOR//
////////////////// 

If I missed something please let me know and I fix it ^^


I will maybe do a video tutorial on this if you guys want Smile

Almost forgot!

Here's a map + code for download, so you can look and see how it works yourself

http://www.mediafire.com/?a38095gcamuhat9
(This post was last modified: 05-15-2012 03:03 PM by SilentStriker.)
02-01-2012 04:04 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
[Tutorial] Use crowbar to open a door - SilentStriker - 02-01-2012 04:04 PM



User(s) browsing this thread: 1 Guest(s)