Frictional Games Forum (read-only)

Full Version: Checking if the player is NOT inside an area?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey. I'm trying to check wheter a player is throwing an item over an entity than just moving along with the object touching the entity, therefore I created an area and a check to see if the player is OUTSIDE the area and the item collides with the entity, means he threw it, but it didn't work.

Code:
if( (mon_health > 0) && (GetEntitiesCollide("Player", "Area_Throw") == false)  )

Any suggestions?
Well, whenever I used the GetEntitiesCollide(,) function, it didn't seem to like using the "==false" part. This is how I'd do it.

Create a AddEntityCollideCallback("Player" , "Area_Throw" , "Collide" , false , 0) in your OnStart().

Then, in your "void Collide(string&in asParent , string&in asChild , int alState)", make it so that every time it is called, a local variable is set to the alState, like this:
SetLocalVarInt("CollideState" , alState);

Finally, use this Local variable to determine whether the player is colliding with the area, like this:
if( (mon_health > 0) && (GetLocalVarInt("CollideState") == -1) )

Overall, the script should go like this.
Spoiler below!

PHP Code:
void OnStart() {

AddEntityCollideCallback("Player" "Area_Throw" "Collide" false 0);
SetLocalVarInt("CollideState" , -1); // Sets the variable so by default the alState is -1

}
void Collide(string&in asParent string&in asChild int alState) {

SetLocalVarInt("CollideState" alState); // Sets the Local variable to the alState

}
void YourFunction(YourFunction) {
if( (
mon_health 0) && (GetLocalVarInt("CollideState") == -1) ) { // If the player has left area
// Do stuff here!
}



Or you can try this:
Code:
if( (mon_health > 0) && GetEntitiesCollide("Player", "Area_Throw") ) {// Do nothing }
else if(mon_health > 0){
// Do stuff here!

}

I don't like doing it this way because I don't really like the GetEntitiesCollide Function, but it should work.
About the first one, I think it won't work as for the fact that if the player does not collide with that area in the first place, the Collide callback won't even be called and the variable won't be set or modified.

I'll check out them both when I'll be able to though, thanks!
(04-12-2012, 06:22 PM)ClayPigeon Wrote: [ -> ]About the first one, I think it won't work as for the fact that if the player does not collide with that area in the first place, the Collide callback won't even be called and the variable won't be set or modified.

I'll check out them both when I'll be able to though, thanks!
Yeah, I forgot to say that I put a SetLocalVarInt("", -1); in OnStart() {} just to initiate it to the -1 state.
If you have a look in the code in the spoiler I put it there, I just forgot to say. It will work if you include that, and the second one should work too, I usually do it the first way just because I'm more familiar with the AddEntityCollideCallback, but if the other way works I might start using that way myself

(04-12-2012, 06:29 PM)DRedshot Wrote: [ -> ]
(04-12-2012, 06:22 PM)ClayPigeon Wrote: [ -> ]About the first one, I think it won't work as for the fact that if the player does not collide with that area in the first place, the Collide callback won't even be called and the variable won't be set or modified.

I'll check out them both when I'll be able to though, thanks!
Yeah, I forgot to say that I put a SetLocalVarInt("", -1); in OnStart() {} just to initiate it to the -1 state.
If you have a look in the code in the spoiler I put it there, I just forgot to say. It will work if you include that, and the second one should work too, I usually do it the first way just because I'm more familiar with the AddEntityCollideCallback, but if the other way works I might start using that way myself
Oh I haven't noticed the part on OnStart, silly me!
I'll check the second method for you mate Smile
Thanks for the help!
(04-12-2012, 06:55 PM)ClayPigeon Wrote: [ -> ]Oh I haven't noticed the part on OnStart, silly me!
I'll check the second method for you mate Smile
Thanks for the help!
Your Welcome, I just realised something though. What happens if the player throws the object from inside the area? Or manages to reach in and hit it from outside the area?

Maybe a better way to do this would be like this:

void OnStart{ AddEntityCollideCallback(Stuff-Goes-Here!); }

void itemCollidesEntity(string &in asItem , string &in asEntity , int alState) {
if( GetPropIsInteractedWith(asItem) && (mon_health > 0) ){
// Player Swung item at Entity
}
else if(mon_health > 0){
// Player Threw item at Entity
}
}

Just a suggestion Tongue

I would be more interested in what happens when the condition is met than the condition itself. Just from the condition itself, i feel this can be accomplished without the need of compensating through scripting.
(04-12-2012, 07:48 PM)DRedshot Wrote: [ -> ]
(04-12-2012, 06:55 PM)ClayPigeon Wrote: [ -> ]Oh I haven't noticed the part on OnStart, silly me!
I'll check the second method for you mate Smile
Thanks for the help!
Your Welcome, I just realised something though. What happens if the player throws the object from inside the area? Or manages to reach in and hit it from outside the area?

Maybe a better way to do this would be like this:

void OnStart{ AddEntityCollideCallback(Stuff-Goes-Here!); }

void itemCollidesEntity(string &in asItem , string &in asEntity , int alState) {
if( GetPropIsInteractedWith(asItem) && (mon_health > 0) ){
// Player Swung item at Entity
}
else if(mon_health > 0){
// Player Threw item at Entity
}
}

Just a suggestion Tongue

Interesting, thanks for the suggestion!
By the way, the second method does not work, I got the feeling that GetEntitiesCollide is not really into areas.

Quote:I would be more interested in what happens when the condition is met than the condition itself. Just from the condition itself, i feel this can be accomplished without the need of compensating through scripting.


What do you mean? Elaborate or demonstrate please.
(04-12-2012, 08:50 PM)ClayPigeon Wrote: [ -> ]What do you mean? Elaborate or demonstrate please.

Do you not know the structure and purpose of an if statement? It's your code, and the part that executes when the expression evaluates to true is what i am interested in.
(04-13-2012, 10:32 AM)Your Computer Wrote: [ -> ]
(04-12-2012, 08:50 PM)ClayPigeon Wrote: [ -> ]What do you mean? Elaborate or demonstrate please.

Do you not know the structure and purpose of an if statement? It's your code, and the part that executes when the expression evaluates to true is what i am interested in.
Oh:
Code:
mon_health -= damage_do_iron;        
PlaySoundAtEntity("", "attack_claw.snt", "servant_grunt_1", 0.5f, false);
PlayPropAnimation("servant_grunt_1", "walk.anm", 1.0f, false, "");
Pages: 1 2