How to avoid CMD SPAM?
#1

PHP код:

CMD
:suicide(playerid)
{
    if(
pInfo[playerid][pIsPlayerLogged] == false) return SendClientMessage(playerid,-1,"*"COL_RED" You haven't logged-in yet!");
    if(
pInfo[playerid][pIsPlayerSpawned] == false) return SendClientMessage(playerid,-1,"*"COL_RED" You are not spawned yet!");
    if(
pInfo[playerid][pHours] < 5) return SendClientMessage(playerid, -1"*"COL_RED" You need at least 5 hour IG time to use this command!"); 
    
SetPlayerHealth(playerid0.0);
    
SendClientMessage(playerid, -1"*"COL_RED" You have commited suicide!");
    return 
CMD_SUCCESS;

You can only use the command every 30 minutes, I want tha. I just don't know how. If it's not yet 30 minutes then it'll send a message "You can only commit suicide once every 30 minutes".


Thanks.
Reply
#2

Код:
CMD:suicide(playerid) 
{ 
    if(pInfo[playerid][pIsPlayerLogged] == false) return SendClientMessage(playerid,-1,"*"COL_RED" You haven't logged-in yet!"); 
    if(pInfo[playerid][pIsPlayerSpawned] == false) return SendClientMessage(playerid,-1,"*"COL_RED" You are not spawned yet!"); 
    if(pInfo[playerid][pHours] < 5) return SendClientMessage(playerid, -1, "*"COL_RED" You need at least 5 hour IG time to use this command!");  

    if(GetPVarInt(playerid, "UsedSucide") ==1)
    {
	   GameTextForPlayer(playerid, "~w~You can only commit suicide once every 30 minutes", 3000, 3);
	   return true;
    }
    SetPVarInt(playerid, "UsedSucide", 1);
    SetTimerEx("UsedSucide", 30*60000, false, "i", playerid);
    SetPlayerHealth(playerid, 0.0); 
    SendClientMessage(playerid, -1, "*"COL_RED" You have commited suicide!"); 

    return CMD_SUCCESS; 

}

forward UsedSucide(playerid);
public UsedSucide(playerid)
{
	if(IsPlayerConnected(playerid)) DeletePVar(playerid, "UsedSucide");
}
try this
Reply
#3

I don't see you should be doing all this for such thing, all you have to do is make a global per player variable, save in that variable every time the last timestamp when the cmd was used ( Variable[playerid]=gettime(); ) and check on the starting of the cmd, so basically your cmd will look like (I am writing from mobile):
PHP код:
new LastUsed[MAX_PLAYERS];
CMD:mycmd(playeridparams[] )
{
if ((
gettime()-LastUsed[playerid])<cool_down_seconds) return error;
//rest of code
LastUsed[playerid]=gettime();
return 
1;

Reply
#4

Quote:
Originally Posted by UFF
Посмотреть сообщение
Код:
CMD:suicide(playerid) 
{ 
    if(pInfo[playerid][pIsPlayerLogged] == false) return SendClientMessage(playerid,-1,"*"COL_RED" You haven't logged-in yet!"); 
    if(pInfo[playerid][pIsPlayerSpawned] == false) return SendClientMessage(playerid,-1,"*"COL_RED" You are not spawned yet!"); 
    if(pInfo[playerid][pHours] < 5) return SendClientMessage(playerid, -1, "*"COL_RED" You need at least 5 hour IG time to use this command!");  

    if(GetPVarInt(playerid, "UsedSucide") ==1)
    {
	   GameTextForPlayer(playerid, "~w~You can only commit suicide once every 30 minutes", 3000, 3);
	   return true;
    }
    SetPVarInt(playerid, "UsedSucide", 1);
    SetTimerEx("UsedSucide", 30*60000, false, "i", playerid);
    SetPlayerHealth(playerid, 0.0); 
    SendClientMessage(playerid, -1, "*"COL_RED" You have commited suicide!"); 

    return CMD_SUCCESS; 

}

forward UsedSucide(playerid);
public UsedSucide(playerid)
{
	if(IsPlayerConnected(playerid)) DeletePVar(playerid, "UsedSucide");
}
try this
REALLY? So much for something so simple?
Reply
#5

Quote:
Originally Posted by Undef1ned
Посмотреть сообщение
REALLY? So much for something so simple?
Well, let it be an alternative method.
Reply
#6

pawn Код:
if(GetPVarInt(playerid,"CmdTime")>GetTickCount()) return SCM(playerid,COLOR_RED,"* Please wait before using this command again.");
SetPVarInt(playerid,"CmdTime",GetTickCount()+10000);
Reply
#7

I would suggest you to use ILearner's Code.
Using a timer for such a task is not smart
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)