I have a strange problem, I'm trying to make a double jump plugin, but if I enable sv_autobunnyhopping, double jump won't work on the first jump, but after I bunnyhop at least once.
That mean, I have to jump, land, then I'll be able to double jump. This is strange. I don't have any other plugin that modifies player's buttons.
Here is my code called on OnPlayerRunCmd()
PHP Code:
void DoubleJump(int Client, float vVel[3])
{
static int CurFlags = 0;
static int CurButtons = 0;
CurFlags = GetEntityFlags(Client);
CurButtons = GetClientButtons(Client);
if(CurFlags & FL_ONGROUND)
{
g_iJumps[Client] = 0;
PrintHintText(Client, "DEBUG 1 [%i Jumps]", g_iJumps[Client]);
}
else if(!(CurFlags & FL_ONGROUND) && g_iJumps[Client] == 0)
{
//PrintHintText(Client, "DEBUG 2 [%i Jumps]", g_iJumps[Client]);
if((CurButtons & IN_JUMP) && !(g_iLastButtons[Client] & IN_JUMP))
{
g_iJumps[Client] = g_iJumps[Client] + 1;
PrintHintText(Client, "DEBUG 2 [%i Jumps]", g_iJumps[Client]);
vVel[2] = 300.0;
TeleportEntity(Client, NULL_VECTOR, NULL_VECTOR, vVel);
SetEntDataVector(Client, g_iVelocity, vVel);
}
}
g_iLastButtons[Client] = CurButtons;
}
I fixed it by myself
Here's the code in case anyone needs it
PHP Code:
void DoubleJump(int Client, float vVel[3])
{
static int CurFlags = 0;
static int CurButtons = 0;
static int LastFlags[MAXPLAYERS + 1];
static int Jumps[MAXPLAYERS + 1];
static int LastButtons[MAXPLAYERS+1] = 0;
CurFlags = GetEntityFlags(Client);
CurButtons = GetClientButtons(Client);
if(CurFlags & FL_ONGROUND)
{
Jumps[Client] = 0;
}
else if(!(CurFlags & FL_ONGROUND))
{
if((CurButtons & IN_JUMP) && !(LastFlags[Client] & FL_ONGROUND) && !(LastButtons[Client] & IN_JUMP))
{
if(Jumps[Client] == 0)
{
vVel[2] = 300.0;
TeleportEntity(Client, NULL_VECTOR, NULL_VECTOR, vVel);
SetEntDataVector(Client, g_iVelocity, vVel);
Jumps[Client]++;
}
}
}
LastFlags[Client] = CurFlags;
LastButtons[Client] = CurButtons;
}
__________________