Help me with my /jail command
#1

Okay here's my command:
pawn Код:
if(strcmp(cmd, "/ajail", true) == 0) if(ShitInfo[playerid][pMuted] == 0)
    {
      if(IsPlayerConnected(playerid))
      {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /jail [playerid/PartOfName] [time(minutes)]");
                return 1;
            }
            new playa;
            new money;
            playa = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            money = strval(tmp);
            if (GetPlayerAdminz(playerid) >= 1)
            {
              if(IsPlayerConnected(playa))
              {
                if(playa != INVALID_PLAYER_ID)
                {
                    GetPlayerName(playa, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        format(string, sizeof(string), "%s has been Jailed for %d seconds by Admin %s", giveplayer,money,sendername);
                        SendClientMessage(playerid, AC_COLOR, string);
                        ShitInfo[playa][pJailed] = 1;
                        ShitInfo[playa][pJailTime] = money*1;
                        SetPlayerInterior(playa, 6);
                        TogglePlayerControllable(giveplayerid,0);
                        SetPlayerPos(playa, 264.6288,77.5742,1001.0391);
                        }
                        if(ShitInfo[playa][pJailTime] == 0)
                        {
                        SendClientMessage(playa,COLOR_GREEN,"Jail time is over, you are free!");
                    ShitInfo[playa][pJailTime] = 0;
                        ShitInfo[playa][pJailed] = 0;
                    SetPlayerInterior(playa,0);
                    SetPlayerFacingAngle(playa,90.00);
                    SetPlayerPos(playa,1552.6807,-1674.8497,16.1953);
                        SetPlayerFacingAngle(playa,177.0350);
                    SetCameraBehindPlayer(playa);
                    TogglePlayerControllable(playa,1);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
            }
        }
        return 1;
    }
But even when i jail some1 for 1 second they NEVER leave jail! how do i make it so after the jail time is over they leave jail? As you can see i have attempted this can somebody just fix that part?
Reply
#2

Because:
1) You aren't setting a timer to decrease the jail time every second/minute.
2) You check if the players jailtime is up in the command, meanign the officer would have to type /jail again to unjail the person.

Use SetTimerEx to unjail the player after their time. When the time reaches zero ,release them.
Reply
#3

can you tell me how to make it use a timer?
Reply
#4

Example
pawn Код:
//in command
SetTimerEx("DecreaseJailTimer", 1000, 0, "i", playa);

//after main()
forward DescreaseJailTimer(playerid);
public DecreseJailTimer(playerid)
{
  ShitPlayer[playa][pJailTime] --;
  if(ShitPlayer[playa][pJailTime] == 0)
  {
   //release thme
  }
  else { SetTimerEx("DecreaseJailTimer", 1000, 0, "i", playerid);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)