AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect when jumping (https://forums.alliedmods.net/showthread.php?t=153806)

KviZ 03-29-2011 15:25

Detect when jumping
 
Is it hard to make a function that is called whenever player jumps? And how can I do it?

P.S. I'm just a begginer

naven 03-29-2011 16:37

Re: Detect when jumping
 
Check this out:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>

#define ADMINACCESS ADMIN_CHAT

new jumpnum[33] = 0
new bool:dojump[33] = false

public plugin_init()
{
    
register_plugin("MultiJump","1.1","twistedeuphoria")
    
register_cvar("amx_maxjumps","1")
    
register_cvar("amx_mjadminonly","0")
}

public 
client_putinserver(id)
{
    
jumpnum[id] = 0
    dojump
[id] = false
}

public 
client_disconnect(id)
{
    
jumpnum[id] = 0
    dojump
[id] = false
}

public 
client_PreThink(id)
{
    if(!
is_user_alive(id)) return PLUGIN_CONTINUE
    
if(get_cvar_num("amx_mjadminonly") && (!access(id,ADMINACCESS))) return PLUGIN_CONTINUE
    
new nbut get_user_button(id)
    new 
obut get_user_oldbutton(id)
    if((
nbut IN_JUMP) && !(get_entity_flags(id) & FL_ONGROUND) && !(obut IN_JUMP))
    {
        if(
jumpnum[id] < get_cvar_num("amx_maxjumps"))
        {
            
dojump[id] = true
            jumpnum
[id]++
            return 
PLUGIN_CONTINUE
        
}
    }
    if((
nbut IN_JUMP) && (get_entity_flags(id) & FL_ONGROUND))
    {
        
jumpnum[id] = 0
        
return PLUGIN_CONTINUE
    
}
    return 
PLUGIN_CONTINUE
}

public 
client_PostThink(id)
{
    if(!
is_user_alive(id)) return PLUGIN_CONTINUE
    
if(get_cvar_num("amx_mjadminonly") && (!access(id,ADMINACCESS))) return PLUGIN_CONTINUE
    
if(dojump[id] == true)
    {
        new 
Float:velocity[3]    
        
entity_get_vector(id,EV_VEC_velocity,velocity)
        
velocity[2] = random_float(265.0,285.0)
        
entity_set_vector(id,EV_VEC_velocity,velocity)
        
dojump[id] = false
        
return PLUGIN_CONTINUE
    
}
    return 
PLUGIN_CONTINUE



KviZ 03-30-2011 07:17

Re: Detect when jumping
 
It's from multijump plugin and I have it and for my basebuilder plugin it's good when you're not gravity zombie, this plugin changes the gravity to 800 after second jump in the air and it makes gravity zombie useless... and it looks difficult, like I said I'm just a begginer. And I want to know what is client_PreThink?

Edit: I fixed my problem! :D

drekes 03-30-2011 07:47

Re: Detect when jumping
 
client_PreThink is an engine forward.
Funcwiki doesn't seem to give a good explanation about it.
This is from the hlsdk:
Quote:

================
PlayerPreThink

Called every frame before physics are run
================
The fakemeta way for this is:
PHP Code:

register_forward(FM_PlayerPreThink"FwdPlayerPreThink"); 


KviZ 03-30-2011 08:03

Re: Detect when jumping
 
Oh thanks a lot :)

<VeCo> 03-30-2011 08:41

Re: Detect when jumping
 
PHP Code:

RegisterHam(Ham_Player_Jump,"player","function",1


Exolent[jNr] 03-30-2011 17:49

Re: Detect when jumping
 
Quote:

Originally Posted by <VeCo> (Post 1441637)
PHP Code:

RegisterHam(Ham_Player_Jump,"player","function",1


That isn't proper for detecting when player jumps, because you still have to check flags and button.

For detecting when player jumps, you should use Orpheu and hook PM_Jump().


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

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