Pressing a key, an amount of times. -
JamesS - 15.02.2013
Well, i'm creating some kind of a medic script currently, and I need the player to hit a key specific amount of times, for instance, pressing the space bar 20 times. Now, this has to happen in about 20 seconds. Is there any way to get this done? I've been searching around, but I can't really find a solution, if anyone could help me, thanks a lot!
Re: Pressing a key, an amount of times. -
2KY - 15.02.2013
pawn Код:
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
Set a timer for 20 seconds, create a new variable like so...
pawn Код:
new TimesPressed [ MAX_PLAYERS ] = 0, TimerActive [ MAX_PLAYERS ] = 0;
SetTimerEx ( "PressedNumberofTimes", 20000, false, "i", playerid );
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if( PRESSED ( KEY_SPRINT ) )
{
if( TimerActive [ playerid ] == 1 )
{
TimesPressed [ playerid ] ++;
}
}
return true;
}
forward PressedNumberofTimes ( playerid );
public PressedNumberofTimes ( playerid )
{
if( TimesPressed [ playerid ] >= 20 )
{
// Success!
TimesPressed [ playerid ] = 0;
}
else
{
// Failure!
}
return true;
}
Re: Pressing a key, an amount of times. -
JamesS - 15.02.2013
Thanks man, Didn't know about the TimerActive thinggy.
Re: Pressing a key, an amount of times. -
2KY - 15.02.2013
It's just a variable that tells the game you want to use the timer. Without it, you'd just spam space a million times and it would continuously succeed.
Re: Pressing a key, an amount of times. -
MP2 - 15.02.2013
Quote:
Originally Posted by ******
Except you don't explain where to start the timer. You don't even need a timer, just GetTickCount.
|
I assume he wants to show a message to the player saying 'press space 20 times' then do this script, and after 20 seconds wants to show a 'failed' message if they failed. You need a timer for that.
Also, a timer is easier. The most efficient way isn't always the
best way, especially for a beginner.
Re: Pressing a key, an amount of times. -
2KY - 15.02.2013
Quote:
Originally Posted by ******
Except you don't explain where to start the timer. You don't even need a timer, just GetTickCount.
|
I thought that was pretty obvious, and why would I use GetTickCount? I've never even thought of beginning to use it because of this:
Quote:
GetTickCount will cause problems on servers with uptime of over 24 days (SA:MP server, not physical server !!!) as GetTickCount will eventually warp past the integer size constraints
|
Re: Pressing a key, an amount of times. -
Scenario - 15.02.2013
Quote:
Originally Posted by 2KY
I thought that was pretty obvious, and why would I use GetTickCount? I've never even thought of beginning to use it because of this:
|
In my experience, servers tend to be restarted WAY before approaching the 24 day period.
Re: Pressing a key, an amount of times. -
2KY - 15.02.2013
Quote:
Originally Posted by RealCop228
In my experience, servers tend to be restarted WAY before approaching the 24 day period.
|
Quote:
Originally Posted by ******
I didn't. Anyway, GetTickCount doesn't cause issues unless you do something stupid (and who leaves a server running that long anyway - they are almost always rebooted in that time).
|
It's the physical server, boxes generally aren't restarted unless there's a problem in my experience at least.
Anyway, just figured a timer would suffice rather than try to use a function which could potentially bug out. There's a line between optimized and OCD, and GetTickCount vs. a 20 second timer is approaching that line.
Re: Pressing a key, an amount of times. -
Scenario - 15.02.2013
Quote:
Originally Posted by 2KY
It's the physical server
|
Mate...
Quote:
SA:MP server, not physical server !!!
|
Re: Pressing a key, an amount of times. -
2KY - 15.02.2013
Quote:
Originally Posted by RealCop228
Mate...
|
Quote:
Originally Posted by ******
This was quoted in YOUR post:
|
Man, that's just bad on my part.
That's what I get for blindly copy-pasting something because I thought I had read it before. Fair enough, you guys are right, but I still stand behind my decision to use a timer, not like it really matters all that much.