gettickcount. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: gettickcount. (
/showthread.php?tid=494496)
gettickcount. -
newbienoob - 13.02.2014
I've spent almost 1 hour trying to fix this shit
pawn Код:
static tick[MAX_PLAYERS char]; //global var
//onplayerupdate
if((GetTickCount() - tick{playerid}) > 5000)
{
tick{playerid} = GetTickCount();
//
}
else
{
SendClientMessage(playerid, -1, "wait");
}
I didn't get the "wait" message.
Re: gettickcount -
Konstantinos - 13.02.2014
Don't use
char because it can only store values 0-255 and using GetTickCount returns extremely higher numbers.
Re: gettickcount. -
newbienoob - 13.02.2014
Same problem.
pawn Код:
static tick[MAX_PLAYERS]; //global var
//onplayerupdate
if((GetTickCount() - tick[playerid]) > 5000)
{
tick[playerid] = GetTickCount();
//
}
else
{
SendClientMessage(playerid, -1, "wait");
}
Re: gettickcount. -
Yashas - 13.02.2014
You will never get the wait message until you pause for 5 seconds(by pause I mean you press ESC).
Please tell what you are trying to do and we'll help you out writing that code.
EDIT:Player Updates are sent many times in a second until the player pauses.
Re: gettickcount. -
newbienoob - 13.02.2014
Tested with SetTimer. Still doesn't work.
Re: gettickcount. -
Yashas - 13.02.2014
-.- Tell me what you are trying to do?
Re: gettickcount. -
newbienoob - 13.02.2014
Moving an object with right or left button. Player must wait 5 seconds before pressing it again.
Re: gettickcount. - Patrick - 13.02.2014
I suggest you using
gettime instead of
GetTickCount,
GetTickCount returns in
milliseconds and
gettime returns in
seconds, also check the
disadvantages about
GetTickCount, you also need a new variable, so the message won't spam. example code below.
pawn Код:
#include <a_samp>
#if defined MAX_PLAYERS
#undef MAX_PLAYERS
#define MAX_PLAYERS (255)
#endif
static stock
tick[ MAX_PLAYERS char ], bool:tickSpam[ MAX_PLAYERS char];
public OnPlayerUpdate(playerid)
{
if( (gettime( ) - tick{playerid} > 5) && ( !tickSpam{ playerid } ) )
{
tickSpam{ playerid } = true;
SendClientMessage( playerid, -1, "Command Status: UnAvailable" );
}
else if( (gettime( ) - tick{ playerid } < 5) && ( tickSpam{ playerid } ) )
{
tickSpam{ playerid } = false;
SendClientMessage( playerid, -1, "Command Status: Available" );
}
return true;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_ACTION)
{
// rest of the code.
tick{ playerid } = gettime( );
}
return true;
}
Re: gettickcount. -
Yashas - 13.02.2014
You need to check if the RMB or LMB was pressed and an object was moved.
And you can instead use OnPlayerKeyStateChange instead of OnPlayerUpdate.
Refer to this link for checking key presses.
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Your current code just keeps setting a variable and spams the user with a message if the player pauses for more than 5 seconds.Your code is more like an anti-pause system.
Re: gettickcount. -
newbienoob - 13.02.2014
I'll just use LMB/RMB with OnPlayerKeyStateChange then :/ After all, no OnPlayerUpdate