gettickcount.
#1

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.
Reply
#2

Don't use char because it can only store values 0-255 and using GetTickCount returns extremely higher numbers.
Reply
#3

Same problem.
pawn Код:
static tick[MAX_PLAYERS]; //global var
//onplayerupdate
if((GetTickCount() - tick[playerid]) > 5000)
{
    tick[playerid] = GetTickCount();
    //
}
else
{
    SendClientMessage(playerid, -1, "wait");
}
Reply
#4

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.
Reply
#5

Tested with SetTimer. Still doesn't work.
Reply
#6

-.- Tell me what you are trying to do?
Reply
#7

Moving an object with right or left button. Player must wait 5 seconds before pressing it again.
Reply
#8

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;
}
Reply
#9

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.
Reply
#10

I'll just use LMB/RMB with OnPlayerKeyStateChange then :/ After all, no OnPlayerUpdate
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)