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
Script Help Make an item appear after smashing plates?
Dominic0904 Offline
Member

Posts: 63
Threads: 14
Joined: Apr 2011
Reputation: 0
#1
Make an item appear after smashing plates?

Hey everybody,

Now usually I am ok with trying to figure out scripting for myself when it comes to Amnesia. But I am struggling to figure out how to do this particular task.

Now here's what I would want to happen. The player enters a room which is full of smashed plates besides a few. A note is left on a table with a riddle and the riddle basically says to smash all the plates to complete the puzzle. After the player smashes the remaining plates a key appears on the table.

Where I am unsure is how could I make sure the key appears after all the plates have been smashed?

I know the plates need to have a unique name such as "SmashPlate_01" and that a if statement would be needed to check the health of the plates and if it sees that all the plates have a health of 0 then it would make the key appear. But I am unsure on how to write that.

I believe the function "GetPropHealth" would have something to do with the matter but the rest I am unsure about.

If I could get some help regarding this it would be very much appreciated and help me learn more about scripting.

Thank you.
04-18-2013, 04:52 PM
Find
Yare Offline
Junior Member

Posts: 22
Threads: 2
Joined: Mar 2013
Reputation: 0
#2
RE: Make an item appear after smashing plates?

Firstly I also though of GetPropHealth, but then something else came to my mind. I think you will only need:
SetEntityCallbackFunc(string& asName, string& asCallback);
It has various types of interaction: “OnPickup”, “Break”, “OnIgnite”. So far I only tried "OnIgnite", but I think "Break" should work well. So you add this Callback for every plate that should be broken. The function for every of them should be like this:

void FUNCTION(string &in asEntity, string &in type)
{
    if(type == "Break")
        {
            AddLocalVarInt("VAR NAME", 1);
            if (GetLocalVarInt("VAR NAME") == x) SetEntityActive("KEY NAME", true);
        }
}

Obviously, don't forget about declaring variable first. "x" is the number of plates that should be broken. Try this and tell me if that works or not.
04-18-2013, 05:14 PM
Find
Dominic0904 Offline
Member

Posts: 63
Threads: 14
Joined: Apr 2011
Reputation: 0
#3
RE: Make an item appear after smashing plates?

Ok, this is what I got:

Quote:void OnStart()
{
SetEntityCallbackFunc("BrokenPlates", "Break");
}



void BrokenPlates(string &in asEntity, string &in type)
{
if(type == "Break")
{
AddLocalVarInt("non_broken_*", 1);
if (GetLocalVarInt("non_broken_*") == 5) SetEntityActive("CellarKey_01", true);
}
}


I guess the variable was the name of the plates that needed to be broken? Sorry I'm not that experienced with the more advanced stuff. The map loads fine, but after breaking all the plates with the name non_broken_* (the * is so that it includes all the plates with the same name and the number at the end as well.)
(This post was last modified: 04-18-2013, 05:37 PM by Dominic0904.)
04-18-2013, 05:34 PM
Find
Yare Offline
Junior Member

Posts: 22
Threads: 2
Joined: Mar 2013
Reputation: 0
#4
RE: Make an item appear after smashing plates?

Huh, you mixed up quite many things Tongue
Here is how it should look like:

void OnStart()
{
SetLocalVarInt("BrokenPlates", 0);
SetEntityCallbackFunc("non_broken_*", "Break");
}



void Break(string &in asEntity, string &in type)
{
if(type == "Break")
{
AddLocalVarInt("BrokenPlates", 1);
if (GetLocalVarInt("BrokenPlates") == 5) SetEntityActive("CellarKey_01", true);
}
}

BrokenPlates - the name of variable (I guess), so it is firstly declared after "void OnStart()"
non_broken_* - it refers to entities, that is your plates to break, so it comes first in "SetEntityCallbackFunc"
Break - the name of the funtcion

Also, I am not sure if asterix (*) shall go like this "non_broken_*", or like this "non_broken_"* (I have never used that before). If the first way doesn't work, try the second one.
04-18-2013, 05:58 PM
Find
Dominic0904 Offline
Member

Posts: 63
Threads: 14
Joined: Apr 2011
Reputation: 0
#5
RE: Make an item appear after smashing plates?

(04-18-2013, 05:58 PM)Yare Wrote: Huh, you mixed up quite many things Tongue
Here is how it should look like:

void OnStart()
{
SetLocalVarInt("BrokenPlates", 0);
SetEntityCallbackFunc("non_broken_*", "Break");
}



void Break(string &in asEntity, string &in type)
{
if(type == "Break")
{
AddLocalVarInt("BrokenPlates", 1);
if (GetLocalVarInt("BrokenPlates") == 5) SetEntityActive("CellarKey_01", true);
}
}

BrokenPlates - the name of variable (I guess), so it is firstly declared after "void OnStart()"
non_broken_* - it refers to entities, that is your plates to break, so it comes first in "SetEntityCallbackFunc"
Break - the name of the funtcion

Also, I am not sure if asterix (*) shall go like this "non_broken_*", or like this "non_broken_"* (I have never used that before). If the first way doesn't work, try the second one.

Yeah the code you quoted worked Smile Thanks a bunch! Now I just need to break it down and learn what certain things do. Like the whole local variable thing confuses me a lot :/
04-18-2013, 06:32 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#6
RE: Make an item appear after smashing plates?

(04-18-2013, 05:58 PM)Yare Wrote: Huh, you mixed up quite many things Tongue
Here is how it should look like:

void OnStart()
{
SetLocalVarInt("BrokenPlates", 0);
SetEntityCallbackFunc("non_broken_*", "Break");
}



void Break(string &in asEntity, string &in type)
{
if(type == "Break")
{
AddLocalVarInt("BrokenPlates", 1);
if (GetLocalVarInt("BrokenPlates") == 5) SetEntityActive("CellarKey_01", true);
}
}

BrokenPlates - the name of variable (I guess), so it is firstly declared after "void OnStart()"
non_broken_* - it refers to entities, that is your plates to break, so it comes first in "SetEntityCallbackFunc"
Break - the name of the funtcion

Also, I am not sure if asterix (*) shall go like this "non_broken_*", or like this "non_broken_"* (I have never used that before). If the first way doesn't work, try the second one.
Don't worry, you used the asterisk the right way.
It's like if all things that have the name "non_broken_(number)" will do the same thing.

"Veni, vidi, vici."
"I came, I saw, I conquered."
04-19-2013, 10:06 AM
Find
xxxxxxxxxxxxxxxx Away
Posting Freak

Posts: 935
Threads: 0
Joined: Jun 2012
Reputation: 54
#7
RE: Make an item appear after smashing plates?

Quote: Now I just need to break it down and learn what certain things do. Like the whole local variable thing confuses me a lot :/
Well a local variable is just that - a variable. Big Grin It has a name and a value - the name always stays the same, but the value can change. So basically it let's the script "remember" a value for later use.

One of it's most basic uses is counting things. So in this case, you create a variable that shall count the number of broken plates:
VarInt means that the variable is an integer, or a whole number. (like 1,2,5...), BrokenPlates is the name and 0 is the start value.

The if statement later on then simply uses AddLocalVarInt to add 1 to the variable every time a plate is broken. It also says that if the number of broken plates is 5 (which means, the variable BrokenPlates has a value of 5), the key shall appear. And that's pretty much the whole magic behind this Smile
(This post was last modified: 04-19-2013, 10:16 AM by xxxxxxxxxxxxxxxx.)
04-19-2013, 10:16 AM
Find




Users browsing this thread: 1 Guest(s)