How to set up timer for script
#1

Hello, I need help with one script. This is script for presents, and everithing is working but problem is that player must have some limit with opening gifts, he can opet gift once now and again in two hours, but there is problem, he can open gifts when ever he wants. So when he type /opengift he must get money. Here is script
Код:
#include <a_samp>
#include <streamer>


#define COLOR_GREEN 0x9EC73DAA
#define FILTERSCRIPT

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    CreateDynamicObject(19058, -2010.34, 193.34, 27.19,   0.00, 0.00, 0.00);
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#else

main()
{
	print("\n----------------------------------");
	print(" Blank Gamemode by your name here");
	print("----------------------------------\n");
}

#endif




public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/opengift", cmdtext, true, 10) == 0)
	{
		if(IsPlayerConnected(playerid))
		{
			if(IsPlayerInRangeOfPoint(playerid, 10.0, -2010.34, 193.34, 27.19))
			{
				new name[MAX_PLAYER_NAME];
				GetPlayerName(playerid, name, sizeof(name));
				if(strcmp(name, "Matija_Isek",true)==0)
				{
					SendClientMessage(playerid, COLOR_GREEN,"You opened a gift.");
					GivePlayerMoney(playerid, 10000);
					SendClientMessage(playerid, COLOR_GREEN,"You got 10000$.");
					return 1;
 					}
	 				else
					{
					SendClientMessage(playerid,0xFF0000FF,"You aren't Matija_Isek!");
					return 1;
				}
			}
			else return SendClientMessage(playerid,0xFF0000FF,"ERROR: You're not close enough to the gift!");
		}
		return 1;
	}
	return 0;
}
Reply
#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
#3

Thanks man, its working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)