GetTickCount()
#1

Heey all,

How to use GetTickCount with HasRobbedRecently[playerid]=value so the player has to wait 60 seconds to rob again?
Can someone give me a example of the 60 seconds please.

Admigo
Reply
#2

Got it:
Код:
HasRobbedShopRecently[playerid] = GetTickCount()+60000;
How to make the tickcount increasing 1 second every second so i can make a better gametime system?
Reply
#3

Ex:
pawn Код:
CMD:rob(playerid, params[])
{
    if(HasRobbedShopRecently[playerid] > GetTickCount())
        return SendClientMessage(playerid, -1, "Wait...");

    HasRobbedShopRecently[playerid] = GetTickCount()+60000;
    //Functions
    return true;
}
Reply
#4

GetTickCount() returns how many milliseconds your server.exe has been running.

gettime() would be better because it returns the time in seconds that have passed since Jan 1, 1970.

Here is an example heal command using gettime(), that can only be used every 10 seconds.
pawn Код:
new gHealTime[MAX_PLAYERS];

CMD:heal(playerid, params[])
{
    if(gHealTime[playerid] <= gettime())
    {
        SetPlayerHealth(playerid, 100.0);
        gHealTime[playerid] = gettime() + 10;
        SendClientMessage(playerid, -1, "You have been healed.");
    }
   
    else
    {
        SendClientMessage(playerid, -1, "You can only use this command every 10 seconds.");
    }

    return 1;
}
Reply
#5

Alternatively you could use:
pawn Код:
forward ResetRob(playerid);
public ResetRob(playerid)
{
        HasRobbedShopRecently[playerid] = 0;
}
pawn Код:
stock IsNearStore(playerid)
{
        if(IsPlayerInRangeOfPoint(playerid, 5, ##COORDX##, ##COORDY##, ##COORDZ##)) return 1; // Store 1 replace COORDX, Y and Z with the coordinates of the shop.
        if(IsPlayerInRangeOfPoint(playerid, 5, ##COORDX##, ##COORDY##, ##COORDZ##)) return 1; // Store 2 replace COORDX, Y and Z with the coordinates of the shop.
        if(IsPlayerInRangeOfPoint(playerid, 5, ##COORDX##, ##COORDY##, ##COORDZ##)) return 1; // Store 3 replace COORDX, Y and Z with the coordinates of the shop.
        if(IsPlayerInRangeOfPoint(playerid, 5, ##COORDX##, ##COORDY##, ##COORDZ##)) return 1; // Store 4 replace COORDX, Y and Z with the coordinates of the shop.
        return 0;
}

pawn Код:
CMD:rob(playerid, params[])
{
        if(HasRobbedShopRecently[playerid] != 0) return SendClientMessage(playerid, -1, "You have already robbed a shop the last 60 seconds."); // if the value is not 0, show this message.
        if(!IsNearStore(playerid)) return SendClientMessage(playerid, -1, "You are not near a store.");
        HasRobbedShopRecently[playerid] = 1; // Shop has been robbed recently.
        new rand, str[100];
        rand = random(2000);
        GivePlayerMoney(playerid, rand); // Give a random value between 1-2000.
        format(str, sizeof(str), "You have robbed the shop and you managed to take $%i.", rand); // format the string
        SendClientMessage(playerid, -1, str); // send the string
        SetTimerEx("ResetRob", 60000, false, "i", playerid); // Set a non-looping timer on 60000 ms (60 sec) to ResetRob(playerid);
        return 1;
}
Sorry if there is any mistakes, I just made this here and now without compiling.
Reply
#6

VincentDunn, don't need to check if it's 0, cause gettime will always be bigger.


@timers aren't required, just more work.
Reply
#7

Quote:
Originally Posted by YourLord
Посмотреть сообщение
VincentDunn, don't need to check if it's 0, cause gettime will always be bigger.
Great observation.
Reply
#8

How can i make a gametimer with GetTickCount?
Example:
pawn Код:
if(gMinute==60)
{
    //1 hour passed
}
if(gMinute==120)
{
    //2 hour passed
}
if(gMinute==1440)
{
    //1 day passed
    gDay++;
}
Rep for the code.
Reply
#9

just use gettime function.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)