Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with script involving making trees appear/disappear
Cakeslam Offline
Junior Member

Posts: 4
Threads: 1
Joined: Sep 2012
Reputation: 0
#1
Need help with script involving making trees appear/disappear

Edit: Wrong section, sorry! Moved to Development Support.

Ok so for part of my custom story the player is in the forest. I'm trying to set up a script so that when the player interacts with a locked door they hear a scream and then some trees appear to block the previous path while some trees disappear to reveal a new path. I've used the SetEntityActive function but something's not right.

Also, I want the message "It's locked" to appear when the player tries to open the door but that's not working either, so any help with that would be appreciated as well.

Here's the script:

void OnStart()
{
    GiveItemFromFile("lantern", "lantern.ent");
        SetPlayerLampOil(50.0f);
    AddUseItemCallback("", "gate_key", "garden_gate", "unlock_garden_gate", true);
    SetEntityPlayerInteractCallback("garden_gate", "garden_gate_locked", false);
    SetEntityPlayerInteractCallback("garden_gate", "tree_door", true);
    SetEntityPlayerInteractCallback("garden_gate", "forest_scream", true);
    AddEntityCollideCallback("Player", "lantern_message", "lantern_message", true, 1);
}

void lantern_message(string &in asChild, string &in asParent, int alState)
{
    SetMessage("Messages", "lantern_message", 0);
}

void tree_door(string &in asParent, string &in asChild, int alState)
{
    SetEntityActive("tree_door_1", false);
    SetEntityActive("tree_door_2", false);
    SetEntityActive("tree_door_3", true);
    SetEntityActive("tree_door_4", true);
}

void garden_gate_locked(string &in Entity) // Needs to be fixed
{
    if(GetSwingDoorLocked("garden_gate") == true)
    {
        SetMessage("Messages", "locked", 0);
    }
}

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

void forest_scream(string &in Entity)
{
    PlaySoundAtEntity("", "15_prisoner_scream.snt", "gate_key", 0, false);
    GiveSanityDamage(10.0f, true);
}

I only started scripting yesterday so there are probably quite a few errors in that script. Any help with cleaning it up in general would be greatly appreciated! Big Grin
(This post was last modified: 09-03-2012, 05:11 PM by Cakeslam.)
09-03-2012, 05:05 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#2
RE: Need help with script involving making trees appear/disappear

First, you need to make the trees into entities, and go you Edit>User Defined Variables. Change Type to Object and SubType to Static. Save and put those in your story, as well as fix the names. The SetEntityActive doesn't work for static objects.

Then in your script, change

void tree_door(string &in asParent, string &in asChild, int alState)


to

void tree_door(string &in asEntity)
09-03-2012, 05:39 PM
Find
lllDash Offline
Member

Posts: 108
Threads: 12
Joined: Apr 2012
Reputation: 3
#3
RE: Need help with script involving making trees appear/disappear

Unfortunately static objects can't be disabled through the use of scripting, only entities have that feature (well, most of them) and trees are categorized as static objects. There is a way to convert an object to an entity and that could possibly be done using a model editor that is compatible with Amnesia, but I don't know how.
But people have done it before. Sorry. Sad
(This post was last modified: 09-07-2012, 02:22 PM by lllDash.)
09-03-2012, 05:58 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#4
RE: Need help with script involving making trees appear/disappear

as for

void garden_gate_locked(string &in Entity)

do

void garden_gate_locked(string &in asEntity)

Also make sure the .lang file matches the entry and category.

(09-03-2012, 05:58 PM)lllDash Wrote: Unfortunately static objects can't be disabled through the use of scripting, only entities have that feature (well, most of them) and trees are categorized as static objects. There is a way to convert an object to an entity and that could possibly be done using a model editor that is compatible with Amnesia, but I don't know how.
But people have done it before. Sorry. Sad

I can help you with the message though. Smile
SetMessage("Messages", "locked", 0);

So far everything looks fine, just change the 0 to 5 or depending on how many seconds you want the message to display for. And as for: void garden_gate_locked(string &in Entity), try (string &in item) instead.
Setting it to 0 won't make it not work. Setting it to 0 will allow the game to calculate the message time depending on the size of the message, so that's fine.

And you gave the wrong syntax for that function.
(This post was last modified: 09-03-2012, 06:02 PM by Statyk.)
09-03-2012, 05:58 PM
Find
Cakeslam Offline
Junior Member

Posts: 4
Threads: 1
Joined: Sep 2012
Reputation: 0
#5
RE: Need help with script involving making trees appear/disappear

