How to set up timer for script
#2

Add this variable globally:
pawn Код:
new bool:giftOpened[playerid] = false;
I tried to optimize your command the way I like it - sorry if that bothers you:
pawn Код:
if (strcmp("/opengift", cmdtext, true, 10) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        if(giftOpened[playerid]) //checks if a gift has been recently opened
            return SendClientMessage(playerid,0xFF0000FF, "ERROR: You have to wait exactly 2 hours before opening another gift");
   
        if(!IsPlayerInRangeOfPoint(playerid, 10.0, -2010.34, 193.34, 27.19))
            return SendClientMessage(playerid,0xFF0000FF,"ERROR: You're not close enough to the gift!");
       
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
           
        if(strcmp(name, "Matija_Isek",true))
            return SendClientMessage(playerid,0xFF0000FF,"You aren't Matija_Isek!");
           
        SendClientMessage(playerid, COLOR_GREEN,"You opened a gift.");
        GivePlayerMoney(playerid, 10000);
        SendClientMessage(playerid, COLOR_GREEN,"You got 10000$.");
        giftOpened[playerid] = true; //gift has been opened, and by setting this to true the if-statement above will come true and the player will be neglected the gift
        SetTimerEx("giftTimer", 2*60*60*1000, false, "i", playerid); //1000 = 1 second * 60 = 1 minute * 60 = 1 hour * 2 = 2 hours
        return 1;
    }
}
And last, put this on the bottom of your script:
pawn Код:
forward giftTimer(playerid);
public giftTimer(playerid)
{
    SendClientMessage(playerid, 0x00FF00FF, "You can now open another gift");
    giftOpened[playerid] = false;
    return true;
}
Reply


Messages In This Thread
How to set up timer for script - by mate213 - 05.12.2012, 01:30
Re: How to set up timer for script - by LarzI - 05.12.2012, 01:42
Re: How to set up timer for script - by mate213 - 05.12.2012, 16:34

Forum Jump:


Users browsing this thread: 1 Guest(s)