[HELP] How can i add a timer in this command?
#1

i want to add in this command a timer which the player can use the command every 15 seconds

PAWN Code:
dcmd_rob(playerid, params[])
{
if (strlen(params))
{
id = strval(params);
if (IsPlayerConnected(id) && (gTeam[playerid] == TEAM_CIVIL) && (GetDistanceBetweenPlayers( playerid, id) < 3.0 ) && (gTeam[id] != TEAM_COPS) && (gTeam[id] != TEAM_CIA))
{
if(GetPlayerWantedLevel(id) == 0)
{
if(id != playerid)
{
SendClientMessage(id, COLOR_RED , "You have been Robbed -1000$");
SendClientMessage(playerid, 0x00FF00AA, "You Have robbed 1000$");
GivePlayerMoney(playerid, 1000);
GivePlayerMoney(id, -1000);
SetPlayerScore(playerid, GetPlayerScore( playerid ) +1 );
SetPlayerWantedLevel( playerid, GetPlayerWantedLevel( playerid )+1 );
GameTextForPlayer(playerid, "~y~Player Robbed~n~+1000$", 3500, 3);
GameTextForPlayer(id, "~y~You have been Robbed~n~-1000$", 3500, 3);
}
else
{
SendClientMessage(playerid, COLOR_RED , "You can not rob your self!");
}
}
}

else
{
SendClientMessage(playerid, COLOR_RED , "You are not a Civilian to use this, or there is no player nearby.");
SendClientMessage(playerid, COLOR_RED , "You can not rob cops or agents!");
}
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/rob <playerid>\"");
}
return 1;
Reply
#2

( Btw use [.pawn] [/pawn] )
I took this from one cops'n'robbers
Top of script where are all the new's at.
pawn Код:
new RobbedPlyRecent[MAX_PLAYERS];
OnGameModeInIt.
pawn Код:
SetTimer("RobbedPlayerRecent",60000,1);
Now go somewhere in script and do this :
pawn Код:
forward RobbedPlayerRecent();
public RobbedPlayerRecent()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
    {
   if(RobbedPlyRecent[i] == 1)
     {
    RobbedPlyRecent[i] =0;

  }
 }
}
OnPlayerConnect..
pawn Код:
RobbedPlyRecent[playerid] =0;
OnPlayerSpawn..
pawn Код:
RobbedPlyRecent[playerid] =1;
now add this to your command
pawn Код:
if(RobbedPlyRecent[playerid] == 1) {
  SendClientMessage(playerid,COLOR_ERROR,"Command used recently... Please wait");
  return 1;
  }
Yes i know its newbish but hope it works.
Reply
#3

BTW: Use SetTimerEx(), with SetTimer it just checks every minute. So if you rob someone in that 59th second you can rob him again 2 seconds later.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)