Thanks for the help!

What I did to get around the issue of not being able to disable static objects is use the fallen tree entity. I then checked the StaticPhysics box because they were moving about erratically. Maybe that's part of the problem. I'll try the solution that Statyk posted and tweak those bits of script and see what happens.

Hmm that didn't work Sad Are there any other specific options I have to select in the model editor other than the Type and SubType boxes, or in the level editor itself? The script for the locked door still doesn't work either, and I've made sure it matches what's in the .lang file.
(This post was last modified: 09-03-2012, 06:44 PM by Cakeslam.)
09-03-2012, 06:13 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#6
RE: Need help with script involving making trees appear/disappear

Go to the Entity tab of the garden_gate and put in the PlayerInteractCallback, "interactgate_func" (no quotations) and change your script to this. As well, make sure the internal name of the gate IS "garden_gate":

void OnStart()
{
    GiveItemFromFile("lantern", "lantern.ent");
        SetPlayerLampOil(50.0f);
    AddUseItemCallback("", "gate_key", "garden_gate", "unlock_garden_gate", true);
    AddEntityCollideCallback("Player", "lantern_message", "lantern_message", true, 1);
}

///GATE DOOR FUNCTIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void interactgate_func(string &in asEntity)
{
    if(GetSwingDoorLocked("garden_gate") == true)
    {
    SetMessage("Messages", "locked", 3);
    AddTimer("", 4, "tree_func"); //Adjust the time here accordingly
    }
}
void tree_func(string &in asTimer)
{
    PlaySoundAtEntity("", "15_prisoner_scream.snt", "gate_key", 0, false);
    GiveSanityDamage(10.0f, true);
    SetEntityActive("tree_door_1", false);
    SetEntityActive("tree_door_2", false);
    SetEntityActive("tree_door_3", true);
    SetEntityActive("tree_door_4", true);
}

///GATE DOOR FUNCTIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


void lantern_message(string &in asChild, string &in asParent, int alState)
{
    SetMessage("Messages", "lantern_message", 0);
}


void unlock_garden_gate(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked(asEntity, false, true);
    PlaySoundAtEntity("", "unlock_door", asEntity, 0, false);
    RemoveItem(asItem);
}
09-03-2012, 06:59 PM
Find
Cakeslam Offline
Junior Member

Posts: 4
Threads: 1
Joined: Sep 2012
Reputation: 0
#7
RE: Need help with script involving making trees appear/disappear

Thanks for all the help, I really appreciate it, but it still isn't working. When I use your script I don't even get the scream sound or the sanity loss when I interact with the door, which is frustrating because everything seems to be in order (even to my inexperienced eyes!) Any other ideas? I feel like I'm starting to become a pain haha Blush
09-03-2012, 07:15 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#8
RE: Need help with script involving making trees appear/disappear

Let's just try getting rid of the if function as it almost seems unnecessary to something linear...

///GATE DOOR FUNCTIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void interactgate_func(string &in asEntity)
{
    SetMessage("Messages", "locked", 3);
    AddTimer("", 4, "tree_func"); //Adjust the time here accordingly
}
void tree_func(string &in asTimer)
{
    PlaySoundAtEntity("", "15_prisoner_scream.snt", "gate_key", 0, false);
    GiveSanityDamage(10.0f, true);
    SetEntityActive("tree_door_1", false);
    SetEntityActive("tree_door_2", false);
    SetEntityActive("tree_door_3", true);
    SetEntityActive("tree_door_4", true);
}

///GATE DOOR FUNCTIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
09-03-2012, 07:24 PM
Find
Cakeslam Offline
Junior Member

Posts: 4
Threads: 1
Joined: Sep 2012
Reputation: 0
#9
RE: Need help with script involving making trees appear/disappear

Nope, still the same problem. I might just leave that bit for now and come back to it later.
09-03-2012, 07:53 PM
Find
lllDash Offline
Member

Posts: 108
Threads: 12
Joined: Apr 2012
Reputation: 3
#10
RE: Need help with script involving making trees appear/disappear

(09-03-2012, 05:58 PM)Statyk Wrote: Setting it to 0 won't make it not work. Setting it to 0 will allow the game to calculate the message time depending on the size of the message, so that's fine.

And you gave the wrong syntax for that function.
Oops, my bad. Confused That's the last time I try to help someone on a forum after a long tiresome day of work. disregard my last post. Blush
09-07-2012, 02:21 PM
Find




Users browsing this thread: 1 Guest(s)