[HELP] advertise timer for all players
#1

Hello everyone. I wonder how can I make when for example first player give advertise then after first player the second is try to ad advertise how can I know make to say you must wait 30 seconds before next advertise also the same I want to say to the firt player if you know what I mean? Thanks
Reply
#2

pawn Код:
new lastadvert = 0; //At the top of your script

CMD:advert(playerid, params[]) //Example command...
{
    if(gettime() < (lastadvert + 30)) return SendClientMessage(playerid, -1, "You must wait 30 seconds between advertisements.");
    //Blah blah blah
    lastadvert = gettime();
    //blah blah blah
pawn Код:
if(gettime() < (lastadvert + 30))
This line says, if the current timestamp is less than the last timestamp (when the command was used) + 30 seconds, then return an error.

pawn Код:
lastadvert = gettime();
Set the new timestamp.

Sources:
https://sampwiki.blast.hk/wiki/Gettime

What is a unix timestamp?
Quote:

The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch. It should also be pointed out (thanks to the comments from visitors to this site) that this point in time technically does not change no matter where you are located on the globe. This is very useful to computer systems for tracking and sorting dated information in dynamic and distributed applications both online and client side.

Reply
#3

is there maybe a way when player try type /advertise that every time he types it show like 30 28 25 23 if you know what I mean? Thanks
Reply
#4

I was thinking if I should put that in when I was making it. Looks like I had to after all.

pawn Код:
if(gettime() < (lastadvert + 30))
{
    new fstr[55];
    format(fstr, sizeof(fstr), "You must wait %d seconds before advertising again.", (lastadvert + 30) - gettime());
    return SendClientMessage(playerid, -1, fstr);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)