Frictional Games Forum (read-only)
What's wrong with my script? - 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: What's wrong with my script? (/thread-24858.html)



What's wrong with my script? - physcostealth - 03-16-2014

This is just a test area. But I want the player to take a key, open a closet with it, grab a crowbar in the closet (which in turn will also make an area active between the player and a door), and when the player walks into the area thunder will crash and the player will look at a nearby window. Then he can use to crowbar to open the door. Everything works out well up till the area part; it seems like the area is always inactive as when I grab the crowbar and walk into the area, nothing happens. The door still opens when I use the crowbar on it, however.

Code:
void OnStart()
{
    AddUseItemCallback("crowbar.ent", "crowbar", "mansion_1", "unlockdoor", false);
    SetSwingDoorLocked("mansion_1", true, true);
    SetSwingDoorLocked("cabinet", true, true);
    AddUseItemCallback("key_tomb.ent", "keycloset", "cabinet", "unlockcloset", false);
    SetEntityActive("thunder", false);
    AddEntityCollideCallback("Player", "thunder", "lookatwindow", true, 1);
}

//To unlock the closet door, grab the key and click on the door.///

void unlockcloset(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("cabinet", false, true);
    PlaySoundAtEntity("locker", "07_pick_lock.ogg", "Player", 0.1f, true);
}

//To unlock the mansion door, grab the crowbar and click the door.///

void unlockdoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("mansion_1", false, true);
    PlayMusic("the_patronus_light.ogg", true, 1.0, 1.0, 1, false);
    PlaySoundAtEntity("lock", "07_pick_lock.ogg", "Player", 0.1f, true);
}

//Before you walk to the mansion door to unlock it, thunder will crash when you walk into the area.//

void lookatwindow(string &in asParent, string &in asChild, int alState)
{
    StartPlayerLookAt("windowblue", 1.0f, 1.0f, "timerset");
    PlaySoundAtEntity("thundercrash", "thunder_crash01.ogg", "windowblue", 0.0f, true);
    if(HasItem("crowbar"))
        {
            SetEntityActive("thunder", true);
        }
    AddTimer("timerthunder", 3.0f, "timerset");
}

//The timer starts when player walks into thunder area.//

void timerset(string &in asTimer)
{
    StopPlayerLookAt();
}

Thanks for your help!


RE: What's wrong with my script? - Mudbill - 03-16-2014

What happens here is that you have the check for the collision from the start. This check it also removed after first execution, therefore it does not happen again if you've already stepped into that area before you had the crowbar, even if you do have it later.

One thing you can do instead of checking for the playing having the crowbar, is to just add the check after you pick it up. Leave the area active and give the collide callback to the PickUp function of the crowbar, and it will only happen after you pick it up.

Just wanna point out that you do not need ".ent" in your callback internal name. That name has nothing to do with any files. I don't think it affects it much but you never know.

PS: This thread will probably be moved to Development Support soon.

Wha-cha! Ninja!


RE: What's wrong with my script? - plutomaniac - 03-17-2014

http://www.frictionalgames.com/forum/thread-24849-post-287559.html#pid287559

Stop posting whatever editor "problem" you have at the Technical Support section. This is the 5th thread I have moved so far.

Also, have one thread for all your issues during the same period of time.


RE: What's wrong with my script? - physcostealth - 03-22-2014

I tried adding an 'OnPickup' function to the script... now the game just crashes and gives me an expected data type error. Ya never know, it might be stupidly obvious.

Code:
void OnStart()
{
    AddUseItemCallback("crowbar.ent", "crowbar", "mansion_1", "unlockdoor", false);
    SetSwingDoorLocked("mansion_1", true, true);
    SetSwingDoorLocked("cabinet", true, true);
    AddUseItemCallback("key_tomb.ent", "keycloset", "cabinet", "unlockcloset", false);
    SetEntityActive("thunderarea", false);
    SetEntityCallbackFunc("", "pickupcrowbar");
}

//To unlock the closet door, grab the key and click on the door.///

void unlockcloset(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("cabinet", false, true);
    PlaySoundAtEntity("locker", "07_pick_lock.ogg", "Player", 0.1f, true);
}

//To unlock the mansion door, grab the crowbar and click the door.///

void unlockdoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("mansion_1", false, true);
    PlayMusic("the_patronus_light.ogg", true, 1.0, 1.0, 1, false);
    PlaySoundAtEntity("lock", "07_pick_lock.ogg", "Player", 0.1f, true);
}

//Before you walk to the mansion door to unlock it, thunder will crash when you walk into the area.//

void pickupcrowbar("crowbar", "OnPickup")
{
    SetEntityActive("thunderarea", true);
    AddEntityCollideCallback("Player", "thunderarea", "lookatwindow", true, 1);
}

void lookatwindow(string &in asParent, string &in asChild, int alState)
{
    StartPlayerLookAt("windowblue", 1.0f, 1.0f, "timer");
    PlaySoundAtEntity("", "thunder_crash01.ogg", "windowblue", 2.0f, true);
}

void timer()
{
    StopPlayerLookAt();
}



RE: What's wrong with my script? - PutraenusAlivius - 03-22-2014

(1) SetEntityCallbackFunc("crowbar", "pickupcrowbar");
(2) void pickupcrowbar(string &in asEntity, string &in type)

You got two things wrong.
First, you didn't filled in the first argument of the SetEntityCallbackFunc. (1)
Second, you have the wrong callback function to SECF. (2)