Frictional Games Forum (read-only)
[SCRIPT] [SOLVED] Using a Single Crowbar on Multiple Doors - 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: [SCRIPT] [SOLVED] Using a Single Crowbar on Multiple Doors (/thread-26253.html)

Pages: 1 2 3 4 5


RE: Using a Single Crowbar on Multiple Doors - Mudbill - 09-22-2014

Let's take another look then.

Are you sure the areas are in the right locations? Make sure AreaEffect_1 is by Door_1 and so on, as that's how the callbacks are set up. Also make sure they're close enough for the crowbar to actually hit them.

PS: I noticed the GiveItem line gives you the crowbar with the internal name of "crowbar" but the callbacks are set to use "Crowbar_1" which makes me think that this will only work once unless you match them up.


RE: Using a Single Crowbar on Multiple Doors - AGP - 09-22-2014

(09-22-2014, 07:25 AM)Mudbill Wrote: Let's take another look then.

Are you sure the areas are in the right locations? Make sure AreaEffect_1 is by Door_1 and so on, as that's how the callbacks are set up. Also make sure they're close enough for the crowbar to actually hit them.

PS: I noticed the GiveItem line gives you the crowbar with the internal name of "crowbar" but the callbacks are set to use "Crowbar_1" which makes me think that this will only work once unless you match them up.

I'm pretty sure the areas are matched up. I've gone over them several times making sure they were in just the right position.
__________________________________________________________
EDIT:

Turns out I went in and changed "AreaBreak" in the AddEntityCollideCallback function. Putting back the _"+i that had been taken out, the first three doors worked, however it was without the door break sound or particle effect and you could still hear the crowbar bending as the door swung open.

The fourth door did not work; the crowbar again moved only back and forth, and I ended up with three crowbars in the inventory.
And in regards to the crowbar, yes, I thought something like like too, but I wasn't sure how to go about fixing that.


RE: Using a Single Crowbar on Multiple Doors - FlawlessHappiness - 09-22-2014

Post your script, yet another time, because I'm not sure how it looks now ^_^


RE: Using a Single Crowbar on Multiple Doors - AGP - 09-22-2014

Spoiler below!
Code:
void OnStart()
{  
    for(int i=1; i<=4; ++i) AddUseItemCallback("crowbarondoors", "Crowbar_1", "Door_"+i, "UseCrowbarOnDoor", false);
    for(int i=1; i<=4; ++i) AddEntityCollideCallback("Joint_Door_"+i, "AreaBreak_"+i, "BreakDoor", true, 1);
}
    
void UseCrowbarOnDoor(string &in asItem, string &in asEntity)
{
    RemoveItem("asItem");
    PlaySoundAtEntity("", "player_crouch.snt", "Player", 0.05, false);
    AddTimer(asEntity, 0.2, "TimerPlaceCrowbar");

    SetLocalVarString("CrowbarDoor", asEntity);
}
    
void TimerPlaceCrowbar(string &in asTimer)
{
    SetEntityActive("Joint_"+asTimer, true);
    PlaySoundAtEntity("", "puzzle_place_jar.snt", asTimer, 0, false);
}
    
void BreakDoor(string &in asParent, string &in asChild, int alState)
{
    SetEntityActive(asParent, false);
  
    SetSwingDoorLocked(GetLocalVarString("CrowbarDoor"), false, false);
    SetSwingDoorClosed(GetLocalVarString("CrowbarDoor"), false, false);
    SetSwingDoorDisableAutoClose(GetLocalVarString("CrowbarDoor"), true);
    
    AddPropImpulse(GetLocalVarString("CrowbarDoor"), 0, 0, 3, "world");

    CreateParticleSystemAtEntity("", "ps_hit_wood.ps", "AreaEffect", false);
    PlaySoundAtEntity("", "break_wood_metal", "AreaEffect", 0, false);
    
    GiveSanityBoostSmall();
    
    PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
    
    AddTimer("", 0.1, "TimerPushDoor");

    GiveItem("crowbar", "Puzzle", "crowbar", "crowbar.tga", 1);
}

void TimerPushDoor(string &in asTimer)
{
        AddPropImpulse(GetLocalVarString("CrowbarDoor"), -4, 2, 1, "world");
        AddTimer("", 1.1, "TimerDoorCanClose");
}
    
void TimerDoorCanClose(string &in asTimer)
{
        SetSwingDoorDisableAutoClose(GetLocalVarString("CrowbarDoor"), false);
}




RE: Using a Single Crowbar on Multiple Doors - FlawlessHappiness - 09-22-2014

Oh! Haha, one thing at least.

In your script it says: RemoveItem("asItem");

You cannot have the two "" for it to work. It must be:

RemoveItem(asItem);


Ok, so now the problem is just that the crowbar doesn't work on the 4th door?
Please check that ALL names are correct.

Also, try adding AddDebugMessage("Test", false); to the UseCrowbarOnDoor function, and enable debug messages, just to see if the thing is actually calling.


RE: Using a Single Crowbar on Multiple Doors - AGP - 09-22-2014

The names are all correct. After removing the two quotation marks, only the first door will unlock.

Here's a download link for the .map and .hps files. This isn't my actual map; this was made to test out the script before adding it into everything.

https://www.mediafire.com/?vqek4b0w4vgcsu0


RE: Using a Single Crowbar on Multiple Doors - FlawlessHappiness - 09-22-2014

Ok! I found another thing!
Will look at your map when I get home.

You have 'true' in AddEntityCollideCallback("Joint_Door_"+i, "AreaBreak_"+i, "BreakDoor", true, 1);

When you have true here, it will delete the Collide callback after it has been called once...
And then it makes sense it's only working once..


RE: Using a Single Crowbar on Multiple Doors - AGP - 09-22-2014

I changed it to false, but the other three doors are still no longer working.


RE: Using a Single Crowbar on Multiple Doors - Mudbill - 09-22-2014

I suggest renaming your crowbar item to just "crowbar" like you have it within GiveItem, and then also rename "Crowbar_1" in the callback to just "crowbar" in order to keep it the same.

This is because the crowbar you pick up (which is named Crowbar_1) will be possible to use to on any of the doors, but after using it, you're given a new crowbar item which is NOT named Crowbar_1, therefore it won't work on the doors. Make those names the same and it should, unless there's something else preventing it.


RE: Using a Single Crowbar on Multiple Doors - AGP - 09-22-2014

That worked! All four doors now open!

There is still the bug with the sound and particle effects, or lack of particle effects. But the doors open!! Hooray! XD