Raised This Month: $ Target: $400
 0% 

Create a +button


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-05-2009 , 22:27   Create a +button
Reply With Quote #1

How does one go about creating a new +button in an amxx plugin and be able to detect when it is being pressed?
__________________
Bad_Bud is offline
MPNumB
Veteran Member
Join Date: Feb 2007
Location: Lithuania
Old 01-05-2009 , 22:43   Re: Create a +button
Reply With Quote #2

for custom buttons:
PHP Code:
register_clcmd("+button""clcmd_plusbutton");
register_clcmd("-button""clcmd_minusbutton");
 
public 
clcmd_plusbutton(id)
{
 
// player typed "+button"
}
 
public 
clcmd_minusbutton(id)
{
 
// player typed "-button"

for already known buttons:

PHP Code:
#include <fakemeta>
public plugin_init()
{
 
// register plugin and do much more
 
 
register_forward(FM_PlayerPreThink"FM_PlayerPreThink_Pre"0);
}
 
public 
FM_PlayerPreThink(iPlrId)
{
 static 
s_iOldButtonss_iNewButtons;
 
s_iOldButtons pev(iPlrIdpev_oldbuttons);
 
s_iNewButtons pev(iPlrIdpev_button);
 
 if( !(
s_iOldButtons&IN_JUMP) && s_iNewButtons&IN_JUMP )
 {
  
// player used "+jump"
 
}
 
 if( 
s_iOldButtons&IN_JUMP && !(s_iNewButtons&IN_JUMP) )
 {
  
// player used "-jump"
 
}

full buttons list in second case:
PHP Code:
// pev(entity, pev_button) or pev(entity, pev_oldbuttons) values
#define IN_ATTACK                       (1<<0)
#define IN_JUMP                         (1<<1)
#define IN_DUCK                         (1<<2)
#define IN_FORWARD                      (1<<3)
#define IN_BACK                         (1<<4)
#define IN_USE                          (1<<5)
#define IN_CANCEL                       (1<<6)
#define IN_LEFT                         (1<<7)
#define IN_RIGHT                        (1<<8)
#define IN_MOVELEFT                     (1<<9)
#define IN_MOVERIGHT                    (1<<10)
#define IN_ATTACK2                      (1<<11)
#define IN_RUN                          (1<<12)
#define IN_RELOAD                       (1<<13)
#define IN_ALT1                         (1<<14)
#define IN_SCORE                        (1<<15)     // Used by client.dll for when scoreboard is held down 
__________________
Skill and no annoying bugs with fixed balance issues is my goal!
My approved plugins what don't show up in Approved List:
* Bomb/Death/CSS Radar
* HotVision
___
Need help? Please check this documentation first.
MPNumB is offline
Send a message via Skype™ to MPNumB
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-05-2009 , 22:46   Re: Create a +button
Reply With Quote #3

You sure something that simple works? It looks like that would just call the function once when the button is pressed, not call it continuously as the button is held down, like the game's +buttons: +attack, +duck, etc.

I saw a jetpack plugin on here once (can't find it now ) that had a module included to add a +jetpack button. I'm thinking it may be more complicated than what you've suggested, unless you can convince me otherwise.

Trying it now -- will get back to you, sonny boy!

Back: Sorry, it doesn't work as intended. It just calls the function once per press/hold. It does not have a hold/release like real hl +buttons.
__________________

Last edited by Bad_Bud; 01-05-2009 at 22:57.
Bad_Bud is offline
MPNumB
Veteran Member
Join Date: Feb 2007
Location: Lithuania
Old 01-05-2009 , 22:53   Re: Create a +button
Reply With Quote #4

Just save in some variable that user is holding a button and check it every time when you need/want. Jatpack is just using playerprethink:

PHP Code:
if( pev(idpev_button)&IN_ALT )
{
 
// set speed by angle...

or if another version...

PHP Code:
if( bIsUserInJat[id] )
{
 
// set speed by angle

===

Anyway, if you wanna reapeat the function just use playerprethink (althow I'm not recomending to do that, cuz of the fps + cl_cmdrate, but ...) just use some loop function... it isn't hard.
__________________
Skill and no annoying bugs with fixed balance issues is my goal!
My approved plugins what don't show up in Approved List:
* Bomb/Death/CSS Radar
* HotVision
___
Need help? Please check this documentation first.
MPNumB is offline
Send a message via Skype™ to MPNumB
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-05-2009 , 22:59   Re: Create a +button
Reply With Quote #5

Ah, I think I understand what you mean now.

Thanks a lot, man. I can go update my plugin now.
__________________

Last edited by Bad_Bud; 01-05-2009 at 23:24.
Bad_Bud is offline
Reply


Thread Tools
Display Modes

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 09:05.


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