PDA

View Full Version : Check if player in air


keygens
11-13-2014, 12:43
Hello. I have small question, about how i can check player if he in air right now.
I know about code like this for it:
(!(GetEntityFlags(client) & FL_ONGROUND))But, how we can check it by other way/other code? Thanks in advance

Ibanezez
11-13-2014, 13:28
Not sure if this is what you're looking for, but there's this:
https://forums.alliedmods.net/showthread.php?t=151142

Basically it would look like this in a script:

#include <sourcemod>
#include <sdktools>
#define MAX_BUTTONS 26
new g_LastButtons[MAXPLAYERS+1];

public OnClientDisconnect_Post(client)
{
g_LastButtons[client] = 0;
}

public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
for (new i = 0; i < MAX_BUTTONS; i++)
{
new button = (1 << i);

if ((buttons & button))
{
if (!(g_LastButtons[client] & button))
{
OnButtonPress(client, button);
}
}
else if ((g_LastButtons[client] & button))
{
OnButtonRelease(client, button);
}
}

g_LastButtons[client] = buttons;

return Plugin_Continue;
}

OnButtonPress(client, button)
{
if (button == IN_JUMP) //Insert some code here
}

OnButtonRelease(client, button)
{
if (button == IN_JUMP) //Insert some code here
}

Put the code into if(button == IN_JUMP) on OnButtonpress and OnButtonRelease.

(OnButtonPress is while in the air, OnButtonRelease is when they hit the ground again, I think)

Not sure if that's what you were looking for, but I hope I helped. :)

friagram
11-13-2014, 14:09
Use entity flags

The1Speck
11-13-2014, 17:23
Another option would be to use trace-rays. Angle it downwards from the player and calculate the distance from the player and the ground.

keygens
11-14-2014, 02:56
Another option would be to use trace-rays. Angle it downwards from the player and calculate the distance from the player and the ground.

Can you give me example of it?

ddhoward
11-14-2014, 03:03
What is the problem with the method that you mentioned in the first post?

Franc1sco
11-14-2014, 03:15
See the code in red here https://forums.alliedmods.net/showpost.php?p=2175381&postcount=44

thecount
11-14-2014, 20:32
Use entity flags

^

keygens
11-15-2014, 03:50
^

Entity flags? m_fFlags? Or what?

ddhoward
11-15-2014, 03:55
I would assume something like this:


if (!(GetEntityFlags(client) & FL_ONGROUND)) {
//client is not on the ground
}
:P

keygens
11-15-2014, 04:09
I would assume something like this:


if (!(GetEntityFlags(client) & FL_ONGROUND)) {
//client is not on the ground
}
:P

I know this method, posted it in my question. But i just to want other method for detecting of player in air.

ddhoward
11-15-2014, 04:10
That is the best method. Other methods are overly complicated or imperfect.

You still haven't answered my question of WHY you want another method.

keygens
11-15-2014, 04:19
That is the best method. Other methods are overly complicated or imperfect.

You still haven't answered my question of WHY you want another method.

i have very specific problem with my plugin...PM me, i will tell you more.

keygens
11-15-2014, 04:59
That is the best method. Other methods are overly complicated or imperfect.

You still haven't answered my question of WHY you want another method.


Check your steam, i have been added. PM not sending from me, that sad...

thecount
11-15-2014, 13:33
i have very specific problem with my plugin...PM me, i will tell you more.

Pretty sure it isn't that there is a problem with the method, but you don't know how to apply it to whatever situation you have. Again, we can help a lot more if you gave full details of the problem. Help us help you, mate. :bacon:

keygens
11-16-2014, 07:00
Pretty sure it isn't that there is a problem with the method, but you don't know how to apply it to whatever situation you have. Again, we can help a lot more if you gave full details of the problem. Help us help you, mate. :bacon:

How do i can check player in air by stock GetEntityFlags?


stock GetEntityFlags(entity)
{
return GetEntProp(entity, Prop_Data, "m_fFlags");
}
I just dont understand what need to add here, i think about FL_ONGROUND, but where put it?

friagram
11-16-2014, 07:15
Wow
if(GetEntityFlags(client) & FL_ONGROUND)

thecount
11-16-2014, 14:43
How do i can check player in air by stock GetEntityFlags? I just dont understand what need to add here, i think about FL_ONGROUND, but where put it?

GetEntityFlags(client) returns bits of information which can be checked for certain bits. FL_ONGROUND is one of those, and you can check by if(GetEntityFlags(client) & FL_ONGROUND). But are you looking to constantly check for players in the air, or do you want to check on certain events?

keygens
11-16-2014, 14:52
GetEntityFlags(client) returns bits of information which can be checked for certain bits. FL_ONGROUND is one of those, and you can check by if(GetEntityFlags(client) & FL_ONGROUND). But are you looking to constantly check for players in the air, or do you want to check on certain events?

My problem is really very specific. Plugin sometimes was bugged, when people in air, and he need to boost them, but debug mode say - "done", but people was not boosted. I guess, maybe need to check players in air...But its not help.

blaacky
11-16-2014, 15:07
Are you saying your goal is to boost players upwards when they are on the ground, but it isn't working? Because I know a way to fix that.

keygens
11-16-2014, 15:27
Are you saying your goal is to boost players upwards when they are on the ground, but it isn't working? Because I know a way to fix that.

