Time Help.
#1

Hi,I just made the command "/heal" But I don`t want them to abuse it. So How can I make it for example after 1 minute? or if they try to abuse it,it will say "Please wait another 1 minute before using /heal again"

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/heal", cmdtext, true, 10) == 0)
	{
	if(IsPlayerVipType(playerid,3)) /// PREMIUM VIP
	{
	SetPlayerHealth(playerid, 10);
	}
	else SendClientMessage(playerid, COLOR_RED, "ERROR: You Are Not A Premium Vip Member!");
	return 1;
	}
	return 0;
}
Reply
#2

Create :

pawn Код:
new Health[MAX_PLAYERS]; // At top
Put this in the command :

pawn Код:
Health[playerid] = 1;
Then set a timer in the command like this :

pawn Код:
SetTimerEx("EndHealthAbuse", 60000, false, "i", playerid);
Then in the bottom of the gamemode :

pawn Код:
forward EndHealthAbuse(playerid);
public EndHealthAbuse(playerid)
{
    Health[playerid] = 0;
    return 1;
}
Then in your command put this :

pawn Код:
if(Health[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "Please wait another 1 minute before using /heal again");
Should work
Reply
#3

Cheers Bro.. Rep +
Reply
#4

One Problem... It`s saying Please wait 1 minute even though I waited 5 minutes.

Код:
#include <a_samp>
#include <ladmin>
////////////////////////////////
new Float:hp;
new Health[MAX_PLAYERS]; // At top
//////////////////////////////////

/////////////////////////////////////
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_BLUE 0x0000BBAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_RED 0xFF0000FF
/////////////////////////////////////

#if defined FILTERSCRIPT



//////////////////////////////////

#else

//////////////////////////////////

#endif

//////////////////////////////////


public OnPlayerCommandText(playerid, cmdtext[])
{
    Health[playerid] = 1;
    SetTimerEx("EndHealthAbuse", 30000, false, "i", playerid); //// 30 sec to prevent /heal abuse
	if (strcmp("/heal", cmdtext, true, 10) == 0)
	{
	if(IsPlayerVipType(playerid,3)) /// PREMIUM VIP
	{
	if(Health[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "Please wait another 1 minute before using /heal again.");
 	GetPlayerHealth(playerid,hp);
  	SetPlayerHealth(playerid,hp+40); /// 40/100 Health.
	}
	else SendClientMessage(playerid, COLOR_RED, "ERROR: You Are Not A Premium Vip Member!");
	return 1;
	}
	return 0;
}

forward EndHealthAbuse(playerid);
public EndHealthAbuse(playerid)
{
    Health[playerid] = 0;
    return 1;
}
Reply
#5

You dont need
Health[playerid] = 1;
under OnPlayerCommandText. Delete that first line in OnPLayerCommandText and also move the timerEx to the under of SetPlayerHealth

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/heal", cmdtext, true, 10) == 0)
	{
		if(IsPlayerVipType(playerid,3)) /// PREMIUM VIP
		{
			if(Health[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "Please wait another 1 minute before using /heal again.");
		 	GetPlayerHealth(playerid,hp);
		  	SetPlayerHealth(playerid,hp+40); /// 40/100 Health.
		  	Health[playerid] = 1;
		    SetTimerEx("EndHealthAbuse", 30000, false, "i", playerid); //// 30 sec to prevent /heal abuse
		}
	}
	else SendClientMessage(playerid, COLOR_RED, "ERROR: You Are Not A Premium Vip Member!");
	return 1;
	}
	return 0;
}
You were placing it that way the player each time uses /heal command no matter if it works for him it will set Timer and Health cooldown to 1. You have to move it to the place when he actualy is alowed to use the command.

Example:
Код:
CMD:test(playerid, params[])
{
      //If you put anything here it will triger it each time you use the command. If you put timer here it will start it no matter if you are VIP or not.
      if(PlayerInfo[playerid][pVIP] == 3)
      { 
                    //Here we will put what will happen if he is level 3 VIP
      }
}
Reply
#6

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/heal", cmdtext, true, 10) == 0)
    {
        if(IsPlayerVipType(playerid,3)) /// PREMIUM VIP
        {
            if(Health[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "Please wait another 1 minute before using /heal again.");
            GetPlayerHealth(playerid,hp);
            SetPlayerHealth(playerid,hp+40);
            Health[playerid] = 1;
            SetTimerEx("EndHealthAbuse", 30000, false, "i", playerid); /// 40/100 Health.
            return 1;
        }
        else SendClientMessage(playerid, COLOR_RED, "ERROR: You Are Not A Premium Vip Member!");
        return 1;
    }
    return 0;
}
@Pawnie maybe he doesn't need it, but it will help him after some time maybe..

EDIT : Pawnie i provided the code before you, please don't copy and paste things from me.
Reply
#7

Cheers Both Rep ++
Worked!! and thank`s for helping me..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)