time %i
#1

How to make:

/jail id time ?

After time it SpawnPlayer and /jail puts the player in a coord...
Reply
#2

Do not make script request threads, this is like the most simplest things to make.

pawn Код:
//Top of script
forward PlayerJailed();
new PlayerIsJailed[MAX_PLAYERS];

//Under OnPlayerConnect
PlayerIsJailed[playerid] = 0;

CMD:jail(playerid, params[])
{
    if(/*Playeradminvariable*/ == /*level of admin*/)
    {
        new targetid, time;
        if(sscanf(params, "id", targetid, time)) return SendClientMessage(playerid, -1, "Usage: /jail <playerid> <time>");
        if(IsPlayerConnected(targetid))
        {
            //Should add a variable here that sets the ammount of time *global variable* that checks when the player logs inm if they are jailed
            SetPlayerPos(targetid, /*posx*/, /*posy*/, /*posz*/);
            SetTimer("PlayerJailed", time /*inmiliseconds*/, false);
            PlayerIsJailed[playerid] = 1;
         }
    }
    else return SendClientMessage(playerid, -1, "You are not authorized to use this command!");
    return 1;
}

//Somewhere else
public PlayerJailed()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerIsJailed[i] == 1)
        {
            SetPlayerPos(i, /*posx*/, /*posy*/, /*posz*/);
            PlayerIsJailed[i] = 0;
        }
    }
}
If you see this, it should be pretty self-explanatory as long as you actually know the basics.

Hint: Next time, actually try something before making a thread.

PS: Some stuff may not be needed, for example, the if(PlayerIsJailed[i] == 1) as I do not see why this would be needed, but I added it anyways.

EDIT: I see, wasn't paying much attention. Thanks below.
Reply
#3

The command should be like this:
pawn Код:
CMD:jail(playerid, params[])
{
    if(/*Playeradminvariable*/ == /*level of admin*/)
    {
        new targetid, time;
        if(sscanf(params, "ud", targetid, time)) return SendClientMessage(playerid, -1, "Usage: /jail <playerid> <time>");
        if(IsPlayerConnected(targetid))
        {
            //Should add a variable here that sets the ammount of time *global variable* that checks when the player logs inm if they are jailed
            SetPlayerPos(targetid, /*posx*/, /*posy*/, /*posz*/);
            SetTimer("PlayerJailed", time /*inmiliseconds*/, false);
            PlayerIsJailed[playerid] = 1;
         }
    }
    else return SendClientMessage(playerid, -1, "You are not authorized to use this command!");
    return 1;
}
sscanf parameter shouldn't be 'i', but 'u'...
Reply
#4

actually if you dont want npcs the sscanf should be "r" not "u" and not "i"



edit:
misspelled sscanf..
Reply
#5

Quote:
Originally Posted by Kindred
Посмотреть сообщение
Do not make script request threads, this is like the most simplest things to make.

pawn Код:
//Top of script
forward PlayerJailed();
new PlayerIsJailed[MAX_PLAYERS];

//Under OnPlayerConnect
PlayerIsJailed[playerid] = 0;

CMD:jail(playerid, params[])
{
    if(/*Playeradminvariable*/ == /*level of admin*/)
    {
        new targetid, time;
        if(sscanf(params, "id", targetid, time)) return SendClientMessage(playerid, -1, "Usage: /jail <playerid> <time>");
        if(IsPlayerConnected(targetid))
        {
            //Should add a variable here that sets the ammount of time *global variable* that checks when the player logs inm if they are jailed
            SetPlayerPos(targetid, /*posx*/, /*posy*/, /*posz*/);
            SetTimer("PlayerJailed", time /*inmiliseconds*/, false);
            PlayerIsJailed[playerid] = 1;
         }
    }
    else return SendClientMessage(playerid, -1, "You are not authorized to use this command!");
    return 1;
}

//Somewhere else
public PlayerJailed()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerIsJailed[i] == 1)
        {
            SetPlayerPos(i, /*posx*/, /*posy*/, /*posz*/);
            PlayerIsJailed[i] = 0;
        }
    }
}
If you see this, it should be pretty self-explanatory as long as you actually know the basics.

Hint: Next time, actually try something before making a thread.

PS: Some stuff may not be needed, for example, the if(PlayerIsJailed[i] == 1) as I do not see why this would be needed, but I added it anyways.

EDIT: I see, wasn't paying much attention. Thanks below.
How could i send a message to the jailed: You have been jailed for %i seconfs by administrator %s.

And to the admin: Youu have jailed %s for %i seconds.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)