[HELP] /jail command
#1

Hi,

I've been working on my /jail command but I'm not that good with timers and I need soemthing that will relese the player after the added time ends.

Here is the command itself:

pawn Код:
if(strcmp(cmd, "/jail", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gTeam[playerid] == 5 || gTeam[playerid] == 6)
            {
                if(!PlayerToPoint(6.0, playerid, 268.3327,77.8972,1001.0391))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not near the Jail, can't Arrest !");
                    return 1;
                }
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   USAGE: /jail [fine] [time]");
                    return 1;
                }
                moneys = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   USAGE: /jail [fine] [time]");
                    return 1;
                }
                new time = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   USAGE: /jail [fine] [time]");
                    return 1;
                }
                if(IsPlayerConnected(giveplayerid))
                {
                    if(GetDistanceBetweenPlayers(playerid, giveplayerid) < 5)
                    {
                        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        format(string, sizeof(string), "* You arrested %s !", giveplayer);
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                        GivePlayerMoney(giveplayerid, -moneys);
                        format(string, sizeof(string), "~r~Fine: $%d", moneys);
                        GameTextForPlayer(giveplayerid, string, 5000, 5);
                        SetPlayerInterior(giveplayerid, 6);
                        SetPlayerPos(giveplayerid,264.6288,77.5742,1001.0391);
                        PlayerInfo[giveplayerid][pJailTime] = time * 60;
                        PlayerInfo[giveplayerid][pJailed] = 1;
                        return 1;
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   That player is too far away.");
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "   You are not authorized to use that command.");
            }
        }
        return 1;
    }
    return 0;
}
Thanks!
Reply
#2

You need to create a loop that checks if the player is in Jail and what to do based upon that, if they log out, then they will just spawn again.
Reply
#3

Quote:
Originally Posted by Dokins
Посмотреть сообщение
You need to create a loop that checks if the player is in Jail and what to do based upon that, if they log out, then they will just spawn again.
I know how to make it check if the player still has [pJailed] == 1 at spawn and if they do they'll spawn at the jail but I don't know how to make the thing that will free them when the time ends.
Reply
#4

Are you saving the time already? Make it something like this.
pawn Код:
if(PlayerInfo[playerid][Jail] == 1)
{
    SetTimer("unjail", PlayerInfo[playerid][Time], false);
}

forward unjail();
public unjail()
{
    // Unjail function
    SendClientMessage(playerid, 0xFFFFFFFF, "Unjailed!");
}
Reply
#5

Quote:
Originally Posted by Kingunit
Посмотреть сообщение
Are you saving the time already? Make it something like this.
pawn Код:
if(PlayerInfo[playerid][Jail] == 1)
{
    SetTimer("unjail", PlayerInfo[playerid][Time], false);
}

forward unjail();
public unjail()
{
    // Unjail function
    SendClientMessage(playerid, 0xFFFFFFFF, "Unjailed!");
}
This is what I've done:

pawn Код:
forward SetPlayerUnjail();

new unjailtimer;

unjailtimer = SetTimer("SetPlayerUnjail", 1000, 1);

if(strcmp(cmd, "/jail", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gTeam[playerid] == 5 || gTeam[playerid] == 6)
            {
                if(!PlayerToPoint(6.0, playerid, 1529.3108,-1677.7783,5.8906))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not near the Jail, can't Arrest !");
                    return 1;
                }
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   USAGE: /jail [playerid/PartOfName] [fine] [time]");
                    return 1;
                }
                giveplayerid = ReturnUser(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   USAGE: /jail [playerid/PartOfName] [fine] [time]");
                    return 1;
                }
                moneys = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GREY, "   USAGE: /jail [playerid/PartOfName] [fine] [time]");
                    return 1;
                }
                new time = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(IsPlayerConnected(giveplayerid))
                {
                    if(GetDistanceBetweenPlayers(playerid, giveplayerid) < 5)
                    {
                        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        format(string, sizeof(string), "* You arrested %s !", giveplayer);
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                        GivePlayerMoney(giveplayerid, -moneys);
                        format(string, sizeof(string), "~r~Fine: $%d", moneys);
                        GameTextForPlayer(giveplayerid, string, 5000, 5);
                        SetPlayerInterior(giveplayerid, 6);
                        SetPlayerPos(giveplayerid,264.6288,77.5742,1001.0391);
                        PlayerInfo[giveplayerid][pJailTime] = time * 60;
                        PlayerInfo[giveplayerid][pJailed] = 1;
                        return 1;
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   That player is too far away.");
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "   You are not authorized to use that command.");
            }
        }
        return 1;
    }

public SetPlayerUnjail()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][pJailed] > 0)
            {
                PlayerInfo[i][pJailTime] = 0;
                if(PlayerInfo[i][pJailed] == 1)
                {
                    SetPlayerInterior(i, 6);
                    SetPlayerPos(i,268.0903,77.6489,1001.0391);
                }
                else if(PlayerInfo[i][pJailed] == 2)
                {
                    SetPlayerWorldBounds(i, 20000.0000,-20000.0000,20000.0000,-20000.0000);
                    SetPlayerInterior(i, 0);
                    SetPlayerPos(i, 90.2101,1920.4854,17.9422);
                }
                PlayerInfo[i][pJailed] = 0;
            }
        }
    }
}
The only problem is that if I type for example /jail 0 1000 1 I get jailed for only 1 second, it doesn't mattar what time I put in there it just keeps relesing me after 1 second.
Reply
#6

It's in MS. Means 1000 = 1Second.
Reply
#7

Quote:
Originally Posted by Kingunit
Посмотреть сообщение
It's in MS. Means 1000 = 1Second.
What did I do wrong?
Reply
#8

Quote:
Originally Posted by ChaosLad
Посмотреть сообщение
What did I do wrong?
You've said: "I type for example /jail 0 1000 1 I get jailed for only 1 second, "

That's correct, since 1000MS is 1 second.
Reply
#9

Quote:
Originally Posted by Kingunit
Посмотреть сообщение
You've said: "I type for example /jail 0 1000 1 I get jailed for only 1 second, "

That's correct, since 1000MS is 1 second.
Yeah, but it doesn't matter what I put in there. I tried /jail 0 1000 100 but I still get jailed for one second. How to I fix this, I want the jail time to be in minutes.
Reply
#10

I still can't figure this out.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)