Command Timer + Random Prize [+REP]
#1

Hello,

Well, I want to add a timer for a command so that he can't use it till the specific time (3 hours) pass, and I want to make the money prize random between 1.000$ and 10.000$.
Here's the cmd:

Код:
CMD:getgift(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	{
		if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1022.8253, -1853.5532, 13.5724)) return SendClientMessage(playerid, COLOR_GREY, "You are not at /getgift location.");
		SCM(playerid,COLOR_WHITE,"{FFFF00}You received 5000$ as a Christmas Gift.");
		GivePlayerCash(playerid,5000);
		Update(playerid, pCashx);
	}
	return 1;
}
Thanks for your help!
Reply
#2

This should work, I didn't compile or test it, if you find anything wrong reply

Код:
new giftCooldown[MAX_PLAYERS]; // In top of your script
		
CMD:getgift(playerid, params[]) // in your commands
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	{
		new currenttime = gettime();
		if(currenttime < (giftCooldown[playerid] + 6480)) return SendClientMessage(playerid, COLOR_GREY, "Wait before using the command again");
		if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1022.8253, -1853.5532, 13.5724)) return SendClientMessage(playerid, COLOR_GREY, "You are not at /getgift location.");
		SCM(playerid,COLOR_WHITE,"{FFFF00}You received 5000$ as a Christmas Gift.");
	GivePlayerCash(playerid, randomEx(1000, 10000));
		Update(playerid, pCashx);
		giftCooldown[playerid] = gettime();
	}
	return 1;
}	
randomEx(min, max) // where you put your functions or under the command
{
    new rand = random (max - min) + min;
    return rand;
}
Reply
#3

Код:
new bool:playercanGetGift[MAX_PLAYERS]; //put this on top of your script

forward getgift(playerid);
public getgift(playerid)
{
	playercanGetGift[playerid] = true;
}

CMD:getgift(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	{
		if(playercanGetGift[playerid] == true)
                {
			if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1022.8253, -1853.5532, 13.5724)) return SendClientMessage(playerid, COLOR_GREY, "You are not at /getgift location.");
			SCM(playerid,COLOR_WHITE,"{FFFF00}You received 5000$ as a Christmas Gift.");
			GivePlayerCash(playerid,5000);
			Update(playerid, pCashx);
                        SetTimerEx("getgift", 10800000, false, "d", playerid); // timer 3 hours or you can edit it to 1000 * 60 * 60 * 3
                        playercanGetGift[playerid] = false;
		}
                else
		{
			SCM(playerid, COLOR_WHITE, "{FFFF00}You can only get gift every 3 hours.");
		}
	}
	return 1;
}
Reply
#4

Quote:
Originally Posted by SilverStand
Посмотреть сообщение
Код:
new bool:playercanGetGift[MAX_PLAYERS]; //put this on top of your script

forward getgift(playerid);
public getgift(playerid)
{
	playercanGetGift[playerid] = true;
}

CMD:getgift(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	{
		if(playercanGetGift[playerid] == true)
                {
			if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1022.8253, -1853.5532, 13.5724)) return SendClientMessage(playerid, COLOR_GREY, "You are not at /getgift location.");
			SCM(playerid,COLOR_WHITE,"{FFFF00}You received 5000$ as a Christmas Gift.");
			GivePlayerCash(playerid,5000);
			Update(playerid, pCashx);
                        SetTimerEx("getgift", 10800000, false, "d", playerid); // timer 3 hours or you can edit it to 1000 * 60 * 60 * 3
                        playercanGetGift[playerid] = false;
		}
                else
		{
			SCM(playerid, COLOR_WHITE, "{FFFF00}You can only get gift every 3 hours.");
		}
	}
	return 1;
}
1. He also asked for random money
2. Using timers for cooldowns is not safe and it will lead to false results, gettime is better (Check my code if you don't about what I am speaking)
Reply
#5

Quote:
Originally Posted by SecretBoss
Посмотреть сообщение
This should work, I didn't compile or test it, if you find anything wrong reply

Код:
new giftCooldown[MAX_PLAYERS]; // In top of your script
		
CMD:getgift(playerid, params[]) // in your commands
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	{
		new currenttime = gettime();
		if(currenttime < (giftCooldown[playerid] + 6480)) return SendClientMessage(playerid, COLOR_GREY, "Wait before using the command again");
		if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1022.8253, -1853.5532, 13.5724)) return SendClientMessage(playerid, COLOR_GREY, "You are not at /getgift location.");
		SCM(playerid,COLOR_WHITE,"{FFFF00}You received 5000$ as a Christmas Gift.");
	GivePlayerCash(playerid, randomEx(1000, 10000));
		Update(playerid, pCashx);
		giftCooldown[playerid] = gettime();
	}
	return 1;
}	
randomEx(min, max) // where you put your functions or under the command
{
    new rand = random (max - min) + min;
    return rand;
}
Thanks for your help, now just one small question, the 6800 represent 3 hours ? cause I want to fix the SCM and add how much time left for him to use the cmd.
Reply
#6

