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

[TUT] Using Button Constants


Post New Thread Reply   
 
Thread Tools Display Modes
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-28-2010 , 00:12   Re: [TUT] Using Button Constants
Reply With Quote #11

Could you use a while with this?

Like, while they're holding this button do this?

Code:
while(entity_get_int(id,EV_INT_BUTTON) & IN_USE)
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-28-2010 , 00:30   Re: [TUT] Using Button Constants
Reply With Quote #12

Quote:
Originally Posted by nikhilgupta345 View Post
Could you use a while with this?

Like, while they're holding this button do this?

Code:
while(entity_get_int(id,EV_INT_BUTTON) & IN_USE)
No. You should just check over and over each time client_PreThink() (or whatever other function) is called.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-28-2010 , 00:32   Re: [TUT] Using Button Constants
Reply With Quote #13

Could you explain how prethink works? when is it called?
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-28-2010 , 00:43   Re: [TUT] Using Button Constants
Reply With Quote #14

Quote:
Originally Posted by nikhilgupta345 View Post
Could you explain how prethink works? when is it called?
Read the "Game Loop" section in this article:
http://developer.valvesoftware.com/w...initialization

It's for Source, but it applies in this case as well.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-29-2010 , 02:33   Re: [TUT] Using Button Constants
Reply With Quote #15

I'm trying to make it so that while player is holding their use key, soemthing happens. How would I keep checking client prethink? Could you provide an example?
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-29-2010 , 02:37   Re: [TUT] Using Button Constants
Reply With Quote #16

Quote:
Originally Posted by nikhilgupta345 View Post
I'm trying to make it so that while player is holding their use key, soemthing happens. How would I keep checking client prethink? Could you provide an example?
Tell me what you want to do and I'll show you. It depends largely on what it is that you're trying to do.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-29-2010 , 02:41   Re: [TUT] Using Button Constants
Reply With Quote #17

If they are pressing use button next while crosshair on player, the player will get healed.

Code:
new target, body
if(entity_get_int(id,EV_INT_button) & IN_USE)
  {
    get_user_aiming(id, target, body, 50)
    if(is_user_alive(target))
      set_user_health(target, get_user_health(target) + 2)
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-29-2010 , 02:46   Re: [TUT] Using Button Constants
Reply With Quote #18

Your code, as-is, should actually work (assuming everything around it makes sense). The only thing that you should be wary of is that the frequency at which client_PreThink() is called depends on both server and client FPS, so you can get wild fluctuations depending on implementations.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-29-2010 , 02:49   Re: [TUT] Using Button Constants
Reply With Quote #19

How would I make it so that it heals every let's say 2 seconds or something
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-29-2010 , 02:50   Re: [TUT] Using Button Constants
Reply With Quote #20

Here's a better sample:

PHP Code:
// How long between heals, expressed in seconds.
#define DELAY 2.0

// How much they get healed each time.
#define AMOUNT 2

new Float:gLastHeal[33]

public 
client_PreThinkid )
{
    if ( 
get_user_buttonid ) & IN_USE 
    {
        new 
Float:curTime get_gametime()
        if ( 
curTime gLastHeal[id] < DELAY )
            return
        
        
gLastHeal[id] = curTime
        
        
new indexbody
        get_user_aiming
idindexbody)
        
        if ( !
is_user_aliveindex ) )
            return

        
set_user_healthidget_user_healthid ) + AMOUNT )
    }

__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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 08:14.


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