AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Jumping Detection low CPU (https://forums.alliedmods.net/showthread.php?t=142596)

TandborsteN 11-07-2010 12:57

Jumping Detection low CPU
 
Hello!
Im trying to detect when a player jumps and i want to have so low CPU as possible.
So what way is the best way?

My code:
Code:

public client_PreThink(id)
{
    new New_Button = get_user_button(id);
    new Old_Button = get_user_oldbutton(id);
    if((New_Button & IN_JUMP) && !(Old_Button & IN_JUMP) && is_user_alive(id))
    {
        //ACTION CODE
    }
}


Exolent[jNr] 11-07-2010 13:06

Re: Jumping Detection low CPU
 
Move to FM_CmdStart.
Use get_uc() for buttons instead of get_user_button()
Check if player is on ground (get_entity_flags() & FL_ONGROUND).

TandborsteN 11-07-2010 13:09

Re: Jumping Detection low CPU
 
Can you PLEASE show me an example? :)
Doesen't get anything of what you mean.

Exolent[jNr] 11-07-2010 13:12

Re: Jumping Detection low CPU
 
Search for FM_CmdStart. You can find funciton examples here: http://www.amxmodx.org/funcwiki.php

TandborsteN 11-07-2010 13:14

Re: Jumping Detection low CPU
 
Okey thank you very much, u are awsome! :)

TandborsteN 11-07-2010 13:22

Re: Jumping Detection low CPU
 
So something like this?
Code:

public FM_CmdStart_Pre(id, uc_handle)
{
    new button = get_uc(uc_handle, UC_Buttons);
    new oldbutton = pev(id, pev_oldbuttons);
    new flags = pev(id, pev_flags);
    if(button & IN_JUMP && !(oldbutton & IN_JUMP) && flags & FL_ONGROUND)
    {
        //CODE
    }
}


bibu 11-07-2010 13:36

Re: Jumping Detection low CPU
 
Exolent isn't ham better?

PHP Code:

RegisterHam(Ham_Player_Jump"player""Player_Jump"


Exolent[jNr] 11-07-2010 13:45

Re: Jumping Detection low CPU
 
Quote:

Originally Posted by TandborsteN (Post 1344344)
So something like this?
Code:

public FM_CmdStart_Pre(id, uc_handle)
{
    new button = get_uc(uc_handle, UC_Buttons);
    new oldbutton = pev(id, pev_oldbuttons);
    new flags = pev(id, pev_flags);
    if(button & IN_JUMP && !(oldbutton & IN_JUMP) && flags & FL_ONGROUND)
    {
        //CODE
    }
}


Yes.

Quote:

Originally Posted by bibu (Post 1344363)
Exolent isn't ham better?

PHP Code:

RegisterHam(Ham_Player_Jump"player""Player_Jump"


Ham would be better to do the same check in this case, but you would still have to check it like in FM_CmdStart because it isn't called only when a player jumps.

abdul-rehman 11-08-2010 09:48

Re: Jumping Detection low CPU
 
Quote:

Originally Posted by TandborsteN (Post 1344344)
So something like this?
Code:

public FM_CmdStart_Pre(id, uc_handle)
{
    new button = get_uc(uc_handle, UC_Buttons);
    new oldbutton = pev(id, pev_oldbuttons);
    new flags = pev(id, pev_flags);
    if(button & IN_JUMP && !(oldbutton & IN_JUMP) && flags & FL_ONGROUND)
    {
        //CODE
    }
}


Ya but its better if you would make the variables static since this forward sometimes get called very quickly


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

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