Ohh, hello Blacky, i know you (bhop_badges and etc)

Can you help me with that? I just can't fix this 2 or 3 weeks...really tired

blaacky
11-18-2014, 13:21
Well I'm not sure I understand the question. But if your problem is to push someone upwards with a small amount of velocity then, this works well.

public OnPluginStart()
{
RegConsoleCmd("sm_test", SM_Test);
}

public Action:SM_Test(client, args)
{
new Float:vVel[3];
vVel[0] = GetRandomFloat(-1000.0, 1000.0);
vVel[1] = GetRandomFloat(-1000.0, 1000.0);
vVel[2] = 251.0; // Velocity to get client off ground

Entity_SetAbsVelocity(client, vVel);

new Handle:hData;
CreateDataTimer(0.0, Timer_Move, hData, TIMER_DATA_HNDL_CLOSE);
WritePackCell(hData, client);
WritePackFloat(hData, vVel[0]);
WritePackFloat(hData, vVel[1]);
}

public Action:Timer_Move(Handle:timer, Handle:data)
{
ResetPack(data);
new client = ReadPackCell(data);

new Float:vVel[3];
vVel[0] = ReadPackFloat(data);
vVel[1] = ReadPackFloat(data);
vVel[2] = 150.0; // The velocity I want

Entity_SetAbsVelocity(client, vVel);
}

You have to push someone up with a velocity greater than 250 velocity, then you have to create a timer with a 0.0 second time delay, and then you can set their velocity to whatever you want.

Chdata
11-18-2014, 14:46
stock DoubleJump(const any:client, Float:flBoost = 280.0)
{
decl Float:vVel[3];
GetEntPropVector(client, Prop_Data, "m_vecVelocity", vVel); // get current speeds

vVel[2] = flBoost;
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vVel); // boost player
return;
}

// DistanceAboveGround(): Calculate a player's distance above the ground.
// Code borrowed from MGE Mod, thanks to Lange!
Float:DistanceAboveGround(client)
{
decl Float:vStart[3];
decl Float:vEnd[3];
new Float:vAngles[3] = {90.0, 0.0, 0.0};
new Handle:trace;
new Float:distance = -1.0;

// Get the client's origin vector and start up the trace ray
GetClientAbsOrigin(client, vStart);
trace = TR_TraceRayFilterEx(vStart, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);

if (TR_DidHit(trace))
{
// Calculate the distance.
TR_GetEndPosition(vEnd, trace);
distance = GetVectorDistance(vStart, vEnd, false);
}
else
{
// There should always be some ground under the player.
LogError("[Airshot Bride] Trace error: client %N (%d)", client, client);
}

// Clean up and return
CloseHandle(trace);
return distance;
}

// TraceEntityFilterPlayer(): Ignore players in a trace ray
public bool:TraceEntityFilterPlayer(entity, contentsMask)
{
return !IsValidClient(entity);
}

By the way you really should just use

Wow
if(GetEntityFlags(client) & FL_ONGROUND)

I would assume something like this:


if (!(GetEntityFlags(client) & FL_ONGROUND)) {
//client is not on the ground
}
:P

if (GetEntityFlags(client) & FL_ONGROUND)
{
//client is on the ground
}
else
{
//client is in the air or swimming in water (you can catch FL_INWATER too)
}

keygens
11-18-2014, 14:51
Well I'm not sure I understand the question. But if your problem is to push someone upwards with a small amount of velocity then, this works well.

public OnPluginStart()
{
RegConsoleCmd("sm_test", SM_Test);
}

public Action:SM_Test(client, args)
{
new Float:vVel[3];
vVel[0] = GetRandomFloat(-1000.0, 1000.0);
vVel[1] = GetRandomFloat(-1000.0, 1000.0);
vVel[2] = 251.0; // Velocity to get client off ground

Entity_SetAbsVelocity(client, vVel);

new Handle:hData;
CreateDataTimer(0.0, Timer_Move, hData, TIMER_DATA_HNDL_CLOSE);
WritePackCell(hData, client);
WritePackFloat(hData, vVel[0]);
WritePackFloat(hData, vVel[1]);
}

public Action:Timer_Move(Handle:timer, Handle:data)
{
ResetPack(data);
new client = ReadPackCell(data);

new Float:vVel[3];
vVel[0] = ReadPackFloat(data);
vVel[1] = ReadPackFloat(data);
vVel[2] = 150.0; // The velocity I want

Entity_SetAbsVelocity(client, vVel);
}You have to push someone up with a velocity greater than 250 velocity, then you have to create a timer with a 0.0 second time delay, and then you can set their velocity to whatever you want.

I will use it for my other idea. Thanks Blacky!

blodia
11-18-2014, 17:12
taken from my player stacker plugin

// the entity the player is standing on.
new GroundEnt = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");if the players isn't standing on an entity i.e in the air it will return -1.

keygens
11-18-2014, 17:35
taken from my player stacker plugin

// the entity the player is standing on.
new GroundEnt = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");if the players isn't standing on an entity i.e in the air it will return -1.


new GroundEnt = (GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") == -1);

Something like that?

Chdata
11-18-2014, 21:33
new bool:GroundEnt

keygens
11-19-2014, 09:20
new bool:GroundEnt

Thanks for help! I will use all what you give me before in this thread!