I've got a bit of a scripting problem (or so it seems). What I want to have happen is the player picks up a key, walks into an area, and (since they have a key) the monster starts beaking down a door behind the player.
When I tested it, it didn't seem to work. Here's the whole .HPS file (it's not very big):
1) Delete the map cache file (Close Amnesia before doing so)
2) Check the naming of your areas and monsters. It's likely a spelling error if not the map cache.
3) Remove == true from your if statement. Your expression is basically saying if(true == true). I don't think it causes any problems but there's no harm in slimming down code -- just say if(HasItem("itemhere")) //code here
Isn't it saying: If you have the key the enemy gets activated. Because if you don't have the key the "if statement" isn't true which means the enemy won't spawn.
Right?
EDIT: Nvm I see what you meant now
(This post was last modified: 02-06-2012, 04:38 AM by Ninami.)
All you do is locate "/custom_stories/(Your storyname here)/maps" and then IF you have a file called "something".cache then delete it.
If that's not the problem then I think there's something wrong with either the names or your level editor, because I have a very similar event on my own map and it works perfectly (with almost the exact script you use).
The only other thing I can think of is, since you have "true" so that the area gets removed after you enter it the first time, I guess you maybe walk through it first WITHOUT key, and THAT'S where the function uses the "if statement" and can't find the key in your inventory (because you haven't picked it up yet) and when you enter the area a SECOND time, WITH the key, the area is gone because you already entered it once before.
Does that sound likely?
It that's the problem then I suggest you do what I did.
Just use SetEntityCallbackFunc(string& asName, string& asCallback); to your key and when you pick it up the Area will spawn SetEntityActive("Area_Name"). That way you won't activate the area when you walk through it when you don't have the key. And when you find the key and pick it up, they area spawns and the "if statement" will work.
(This post was last modified: 02-06-2012, 06:28 AM by Ninami.)
void OnStart()
{
AddEntityCollideCallback("Player", "CollideArea", "MonsterScare", false, 1); // This will activate every time the player enters the area.
}
void MonsterScare(string &in asParent, string &in asChild, int alState)
{
if(HasItem("Key")) // Checks if the player has the key
{
// Monsterstuff goes here. SetEntityActive and whatnot.
SetEntityActive("CollideArea", false);// This gets rid of the area, so the script will only run once.
}
// If the player doesn't have the key, nothing happens.
}