Help with a timer to use the command per minute.
#1

Hello again. I need some help creating a timer to use the command once per minute So players can't spam it.

pawn Код:
if(strcmp(cmdtext, "/fart", true) == 0) {
new pName[MAX_PLAYER_NAME];
new string[256];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "EEW! %s has just farted!.", pName);
SendClientMessageToAll(0xFFFF00AA, string);
return 1;
}
How to do that? Thanks
Reply
#2

Take a look in the pinned optimise topic, it has an example.
Reply
#3

And you don't need 256 cells, 128 is enough.
Reply
#4

Put this at the top where you put the new variables.
pawn Код:
new FartTimer[MAX_PLAYERS];
and add this where you add forward:
pawn Код:
forward FartTimerOff(playerid);
and change your command to this:
pawn Код:
if(strcmp(cmdtext, "/fart", true) == 0) {
if(FartTimer[playerid] == 1)
{
SendClientMessage(playerid, 0xFFFFFFFF, "You must wait to do that again.");
return 1;
}
new pName[MAX_PLAYER_NAME];
new string[256];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "EEW! %s has just farted!.", pName);
SendClientMessageToAll(0xFFFF00AA, string);
FartTimer[playerid] = 1;
SetTimer("FartTimerOff", 60000, 0);//change this 60000 to your timer, this is in milli secconds.
return 1;
}
and add this where you add Public:
pawn Код:
public FartTimerOff(playerid)
{
if(FartTimer[playerid] == 1)
{
FartTimer[playerid] == 0;
return 1;
}
}
Regards, Adil.
Reply
#5

Quote:
Originally Posted by Adil_Rahoo
Put this at the top where you put the new variables.
pawn Код:
new FartTimer[MAX_PLAYERS];
and add this where you add forward:
pawn Код:
forward FartTimerOff(playerid);
and change your command to this:
pawn Код:
if(strcmp(cmdtext, "/fart", true) == 0) {
if(FartTimer[playerid] == 1)
{
SendClientMessage(playerid, 0xFFFFFFFF, "You must wait to do that again.");
return 1;
}
new pName[MAX_PLAYER_NAME];
new string[256];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "EEW! %s has just farted!.", pName);
SendClientMessageToAll(0xFFFF00AA, string);
FartTimer[playerid] = 1;
SetTimer("FartTimerOff", 60000, 0);//change this 60000 to your timer, this is in milli secconds.
return 1;
}
and add this where you add Public:
pawn Код:
public FartTimerOff(playerid)
{
if(FartTimer[playerid] == 1)
{
FartTimer[playerid] == 0;
return 1;
}
}
Regards, Adil.
pawn Код:
public FartTimerOff(playerid)
{
if(FartTimer[playerid] == 1)
{
FartTimer[playerid] = 0;
return 1;
}
}
Use the FartTimerOff function I've provided, as Adil's has an error.
Reply
#6

Quote:
Originally Posted by Calgon
Use the FartTimerOff function I've provided, as Adil's has an error.
Oh, i added one extra "=", my bad.

Regards, Adil.
Reply
#7

1 Warning, it's the last } I can't remove.

Код:
warning 209: function "FartTimerOff" should return a value
Reply
#8

You don't need a timer to do this guys:

pawn Код:
//global
new
  gLastTime[ MAX_PLAYERS ] = 0;

//connect and disconnect
gLastTime[ playerid ] = 0;

//text or command or pm, wherever you want
if ( ( gettime() - gLastTime[ playerid ] ) < SOME_AMOUNT_OF_SECONDS )
{
  //they are spamming so tell them or return false ?
}
else gLastTime[ playerid ] = gettime();
That will run only when they actually send a text and not every ** amount of seconds like a timer would.

Timers slow your sync, always best to use a work around when possible (well most cases).
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)