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
Checking if the player is NOT inside an area?
ClayPigeon Offline
Member

Posts: 214
Threads: 13
Joined: Mar 2012
Reputation: 8
#1
Checking if the player is NOT inside an area?

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.

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

Any suggestions?
(This post was last modified: 04-12-2012, 04:46 PM by ClayPigeon.)
04-12-2012, 04:46 PM
Find
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#2
RE: Checking if the player is NOT inside an area?

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: (Select All)
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:
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.

(This post was last modified: 04-12-2012, 05:25 PM by DRedshot.)
04-12-2012, 05:16 PM
Find
ClayPigeon Offline
Member

Posts: 214
Threads: 13
Joined: Mar 2012
Reputation: 8
#3
RE: Checking if the player is NOT inside an area?

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!
(This post was last modified: 04-12-2012, 06:23 PM by ClayPigeon.)
04-12-2012, 06:22 PM
Find
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#4
RE: Checking if the player is NOT inside an area?

(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


(This post was last modified: 04-12-2012, 06:30 PM by DRedshot.)
04-12-2012, 06:29 PM
Find
ClayPigeon Offline
Member

Posts: 214
Threads: 13
Joined: Mar 2012
Reputation: 8
#5
RE: Checking if the player is NOT inside an area?

(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
Find
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#6
RE: Checking if the player is NOT inside an area?

(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


(This post was last modified: 04-12-2012, 07:51 PM by DRedshot.)
04-12-2012, 07:48 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#7
RE: Checking if the player is NOT inside an area?

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.

Tutorials: From Noob to Pro
04-12-2012, 08:03 PM
Website Find
ClayPigeon Offline
Member

Posts: 214
Threads: 13
Joined: Mar 2012
Reputation: 8
#8
RE: Checking if the player is NOT inside an area?

(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
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#9
RE: Checking if the player is NOT inside an area?

(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.

Tutorials: From Noob to Pro
04-13-2012, 10:32 AM
Website Find
ClayPigeon Offline
Member

Posts: 214
Threads: 13
Joined: Mar 2012
Reputation: 8
#10
RE: Checking if the player is NOT inside an area?

(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:
mon_health -= damage_do_iron;        
PlaySoundAtEntity("", "attack_claw.snt", "servant_grunt_1", 0.5f, false);
PlayPropAnimation("servant_grunt_1", "walk.anm", 1.0f, false, "");
(This post was last modified: 04-13-2012, 10:35 AM by ClayPigeon.)
04-13-2012, 10:35 AM
Find




Users browsing this thread: 1 Guest(s)