SA-MP Forums Archive
Need help with Setting a Timer. - 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: Need help with Setting a Timer. (/showthread.php?tid=549294)



Need help with Setting a Timer. - danielpalade - 06.12.2014

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



Re: Need help with Setting a Timer. - MohanedZzZ - 06.12.2014

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


Re: Need help with Setting a Timer. - lulo356 - 06.12.2014

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



Re: Need help with Setting a Timer. - danielpalade - 06.12.2014

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.


Re: Need help with Setting a Timer. - lulo356 - 06.12.2014

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