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; }
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; }
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; }
Код:
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; } |
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.
|
Wrong calculation change 6800 to 10800, 10800 / 60 = 180, 180 / 60 = 3 hours or 60 * 60 * 3 = 10800 (3 hours)
|
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; }
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.");
new prize = randomEx(1000, 10000);
new tmpstr[128];
format(tmpstr, sizeof(tmpstr), "{FFFF00}You received $%i as a Christmas Gift.", prize);
SCM(playerid,COLOR_WHITE,tmpstr);
GivePlayerCash(playerid, prize);
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;
}