Raised This Month: $51 Target: $400
 12% 

Help change button double jump


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vegeta1241
AlliedModders Donor
Join Date: Apr 2017
Location: Switzerland
Old 03-06-2019 , 13:09   Help change button double jump
Reply With Quote #1

Hello i use this plugin but i need help to change the double jump button to CTRL. If you can help me

PHP Code:
/*
 * Double Jump
 *
 * Description:
 *  Allows players to double-jump
 *  Original idea: NcB_Sav
 *
 * Convars:
 *  sm_doublejump_enabled [bool] : Enables or disable double-jumping. Default: 1
 *  sm_doublejump_boost [amount] : Amount to boost the player. Default: 250
 *  sm_doublejump_max [jumps]    : Maximum number of re-jumps while airborne. Default: 1
 *
 * Changelog:
 *  v1.0.1
 *   Minor code optimization.
 *  v1.0.0
 *   Initial release.
 *
 * Known issues:
 *  Doesn't register all mouse-wheel triggered +jumps
 *
 * Todo:
 *  Employ upcoming OnClientCommand function to remove excess OnGameFrame-age.
 *
 * Contact:
 *  Paegus: [email protected]
 *  SourceMod: http://www.sourcemod.net
 *  Hidden:Source: http://www.hidden-source.com
 *  NcB_Sav: http://forums.alliedmods.net/showthread.php?t=99228
 */
#define PLUGIN_VERSION        "1.0.1"

#include <sdktools>


public Plugin:myinfo = {
    
name        "Double Jump",
    
author        "Paegus",
    
description    "Allows double-jumping.",
    
version        PLUGIN_VERSION,
    
url            ""
}

new
    
Handle:g_cvJumpBoost    INVALID_HANDLE,
    
Handle:g_cvJumpEnable    INVALID_HANDLE,
    
Handle:g_cvJumpMax        INVALID_HANDLE,
    
Float:g_flBoost            250.0,
    
bool:g_bDoubleJump        true,
    
g_fLastButtons[MAXPLAYERS+1],
    
g_fLastFlags[MAXPLAYERS+1],
    
g_iJumps[MAXPLAYERS+1],
    
g_iJumpMax
    
public OnPluginStart() {
    
CreateConVar(
        
"sm_doublejump_version"PLUGIN_VERSION,
        
"Double Jump Version",
        
FCVAR_PLUGIN|FCVAR_NOTIFY
    
)
    
    
g_cvJumpEnable CreateConVar(
        
"sm_doublejump_enabled""1",
        
"Enables double-jumping.",
        
FCVAR_PLUGIN|FCVAR_NOTIFY
    
)
    
    
g_cvJumpBoost CreateConVar(
        
"sm_doublejump_boost""250.0",
        
"The amount of vertical boost to apply to double jumps.",
        
FCVAR_PLUGIN|FCVAR_NOTIFY
    
)
    
    
g_cvJumpMax CreateConVar(
        
"sm_doublejump_max""1",
        
"The maximum number of re-jumps allowed while already jumping.",
        
FCVAR_PLUGIN|FCVAR_NOTIFY
    
)
    
    
HookConVarChange(g_cvJumpBoost,        convar_ChangeBoost)
    
HookConVarChange(g_cvJumpEnable,    convar_ChangeEnable)
    
HookConVarChange(g_cvJumpMax,        convar_ChangeMax)
    
    
g_bDoubleJump    GetConVarBool(g_cvJumpEnable)
    
g_flBoost        GetConVarFloat(g_cvJumpBoost)
    
g_iJumpMax        GetConVarInt(g_cvJumpMax)
}

public 
convar_ChangeBoost(Handle:convar, const String:oldVal[], const String:newVal[]) {
    
g_flBoost StringToFloat(newVal)
}

public 
convar_ChangeEnable(Handle:convar, const String:oldVal[], const String:newVal[]) {
    if (
StringToInt(newVal) >= 1) {
        
g_bDoubleJump true
    
} else {
        
g_bDoubleJump false
    
}
}

public 
convar_ChangeMax(Handle:convar, const String:oldVal[], const String:newVal[]) {
    
g_iJumpMax StringToInt(newVal)
}

public 
OnGameFrame() {
    if (
g_bDoubleJump) {                            // double jump active
        
for (new 1<= MaxClientsi++) {        // cycle through players
            
if (
                
IsClientInGame(i) &&                // is in the game
                
IsPlayerAlive(i)                    // is alive
            
) {
                
DoubleJump(i)                        // Check for double jumping
            
}
        }
    }
}

