Time limiter for /rob help!
#1

guys how can i add a time limiter in this code?

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob
  {
    if(IsPlayerInCheckpoint(playerid)) // Check if they are in a checkpoint
    {
      GivePlayerMoney(playerid, random(2000+1)); // Give the player the money!
    }
    return 1; //return one to prevent "SERVER: Unknown command"
  }
  return 0;
}
I mean that, i want when someone /rob a place, then he must wait 60 minutes for the next /rob, how to add this to the script?

Thanks
Reply
#2

set the variable like robbed = 1; and then set the timer, which will set the robbed back to 0 after x amount of time.
Reply
#3

Quote:
Originally Posted by [Diablo]
Посмотреть сообщение
set the variable like robbed = 1; and then set the timer, which will set the robbed back to 0 after x amount of time.
i didn't understand
Reply
#4

pawn Код:
new Canrob[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
  if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob
  {
    if(IsPlayerInCheckpoint(playerid)) // Check if they are in a checkpoint
    {
        if(CanRob[playerid] == 1)
        {
          GivePlayerMoney(playerid, random(2000+1)); // Give the player the money!
              Canrob[playerid] = 0;
          SetTimerEx("CanRob",60000,false,"i",playerid);
          else return SendClientMessage(playerid,-1,"You must wait 60 seconds before robbing again!");
    }
    return 1; //return one to prevent "SERVER: Unknown command"
  }
  return 0;
}
forward CanRob(playerid);
public CanRob(playerid)
{
    Canrob[playerid] = 1;
    return 1;
}
Reply
#5

Quote:
Originally Posted by Panormitis
Посмотреть сообщение
i didn't understand
It's really simple, just read SetTimer or SetTimerEx and use variables to help you with the timers. I would've done it for ya but my laptop is dead .

EDIT: Sorry the above post was posted while I was writing. The above script is exactly how you do it.
Reply
#6

Here's a way, there is no need for a timer. You will need to edit make the "iLastRobbery" var an array and assign robbery shops ids to it.

pawn Код:
new iLastRobbery;

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob
    {
        if(IsPlayerInCheckpoint(playerid))
        {
            if(GetTickCount() > iLastRobbery) //if iLastRobbey is less than tickcount. ie. iLastRobbey = GetTickCount + 60 seconds.
            {
                GivePlayerMoney(playerid, random(2000+1));
                iLastRobbery = GetTickCount() + 60000;//iLastRobbery is GetTickCount plus 60 secons
                return 1;
            }
            else {
                SendClientMessage(playerid, 0xFF0000AA, "ERROR: That shop has only recently been robbed.");
                return 1;
            }
        }
    }
    return 0;
}
You need to keep in mind that a player will be able to rob cash at any checkpoint since you only check if they are in a checkpoint and not in a specific checkpoint.
Reply
#7

jap iggy1's way is even better. gj
Reply
#8

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Here's a way, there is no need for a timer. You will need to edit make the "iLastRobbery" var an array and assign robbery shops ids to it.

pawn Код:
new iLastRobbery;

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob
    {
        if(IsPlayerInCheckpoint(playerid))
        {
            if(GetTickCount() > iLastRobbery) //if iLastRobbey is less than tickcount. ie. iLastRobbey = GetTickCount + 60 seconds.
            {
                GivePlayerMoney(playerid, random(2000+1));
                iLastRobbery = GetTickCount() + 60000;//iLastRobbery is GetTickCount plus 60 secons
                return 1;
            }
            else {
                SendClientMessage(playerid, 0xFF0000AA, "ERROR: That shop has only recently been robbed.");
                return 1;
            }
        }
    }
    return 0;
}
You need to keep in mind that a player will be able to rob cash at any checkpoint since you only check if they are in a checkpoint and not in a specific checkpoint.
i added this, but when i type /rob nothing happens :\
Reply
#9

Quote:
Originally Posted by Panormitis
Посмотреть сообщение
i added this, but when i type /rob nothing happens :\
I don't understand why not I'm afraid. I have just tested it several times and it works for me. (i tested without the checkpoint check)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)