SA-MP Forums Archive
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=379161)



GetTickCount() - Admigo - 20.09.2012

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


Re: GetTickCount() - Admigo - 20.09.2012

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


Re: GetTickCount() - ViniBorn - 20.09.2012

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

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



Re: GetTickCount() - ReneG - 20.09.2012

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;
}



Re: GetTickCount() - Chriham3 - 20.09.2012

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.


Re: GetTickCount() - YourLord - 20.09.2012

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


@timers aren't required, just more work.


Re: GetTickCount() - ReneG - 20.09.2012

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


Re: GetTickCount() - Admigo - 21.09.2012

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.


Re: GetTickCount() - YourLord - 21.09.2012

just use gettime function.