AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Best way to detect if player is in air (https://forums.alliedmods.net/showthread.php?t=130139)

NucL3ra 06-20-2010 16:47

Best way to detect if player is in air
 
Which one of those is better (lower CPU usage)

1.
PHP Code:

new Float:velocity[3]
entity_get_vector(id,EV_VEC_velocity,velocity)

 if ( (
velocity[2]!=0) ) 
   
ColorChat(id ,GREEN"You are in air"

2.
PHP Code:

const FL_ONGROUND2 = ( FL_ONGROUND FL_PARTIALGROUND FL_INWATER |  FL_CONVEYOR FL_FLOAT );

if( !( 
pevidpev_flags ) & FL_ONGROUND2 
   
ColorChatidGREEN"You are in air"

1st uses engine modules
2nd uses amxmodx only, but it detects players on ladders as being in air

wrecked_ 06-20-2010 16:52

Re: Best way to detect if player is in air
 
Then use the engine one if the second one is not getting the correct answer every time. It's extremely trivial.

JaGareN 06-20-2010 22:02

Re: Best way to detect if player is in air
 
I have a question...
Which of those tow are better (lower cpu) or faster?

Engine:
PHP Code:

new Float:velocity[3];
entity_get_vectoridEV_VEC_velocityvelocity ); 

Fakemeta:
PHP Code:

new Float:velocity[3];
pevidpev_velocityvelocity ); 


Emp` 06-20-2010 22:54

Re: Best way to detect if player is in air
 
The difference is very small. You should just use whichever one you are more comfortable with.

Btw, in your second example, the pev native is from fakemeta and not amxmodx.

IIRC, when on a ladder you are given the flag FL_FLY, you can add it to the bitsum to get rid of your bug.

Additionally, your velocity check will return that they are on the ground at the max height of their jump.

ConnorMcLeod 06-21-2010 00:56

Re: Best way to detect if player is in air
 
Velocity check is also false if you run on a non-flat ground.

grimvh2 06-21-2010 04:14

Re: Best way to detect if player is in air
 
Quote:

Originally Posted by ConnorMcLeod (Post 1215124)
Velocity check is also false if you run on a non-flat ground.

surf parts also.

ConnorMcLeod 06-21-2010 13:38

Re: Best way to detect if player is in air
 
Quote:

Originally Posted by grimvh2 (Post 1215204)
surf parts also.

I guess he doesn't want to allow checkpoints on surf parts.

NucL3ra 06-21-2010 17:09

Re: Best way to detect if player is in air
 
Ok so i will remain with the first one.

And ehh, I didn't know pev native is from fakemeta

Hawk552 06-21-2010 22:46

Re: Best way to detect if player is in air
 
Quote:

Originally Posted by Emp` (Post 1215051)
The difference is very small. You should just use whichever one you are more comfortable with.

Floating point math is insanely expensive, especially compared to bit operations. The difference is not even close to being small. If you're referring to JaGareN's post, then nevermind.

ConnorMcLeod 06-22-2010 00:53

Re: Best way to detect if player is in air
 
Quote:

Originally Posted by NucL3ra (Post 1215698)
Ok so i will remain with the first one.

And ehh, I didn't know pev native is from fakemeta

oO, use the 2nd one and read post #4


All times are GMT -4. The time now is 14:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.