In your best interest I have put a timer on it and an anti-spam function.
pawn Код:
#define FindTobacoTime 5000 //Time in milliseconds it takes to find tobaco
forward ProcessTobacoFind(playerid);
pLastTobacoFind[MAX_PLAYERS];
pSpamalot[MAX_PLAYERS];
Float:pLastStand[MAX_PLAYERS][3];
public OnPlayerConnect(playerid)
{
pLastTobacoFind[playerid]=gettick();
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
if(!strcmp(cmdtext[1],"tobaco",true))
{
pSpamalot[playerid]++;
if(pSpamalot[playerid]>5)
{
pLastTobacoFind[playerid]=gettick()+3600000; //3600000 MS = 1 hour, you should probably change this.
pSpamalot[playerid]=0;
SendClientMessage(playerid,0xFF0000FF,"You have spammed, you're banned from this command for 1 hour");
return SendClientMessage(playerid,0xFF0000FF,"Typing the command in more will just make you wait longer.");
}
if(pLastTobacoFind[playerid]>gettick()) return SendClientMessage(playerid,0xFF0000FF,"You cannot do that yet!");
pSpamalot[playerid]=0;
SetTimerEx("ProcessTobacoFind",FindTobacoTime,0,"i",playerid);
pLastTobacoFind[playerid]=gettick();
GetPlayerPos(playerid,pLastStand[playerid][0],pLastStand[playerid][1],pLastStand[playerid][2]);
SendClientMessage(playerid,0xFF0000FF,"You have started looking for tobaco leaves.");
return SendClientMessage(playerid,0xFF0000FF,"If you move, you won't find any.");
}
return 0;
}
public ProcessTobacoFind(playerid)
{
if(IsPlayerInRangeOfPoint(playerid,pLastStand[0],pLastStand[1],pLastStand[2])>0)return SendClientMessage(playerid,0xFF0000FF,"You didn't find any tobaco leaves.");
new temp = random(100);
new find;
if(temp<33)return SendClientMessage(playerid,0xFF0000FF,"You didn't find any tobaco leaves."); //33% chance of failure
else if(temp<70)find = 1; //37% chance to find only 1
else if(temp<90)find = 2; //20% chance to find 2
else find = 3; //10% chance to find 3
new tmpstring[100];
format(tmpstring,sizeof(tmpstring),"You have found %d leave(s).",find);
AddItemToPlayerInventory(playerid,1,find,"Item");//This is YOUR function, not sure how to use it
return SendClientMessage(playerid,0xFF0000FF,tmpstring);
}