Need help with Setting a Timer.
#1

I am trying to make a /getgift command. But i need to make a timer for it.
Does anyone know how to make one? Please let me know.
Here is my code:

Код:
CMD:getgift(playerid, params[])
{
	if(IsPlayerInRangeOfPoint(playerid, 5.0, 1128.26636, -1450.60254, 14.66266))
	{
	    Random = random(3);
	    switch(Random)
	    {
	        case 0:
	        {
	            GivePlayerMoney(playerid, 250000);
	            SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 250,000$! Merry christmas!");
	        }
	        case 1:
	        {
	            SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
	            SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 1 levelup! Merry christmas!");
	        }
	    }
	}
	else
	{
	    SendClientMessage(playerid, -1, "You are not at the christmas tree!");
	}
	return 1;
}
Reply
#2

Take look at this topic https://sampforum.blast.hk/showthread.php?tid=368931
Reply
#3

pawn Код:
//on the top of your script
new GiftTimer[MAX_PLAYERS];
new GiftgTimer[MAX_PLAYERS];
pawn Код:
CMD:getgift(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 1128.26636, -1450.60254, 14.66266))
    {
        Random = random(3);
        switch(Random)
        {
            case 0:
            {
                GivePlayerMoney(playerid, 250000);
                SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 250,000$! Merry christmas!");
            }
            case 1:
            {
                SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
                SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 1 levelup! Merry christmas!");
            }
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You are not at the christmas tree!");
    }
    GiftTimer[playerid] = 1;
    GiftgTimer[playerid]= SetTimerEx("Giftg", 1000, false, "d", playerid);
    return 1;
}
pawn Код:
//place it on the buttom of your script
forward Giftg(playerid);
public Giftg(playerid)
{
    GiftTimer[playerid] = 0;
    SendClientMessage(playerid,0x42CC33C8, "You have to wait 1 minute to use /getgift again.");
    return 1;
}
Reply
#4

Quote:
Originally Posted by lulo356
Посмотреть сообщение
pawn Код:
//on the top of your script
new GiftTimer[MAX_PLAYERS];
new GiftgTimer[MAX_PLAYERS];
pawn Код:
CMD:getgift(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 1128.26636, -1450.60254, 14.66266))
    {
        Random = random(3);
        switch(Random)
        {
            case 0:
            {
                GivePlayerMoney(playerid, 250000);
                SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 250,000$! Merry christmas!");
            }
            case 1:
            {
                SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
                SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 1 levelup! Merry christmas!");
            }
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You are not at the christmas tree!");
    }
    GiftTimer[playerid] = 1;
    GiftgTimer[playerid]= SetTimerEx("Giftg", 1000, false, "d", playerid);
    return 1;
}
pawn Код:
//place it on the buttom of your script
forward Giftg(playerid);
public Giftg(playerid)
{
    GiftTimer[playerid] = 0;
    SendClientMessage(playerid,0x42CC33C8, "You have to wait 1 minute to use /getgift again.");
    return 1;
}
I have done everything you said. But it won't work :/
I can still use that command whenever i want.
Reply
#5

pawn Код:
//on the top of your script
new GiftTimer[MAX_PLAYERS];
new GiftgTimer[MAX_PLAYERS];
pawn Код:
CMD:getgift(playerid, params[])
{
    if(GiftTimer[playerid] == 1)
    return SendClientMessage(playerid, COLOR_WHITE, "You can use this command after 1 minute again!"); //Sorry, i forgot to check the timer in it.
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 1128.26636, -1450.60254, 14.66266))
    {
        Random = random(3);
        switch(Random)
        {
            case 0:
            {
                GivePlayerMoney(playerid, 250000);
                SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 250,000$! Merry christmas!");
            }
            case 1:
            {
                SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
                SendClientMessage(playerid, 0xFF0000FF ,"[GiftBox:] {FFFFFF}You have received 1 levelup! Merry christmas!");
            }
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You are not at the christmas tree!");
    }
    GiftTimer[playerid] = 1;
    GiftgTimer[playerid]= SetTimerEx("Giftg", 1000, false, "d", playerid);
    return 1;
}
pawn Код:
//place it on the buttom of your script
forward Giftg(playerid);
public Giftg(playerid)
{
    GiftTimer[playerid] = 0;
    SendClientMessage(playerid,0x42CC33C8, "You have to wait 1 minute to use /getgift again.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)