Quote:
Originally Posted by EgyptForLife
Посмотреть сообщение
Thanks for your help, now just one small question, the 6800 represent 3 hours ? cause I want to fix the SCM and add how much time left for him to use the cmd.
Wrong calculation change 6800 to 10800, 10800 / 60 = 180, 180 / 60 = 3 hours or 60 * 60 * 3 = 10800 (3 hours)
Reply
#7

Quote:
Originally Posted by SecretBoss
Посмотреть сообщение
Wrong calculation change 6800 to 10800, 10800 / 60 = 180, 180 / 60 = 3 hours or 60 * 60 * 3 = 10800 (3 hours)
Ok and about the money bonus gained, how to set instead of saying 5.000$ the exact prize that he got ?
Reply
#8

Код:
CMD:getgift(playerid, params[]) // in your commands
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	{
		new currenttime = gettime();
		if(currenttime < (giftCooldown[playerid] + 6480)) return SendClientMessage(playerid, COLOR_GREY, "Wait before using the command again");
		if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1022.8253, -1853.5532, 13.5724)) return SendClientMessage(playerid, COLOR_GREY, "You are not at /getgift location.");
		SCM(playerid,COLOR_WHITE,"{FFFF00}You received 5000$ as a Christmas Gift.");
		
		new moneyToGive, string[88];
		moneyToGive = randomEx(1000, 10000);
		GivePlayerCash(playerid, moneyToGive);
		format(string, sizeof(string), "{B7B7B7}[SERVER] {FFFFFF}You received %i as gift, merry christmas", moneyToGive);
		SendClientMessage(playerid, -1, string);
		
		Update(playerid, pCashx);
		giftCooldown[playerid] = gettime();
	}
	return 1;
}
Reply
#9

PHP код:
new giftCooldown[MAX_PLAYERS]; // In top of your script
        
CMD:getgift(playeridparams[]) // in your commands
{
    if(
gPlayerLogged[playerid] == 0) return SendClientMessage(playeridCOLOR_LIGHTRED"You need to login first.");
    {
        new 
currenttime gettime();
        if(
currenttime < (giftCooldown[playerid] + 6480)) return SendClientMessage(playeridCOLOR_GREY"Wait before using the command again");
        if(!
IsPlayerInRangeOfPoint(playerid7.01022.8253, -1853.553213.5724)) return SendClientMessage(playeridCOLOR_GREY"You are not at /getgift location.");
        new 
prize randomEx(100010000);
        new 
tmpstr[128];
        
format(tmpstrsizeof(tmpstr), "{FFFF00}You received $%i as a Christmas Gift."prize);
        
SCM(playerid,COLOR_WHITE,tmpstr);
        
GivePlayerCash(playeridprize);
        
Update(playeridpCashx);
        
giftCooldown[playerid] = gettime();
    }
    return 
1;
}    
randomEx(minmax// where you put your functions or under the command
{
    new 
rand random (max min) + min;
    return 
rand;

Someone answered above, xD.
Reply
#10

Thanks for your help guys! +REP given!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)