Frictional Games Forum (read-only)
Activating a script area - 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: Activating a script area (/thread-16374.html)

Pages: 1 2


Activating a script area - ApeCake - 06-21-2012

Hello again. So I thought about something very simple, a script area that activates upon a key pickup. When I walk into the script area nothing happens, but after I picked up the key and walk in it it does something (in this case push the player back) (I had in mind delete the script area after one use). However, after I picked up the key and walked in the area nothing happened. Here's my script. The script area is called "pusharea" and the key "tocarnellroomkey". The area is not active in the beginning obviously.



void OnStart()

{
AddEntityCollideCallback("Player", "pusharea", "Push", false, 1);
SetEntityCallbackFunc("tocarnellroomkey", "OnPickupKey");
}


//The push script
void Push(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
AddPlayerBodyForce(0, 0, -2000, false);
}

//The setting-the-area-active script
void OnPickupKey(string &in asEntity, string &in type)
{
SetEntityActive("pusharea", true);
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false);
}

So my guess is that SetEntityActive doesn't work on script areas? Can anyone improve this or knows what I did wrong? Thanks in advance.

EDIT: If I do the code in a code window, it gets messed up.


RE: Activating a script area - MaZiCUT - 06-21-2012

(06-21-2012, 04:58 PM)ApeCake Wrote: Hello again. So I thought about something very simple, a script area that activates upon a key pickup. When I walk into the script area nothing happens, but after I picked up the key and walk in it it does something (in this case push the player back) (I had in mind delete the script area after one use). However, after I picked up the key and walked in the area nothing happened. Here's my script. The script area is called "pusharea" and the key "tocarnellroomkey". The area is not active in the beginning obviously.



void OnStart()

{
AddEntityCollideCallback("Player", "pusharea", "Push", false, 1);
SetEntityCallbackFunc("tocarnellroomkey", "OnPickupKey");
}


//The push script
void Push(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
AddPlayerBodyForce(0, 0, -2000, false);
}

//The setting-the-area-active script
void OnPickupKey(string &in asEntity, string &in type)
{
SetEntityActive("pusharea", true);
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false);
}

So my guess is that SetEntityActive doesn't work on script areas? Can anyone improve this or knows what I did wrong? Thanks in advance.

EDIT: If I do the code in a code window, it gets messed up.
SetEntityActive works on script areas, i don't really understand what you are trying to achieve but i guess you want a script area to be set to true/false when you collide with another script area?


RE: Activating a script area - Cruzore - 06-21-2012

replace AddEntityCollideCallback("Player", "pusharea", "Push", false, 1);
to under the OnPickupKey function, and it should work.

Edit: and delete the setentityactive for this one, and set it active in the level editor


RE: Activating a script area - ApeCake - 06-21-2012

(06-21-2012, 05:04 PM)CrazyArts Wrote: SetEntityActive works on script areas, i don't really understand what you are trying to achieve but i guess you want a script area to be set to true/false when you collide with another script area?
Close, I want the script area to be true when a key is picked up.


RE: Activating a script area - Adny - 06-21-2012

Yes, script areas can in fact be set active/inactive. Quick question though, when "OnPickupKey" is called, does the PlaySoundAtEntity work? If the sound doesn't play, then what I'm about to show you will most likely work; if it does play and the script area doesn't activate, it is a spelling error you made (it's hard to tell because I can't see your level editor Tongue)

Anyways, try replacing the "OnPickupKey" function with this:

void OnPickupKey(string &in asEntity, string &in asType)
{
if(asType == "OnPickup") //I'm pretty sure this is what needs to be specified for this function
{
SetEntityActive("pusharea", true);
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false);
}
}


RE: Activating a script area - Cruzore - 06-21-2012

Nevermind, the real problem is:
the function has to be called OnPickup. So it's SetEntityCallbackFunc("tocarnellroomkey", "OnPickup");
and void OnPickup(string &in asEntity, string &in asType)
also, like andyrockin123 said, you have to use a if:
if(asEntity == "tocarnellroomkey")
{
stuff
}


RE: Activating a script area - ApeCake - 06-21-2012

(06-21-2012, 05:09 PM)andyrockin123 Wrote: Yes, script areas can in fact be set active/inactive. Quick question though, when "OnPickupKey" is called, does the PlaySoundAtEntity work? If the sound doesn't play, then what I'm about to show you will most likely work; if it does play and the script area doesn't activate, it is a spelling error you made (it's hard to tell because I can't see your level editor Tongue)

Anyways, try replacing the "OnPickupKey" function with this:

void OnPickupKey(string &in asEntity, string &in asType)
{
if(asType == "OnPickup") //I'm pretty sure this is what needs to be specified for this function
{
SetEntityActive("pusharea", true);
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false);
}
}
Thank you, however the sound actually did play before.

And FasthunteR, it didn't work unfortunately


Let me try out your new one... you guys are posting solutions too fast! Tongue


RE: Activating a script area - Cruzore - 06-21-2012

Or maybe i'm wrong, i hate that type of callback Smile Just try it out, maybe it works


RE: Activating a script area - Adny - 06-21-2012

An alternative that I see is vastly underused is using the level editor to reduce such scripting complications; if you select any (interactable) entity, in the 2nd tab there is a box labeled "PlayerInteractCallback", just type in the name of your function, and use the syntax:
"string &in asEntity"

So the OP can select his key in the editor, type in OnPickupKey for the function then write:

void OnPickupKey(string &in asEntity)
{

SetEntityActive("pusharea", true);
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false);
}


Just something I thought I'd share since I don't see it used too often, and it's pretty useful for reducing script clutter.


RE: Activating a script area - ApeCake - 06-21-2012

(06-21-2012, 05:23 PM)andyrockin123 Wrote: An alternative that I see is vastly underused is using the level editor to reduce such scripting complications; if you select any (interactable) entity, in the 2nd tab there is a box labeled "PlayerInteractCallback", just type in the name of your function, and use the syntax:
"string &in asEntity"

So the OP can select his key in the editor, type in OnPickupKey for the function then write:

void OnPickupKey(string &in asEntity)
{

SetEntityActive("pusharea", true);
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false);
}


Just something I thought I'd share since I don't see it used too often, and it's pretty useful for reducing script clutter.
Doesn't seem to be working ;_; I have no idea what to do now. I must've made a stupid mistake somewhere or something, however there are no errors...