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

Counting key press time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LynX
Veteran Member
Join Date: Oct 2004
Old 12-20-2004 , 04:33   Counting key press time
Reply With Quote #1

Is there a way that when you press a binded key, let's say named "charge" , and then when you keep your finger on it, and then how much seconds you keeped pushing it, that function you got. Example:
I want to get more health.

So, I push button "health" - if I kept pressed it for 1 second, I got 10 health, if I pushed it 2 seconds, I got 20 health, etc.
Is this possible?
__________________
Current plugin : SoulPunisher anti-cheat
Percentage done : {||--------} 20%

If you think v3x is a PIMP, paste this into your sig!

If you think Bailopan is DA BOMB, paste this into your sig
LynX is offline
Send a message via ICQ to LynX
mobytoss
Senior Member
Join Date: Jun 2004
Location: On my TS server
Old 12-20-2004 , 05:06  
Reply With Quote #2

well yeah. If you made some commands using + and -, using set_task() with a function that gave you 10 HP everytime it ran through, it'd work you'd just need to bind to the + command.
__________________
"As we know, There are known knowns. There are things we know we know. We also know There are known unknowns. That is to say We know there are some things We do not know. But there are also unknown unknowns, The ones we don't know We don't know."
mobytoss is offline
Ronkkrop
Member
Join Date: May 2004
Old 12-20-2004 , 05:55  
Reply With Quote #3

set_task is a poor way to do it. Only use set_task if you have to. One thing he right about is using a +command, and a -command. What you could do is register a command.

Then using an array for every player (of size 32), dump the systemtime in there, do that on a +command. On the -command, get the systime again and compare the times and see how much time went by, then multiply the amount of seconds that went by, by 10.

example:
Code:
#include <amxmodx> #include <fun> new iTime[32] = { 0, ... }; public plugin_init(){     register_plugin("+Health","0.1","Cr!Z");     register_clcmd("+health", "health_gettime");     register_clcmd("-health", "health_give"); } public health_gettime( id ){     iTime[id] = get_systime();     return PLUGIN_HANDLED; } public health_give( id ){     new iCurrentHealth = get_user_health( id );     new tempTime = get_systime();     new iHealth = (tempTime - iTime[id]) * 10  + iCurrentHealth;     if ( iHealth > 100 ) iHealth = iCurrentHealth;     if ( iHealth != 0 ) set_user_health( id, iHealth );     iTime[id] = 0;     return PLUGIN_HANDLED; }

Now, that may work, it may not. If it doesn't work, its because amxmodx cant handle +/- commands because the client doesn't send the + or -. But im betting it does.
__________________
"I refuse to join any club that would have me as a member."
--Groucho Marx
Ronkkrop is offline
Send a message via ICQ to Ronkkrop Send a message via AIM to Ronkkrop Send a message via MSN to Ronkkrop Send a message via Yahoo to Ronkkrop
mobytoss
Senior Member
Join Date: Jun 2004
Location: On my TS server
Old 12-20-2004 , 07:00  
Reply With Quote #4

Hmm, ok, I'll have to remember that in future ^.^
One thing about that code though. If he's holding down the key, then he wants to know hes gettting health, while holding it down, like the healthchargers in HL, so he can tell how much he's gained, rather than getting it in one big lump at the end.
__________________
"As we know, There are known knowns. There are things we know we know. We also know There are known unknowns. That is to say We know there are some things We do not know. But there are also unknown unknowns, The ones we don't know We don't know."
mobytoss is offline
Ronkkrop
Member
Join Date: May 2004
Old 12-20-2004 , 07:56  
Reply With Quote #5

Quote:
Originally Posted by mobytoss
Hmm, ok, I'll have to remember that in future ^.^
One thing about that code though. If he's holding down the key, then he wants to know hes gettting health, while holding it down, like the healthchargers in HL, so he can tell how much he's gained, rather than getting it in one big lump at the end.
for that, you'd have to use a set_task set every second, and the -health removes the task. I dont like it though...
__________________
"I refuse to join any club that would have me as a member."
--Groucho Marx
Ronkkrop is offline
Send a message via ICQ to Ronkkrop Send a message via AIM to Ronkkrop Send a message via MSN to Ronkkrop Send a message via Yahoo to Ronkkrop
mobytoss
Senior Member
Join Date: Jun 2004
Location: On my TS server
Old 12-20-2004 , 09:23  
Reply With Quote #6

Hmm, Im sure you *could* do it with your method though.
__________________
"As we know, There are known knowns. There are things we know we know. We also know There are known unknowns. That is to say We know there are some things We do not know. But there are also unknown unknowns, The ones we don't know We don't know."
mobytoss is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 12-20-2004 , 12:08  
Reply With Quote #7

Couldn't you fool around with get_user_button.... something like

Code:
while(get_user_button(id)&"charge")
__________________
Anything that is done can only be done better by urself - since life is a opinion make it the way urs feel its best

~live by it
Da Bishop is offline
Send a message via MSN to Da Bishop
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 12-20-2004 , 12:15  
Reply With Quote #8

Quote:
Originally Posted by Da Bishop
Couldn't you fool around with get_user_button.... something like

Code:
while(get_user_button(id)&"charge")
Erm... get_user_button only works for built-in commands and "charge" would need to be an integer and not a string anyway

The best idea is storing the start time on +stuff , and computing current time - start time on -stuff..
__________________
hello, i am pm
PM is offline
LynX
Veteran Member
Join Date: Oct 2004
Old 12-20-2004 , 15:19  
Reply With Quote #9

Wow! So much replies !!!

Anyway, mine idea is that it doesn't happen while its charging, when you are charging you shouldn't be able to see it.
Lets say, guys is charging 10 seconds. He gets 100 health! But he gets 100 health AFTER he charged up, not that he gets 10 health for every second immediateley, because this thing I'm working on is tricky, and one function is called only if 1 second chargetime. If I make it like getting each time function 1 for 1 second, you wouldn't be able to get function 2 & 3, etc. I'll try, thanks for the help guys.
__________________
Current plugin : SoulPunisher anti-cheat
Percentage done : {||--------} 20%

If you think v3x is a PIMP, paste this into your sig!

If you think Bailopan is DA BOMB, paste this into your sig
LynX is offline
Send a message via ICQ to LynX
Ronkkrop
Member
Join Date: May 2004
Old 12-20-2004 , 16:11  
Reply With Quote #10

Quote:
Originally Posted by LynX
Wow! So much replies !!!

Anyway, mine idea is that it doesn't happen while its charging, when you are charging you shouldn't be able to see it.
Lets say, guys is charging 10 seconds. He gets 100 health! But he gets 100 health AFTER he charged up, not that he gets 10 health for every second immediateley, because this thing I'm working on is tricky, and one function is called only if 1 second chargetime. If I make it like getting each time function 1 for 1 second, you wouldn't be able to get function 2 & 3, etc. I'll try, thanks for the help guys.

the code snippet above does just that. It doesn't show the health change at all until after they stop pressing it.
__________________
"I refuse to join any club that would have me as a member."
--Groucho Marx
Ronkkrop is offline
Send a message via ICQ to Ronkkrop Send a message via AIM to Ronkkrop Send a message via MSN to Ronkkrop Send a message via Yahoo to Ronkkrop
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 07:06.


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