Cool down
#1

Hi guys , i need some help i have this code and i want to add a cooldown , player can use it only every minute
Код:
CMD:dive(playerid, params[])
{
    new highness;
	if(sscanf(params,"i",highness))return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");
	if (highness < 100 || highness > 800) return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");//COLOR_BROWN
	SendClientMessage(playerid,COLOR_RED,"You dive. Enjoy.");
	new Float:x,Float:y,Float:z;
	GetPlayerPos(playerid,x,y,z);
	SetPlayerPos(playerid,x,y,z+highness);
	GivePlayerWeapon(playerid, 46, 1);
	SendAdminCMD(playerid, "dive");
	return 1;
}
Reply
#2

PHP код:
new
     
Cooldown[MAX_PLAYERS char];
CMD:dive(playeridparams[]) {
    if(
Cooldown{playerid} > gettime())
        return 
SendClientMessage(playeridCOLOR_GREEN"You already dived!");
    new 
highness;
    if(
sscanf(params,"i",highness))return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");
    if (
highness 100 || highness 800) return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");//COLOR_BROWN
    
SendClientMessage(playerid,COLOR_RED,"You dive. Enjoy.");
    new 
Float:x,Float:y,Float:z;
    
GetPlayerPos(playerid,x,y,z);
    
SetPlayerPos(playerid,x,y,z+highness);
    
GivePlayerWeapon(playerid461);
    
SendAdminCMD(playerid"dive");
    
Cooldown{playerid} = gettime() + 60;
    return 
1;

@oma Your code will still execute and then print the error message.
Reply
#3

PHP код:
CMD:dive(playeridparams[])
{
    new 
highness;
    if(
sscanf(params,"i",highness))return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");
    if (
highness 100 || highness 800) return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");//COLOR_BROWN
    
SendClientMessage(playerid,COLOR_RED,"You dive. Enjoy.");
    new 
Float:x,Float:y,Float:z;
    
GetPlayerPos(playerid,x,y,z);
    
SetPlayerPos(playerid,x,y,z+highness);
    
GivePlayerWeapon(playerid461);
    
SendAdminCMD(playerid"dive");
    if(
GetPVarInt(playerid,"pMIN") > GetTickCount()) return SendClientMessage(playeridCOLOR_GREEN,"You have to wait 1 minutes to use the command again");
    
SetPVarInt(playerid,"pMIN",GetTickCount()+60000); // Minute
    
return 1;

Reply
#4

Код:
new Cmd[MAX_PLAYERS];
CMD:dive(playerid, params[])
{
    if(Cmd[playerid] > gettime())return SendClientMessage(playerid,COLOR_GREEN,"You should wait 1 minute to use this cmd again;");
    new highness;
	if(sscanf(params,"i",highness))return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");
	if (highness < 100 || highness > 800) return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");//COLOR_BROWN
	SendClientMessage(playerid,COLOR_RED,"You dive. Enjoy.");
	new Float:x,Float:y,Float:z;
	GetPlayerPos(playerid,x,y,z);
	SetPlayerPos(playerid,x,y,z+highness);
	GivePlayerWeapon(playerid, 46, 1);
	Cmd[playerid] = gettime() + 60;
        SendAdminCMD(playerid, "dive");
	return 1;
}
Done
test it u can use that cmd once per minute.
Reply
#5

Jamester , Oma both of your codes didnt work for :/ but thank you for the help +rep
Reply
#6

Quote:
Originally Posted by MBilal
Посмотреть сообщение
Код:
new Cmd[MAX_PLAYERS];
CMD:dive(playerid, params[])
{
    if(Cmd[playerid] > gettime())return SendClientMessage(playerid,COLOR_GREEN,"You should wait 1 minute to use this cmd again;");
    new highness;
	if(sscanf(params,"i",highness))return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");
	if (highness < 100 || highness > 800) return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");//COLOR_BROWN
	SendClientMessage(playerid,COLOR_RED,"You dive. Enjoy.");
	new Float:x,Float:y,Float:z;
	GetPlayerPos(playerid,x,y,z);
	SetPlayerPos(playerid,x,y,z+highness);
	GivePlayerWeapon(playerid, 46, 1);
	Cmd[playerid] = gettime() + 60;
        SendAdminCMD(playerid, "dive");
	return 1;
}
Done
test it u can use that cmd once per minute.
Thank You ! it worked !
Reply
#7

Quote:
Originally Posted by Xdrime
Посмотреть сообщение
Jamester , Oma both of your codes didnt work for :/ but thank you for the help +rep
My code is the same as the other guy's code lol.
Reply
#8

Quote:
Originally Posted by Jamester
Посмотреть сообщение
My code is the same as the other guy's code lol.
It is not. You have used char which can only store values 0-255.
Reply
#9

Ah shit! Didn't know about that, sorry!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)