PDA

View Full Version : Lower gravity for client when holding spacebar?


Ibanezez
11-08-2014, 11:20
I'm thinking about making a TF2 surf server, and I know that a surf server isn't complete without a jump pack. Basically, I want it to lower gravity for the client when they hold space. They have this on Garry's Mod servers, though it is using Lua. Is this possible?

psychonic
11-08-2014, 14:10
You can check this example to catch the IN_JUMP button being pressed and released (spacebar or whatever key they have jump bound to). https://forums.alliedmods.net/showthread.php?t=151142

From there, you can alter the m_flGravity property on the player with SetEntPropFloat. The value is a multiplier used against the sv_gravity value. (1.0 = same, 0.8 = 80%, etc)

thecount
11-08-2014, 16:00
You can check this example to catch the IN_JUMP button being pressed and released (spacebar or whatever key they have jump bound to). https://forums.alliedmods.net/showthread.php?t=151142

From there, you can alter the m_flGravity property on the player with SetEntPropFloat. The value is a multiplier used against the sv_gravity value. (1.0 = same, 0.8 = 80%, etc)

There's alsoSetEntityGravity(client, #);

Ibanezez
11-08-2014, 16:50
How would this look inside a code?

Would it be like this:


#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

#define MAX_BUTTONS 25
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 IN_JUMP = (1 << 1);

if ((buttons & IN_JUMP))
{
if (!(g_LastButtons[client] & IN_JUMP))
{
OnButtonPress(client, IN_JUMP);
{
SetEntityGravity(client, 0.5);
return Plugin_Handled;
}
}
}
else if ((g_LastButtons[client] & IN_JUMP))
{
OnButtonRelease(client, IN_JUMP);
{
SetEntityGravity(client, 1.0);
return Plugin_Handled;
}
}
}

g_LastButtons[client] = buttons;

return Plugin_Continue;

ddhoward
11-08-2014, 17:04
-snip-

You would need to include the rest of the code in there. And also, you aren't checking to see if the button they pressed is actually the jump button. Your code in your edited post is completely nonsensical.



{
OnButtonRelease(client, IN_JUMP);
{

what is this even



#include <sdktools>
#define MAX_BUTTONS 26 //i believe that with the addition of +attack3, tf2 has 26 buttons now
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) SetEntityGravity(client, 0.5);
}

OnButtonRelease(client, button)
{
if (button == IN_JUMP) SetEntityGravity(client, 1.0);
}