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: if HasItem, spawn monster
Ghostblade Offline
Junior Member

Posts: 3
Threads: 1
Joined: Feb 2012
Reputation: 0
#1
need help: if HasItem, spawn monster

Hey guys.

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):

Spoiler below!

void OnStart()
{
SetEntityCallbackFunc("keytonextstage", "OnPickup");

AddUseItemCallback("", "keytostorageroomonedoor", "storageroomonedoor", "KeyOnDoorStorageRoomOneDoor", true);

AddEntityCollideCallback("Player", "furiousenemyspawn", "collidefuriousenemyspawn", true, 1);
}

void collidefuriousenemyspawn(string &in asParent, string &in asChild, int alState)
{
if(HasItem("keytostorageroomonedoor") == true)
{
SetEntityActive("furious_enemy", true);
ShowEnemyPlayerPosition("furious_enemy");
}
}


//void OnPickup(string &in asEntity, string &in type)
//{
// SetEntityActive("furious_enemy", true);
// ShowEnemyPlayerPosition("furious_enemy");
//}

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

void OnEnter()
{

}

void OnLeave()
{

}


The bolded parts are the key bits.

Is there any reason why this might not be working?
02-06-2012, 04:16 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: need help: if HasItem, spawn monster

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

02-06-2012, 04:30 AM
Find
Ninami Offline
Member

Posts: 59
Threads: 6
Joined: Feb 2012
Reputation: 2
#3
RE: need help: if HasItem, spawn monster

Don't know if I agree with 3).

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.)
02-06-2012, 04:37 AM
Find
Ghostblade Offline
Junior Member

Posts: 3
Threads: 1
Joined: Feb 2012
Reputation: 0
#4
RE: need help: if HasItem, spawn monster

1) Alright, so how do I delete the map cache? I assume I do it in code, but I'm not sure what I type.

2) The names are right, so no problem there.

3) I remember looking at a piece of code that had the "== true" bit in it, so I assumed that's what it needed to function properly.
(This post was last modified: 02-06-2012, 05:40 AM by Ghostblade.)
02-06-2012, 05:38 AM
Find
Ninami Offline
Member

Posts: 59
Threads: 6
Joined: Feb 2012
Reputation: 2
#5
RE: need help: if HasItem, spawn monster

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.)
02-06-2012, 06:03 AM
Find
Obliviator27 Offline
Posting Freak

Posts: 792
Threads: 10
Joined: Jul 2011
Reputation: 66
#6
RE: need help: if HasItem, spawn monster

Or you could make it really easy.
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.
}

02-06-2012, 07:56 AM
Find
Ninami Offline
Member

Posts: 59
Threads: 6
Joined: Feb 2012
Reputation: 2
#7
RE: need help: if HasItem, spawn monster

Yeah doesn't really matter how you do it, as long as the area doesn't get removed when used once.
02-06-2012, 04:50 PM
Find
Ghostblade Offline
Junior Member

Posts: 3
Threads: 1
Joined: Feb 2012
Reputation: 0
#8
RE: need help: if HasItem, spawn monster

Sorry for the late reply >.<

I tried out Obliviator27's code and it worked like a charm. Thanks a lot :]
02-19-2012, 04:12 AM
Find




Users browsing this thread: 4 Guest(s)