stock DoubleJump(const any:client) {
    new
        
fCurFlags    GetEntityFlags(client),        // current flags
        
fCurButtons    GetClientButtons(client)        // current buttons
    
    
if (g_fLastFlags[client] & FL_ONGROUND) {        // was grounded last frame
        
if (
            !(
fCurFlags FL_ONGROUND) &&            // becomes airbirne this frame
            
!(g_fLastButtons[client] & IN_JUMP) &&    // was not jumping last frame
            
fCurButtons IN_JUMP                    // started jumping this frame
        
) {
            
OriginalJump(client)                    // process jump from the ground
        
}
    } else if (                                        
// was airborne last frame
        
fCurFlags FL_ONGROUND                        // becomes grounded this frame
    
) {
        
Landed(client)                                // process landing on the ground
    
} else if (                                        // remains airborne this frame
        
!(g_fLastButtons[client] & IN_JUMP) &&        // was not jumping last frame
        
fCurButtons IN_JUMP                        // started jumping this frame
    
) {
        
ReJump(client)                                // process attempt to double-jump
    
}
    
    
g_fLastFlags[client]    = fCurFlags                // update flag state for next frame
    
g_fLastButtons[client]    = fCurButtons            // update button state for next frame
}

stock OriginalJump(const any:client) {
    
g_iJumps[client]++    // increment jump count
}

stock Landed(const any:client) {
    
g_iJumps[client] = 0    // reset jumps count
}

stock ReJump(const any:client) {
    if ( 
<= g_iJumps[client] <= g_iJumpMax) {                        // has jumped at least once but hasn't exceeded max re-jumps
        
g_iJumps[client]++                                            // increment jump count
        
decl Float:vVel[3]
        
GetEntPropVector(clientProp_Data"m_vecVelocity"vVel)    // get current speeds
        
        
vVel[2] = g_flBoost
        TeleportEntity
(clientNULL_VECTORNULL_VECTORvVel)        // boost player
    
}

__________________
IDEAS-GAMING.COM SERVERS ON CSGO :

- HIDE AND SEEK - SUPERHEROES
- BUNNY HOP
- KZ / CLIMB

---------------------------------------------------------------------
My steam link
Donate !
vegeta1241 is offline
Vasto_Lorde
Junior Member
Join Date: Oct 2016
Old 03-06-2019 , 14:46   Re: Help change button double jump
Reply With Quote #2

Hi there! This is the function that creates the ability to do double jump:
Code:
DoubleJump(const any:client)
The process of deciding whether the player is airbone and clicks space (IN_JUMP) buton begins here:
Code:
if (g_fLastFlags[client] & FL_ONGROUND)
Althorugh the "ifs" are somehow not super clear to read, there are multiple comments what is processing at any single step. So, there is a line that states "this is where we do doublejump"
Code:
ReJump(client)                                // process attempt to double-jump
This however does not tell us when to jump, it simply says just to jump. To look up when do we do this, we must look a few lines upwards
Code:
    } else if (                                        // remains airborne this frame 
        !(g_fLastButtons[client] & IN_JUMP) &&        // was not jumping last frame 
        fCurButtons & IN_JUMP                        // started jumping this frame 
    ) {
This code says: "Is the player starting to click space (IN_JUMP button) now?"


So basicly, you must change both IN_JUMP defines into IN_DUCK. There are multiple buttons defined like that, for example you could make double jump by replacing IN_JUMP with IN_ATTACK, which would cause to activate double jump when somebody shoots with leftclick while in the air. The full list of buttons can be found here: https://sm.alliedmods.net/api/index....oad=file&id=47

Last edited by Vasto_Lorde; 03-06-2019 at 14:46.
Vasto_Lorde is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 03-07-2019 , 02:44   Re: Help change button double jump
Reply With Quote #3

Quote:
Originally Posted by Vasto_Lorde View Post
So basicly, you must change both IN_JUMP defines into IN_DUCK.
Doing this in csgo would make you lose almost all your speed unless you press it extremely fast since crouching makes you move around 66% slower than normal run speed and makes the double jump almost useless unless it was specifically used just for gaining height.

I would suggest just binding ctrl to +jump and +duck to another key.

Last edited by CliptonHeist; 03-07-2019 at 02:50.
CliptonHeist is offline
Vasto_Lorde
Junior Member
Join Date: Oct 2016
Old 03-07-2019 , 03:55   Re: Help change button double jump
Reply With Quote #4

Quote:
Originally Posted by CliptonHeist View Post
Doing this in csgo would make you lose almost all your speed unless you press it extremely fast since crouching makes you move around 66% slower than normal run speed and makes the double jump almost useless unless it was specifically used just for gaining height.

I would suggest just binding ctrl to +jump and +duck to another key.
Doesn't slow only work when you are on the ground?

I don't think your suggestion is appropiate, since you can not bind users keys from plugin level
Vasto_Lorde is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 03-07-2019 , 04:08   Re: Help change button double jump
Reply With Quote #5

Quote:
Originally Posted by Vasto_Lorde View Post
Doesn't slow only work when you are on the ground?

I don't think your suggestion is appropiate, since you can not bind users keys from plugin level
No, it also removes momentum when in the air and makes you drop faster.
I was suggesting to bind ingame since there isn't a way to check individual key presses afaik, can only use client buttons to check.
CliptonHeist is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:02.


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