////////////////////////////
// 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", true, 1);
//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 asItem, string &in asEntity)
{
//Calls a timer that places the crowbar in the door frame.
AddTimer(asEntity, 0.2, "TimerAttachCrowbar");
//Plays a sound of the player crouching.
PlaySoundAtEntity("pickupcrow","player_crouch.snt", "Player", 0.05, false);
//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", 0, false);
//Sets the crowbar_joint active
SetEntityActive("NAMEOFTHECROWBAR_JOINT", true);
}
//The function we called from the AddEntityCollideCallback
void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
//Gives a small boost of sanity
GiveSanityBoostSmall();
//Plays music because you completed the puzzle
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
//Unlocks the door
SetSwingDoorLocked("NAMEOFYOURDOOR", false, false);
//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", 0, false);
//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", 0, 0, 3, "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", -1, 2, -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//
//////////////////