Please help !!!
#1

guys i want to make when ill type jail and if i i type the ID of the player who is alredy in jail to send me message "That player is alredy in jail." i have tryed so many ways to make that but still cant get the right one so here is the code:
pawn Код:
CMD:jail(playerid, params[])
{
    if(IsPlayerAdmin2[playerid] == 2)
    {
        new targetid, Text:JailTextDraw, reason[128], msg[64], name[46];
        if(sscanf(params, "us[128]", targetid, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /jail [id] [reason]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "That player is not online.");
        GetPlayerName(playerid, name, sizeof(name));
        format(msg, sizeof(msg), "%s was jailed. Reason: %s. Time: 120sec.", name, reason);
        SendClientMessageToAll(COLOR_RED, msg);
        SetTimer("jailtime", 120000, false);
        SetPlayerInterior(targetid, 6);
        SetPlayerPos(targetid, 265.34756469727, 77.521759033203, 1001.0390625);
        JailTextDraw = TextDrawCreate(327.000000, 377.000000, "X");
        TextDrawAlignment(JailTextDraw, 2);
        TextDrawBackgroundColor(JailTextDraw, 255);
        TextDrawFont(JailTextDraw, 2);
        TextDrawLetterSize(JailTextDraw, 0.620000, 3.200000);
        TextDrawColor(JailTextDraw, -1);
        TextDrawSetOutline(JailTextDraw, 0);
        TextDrawSetProportional(JailTextDraw, 1);
        TextDrawSetShadow(JailTextDraw, 1);
        CountdownTextDraw(targetid, JailTextDraw, 120);
        return 1;
    }
    return 1;
}
Thanks all
Reply
#2

please help anyone ? :S
Reply
#3

A global boolean array to represent if player is jailed or not.
pawn Код:
new bool:IsJailed[MAX_PLAYERS];
To avoid bugs with players being jailed when connecting (if player is assigned a playerid, which was earlier jailed, you'll reset it when the player joins)
pawn Код:
public OnPlayerConnect(playerid)
{
    IsJailed[playerid] = false;
}
When you jail the player, you set it to true and check if the the player is already jailed.
pawn Код:
CMD:jail(playerid, params[])
{
    if(IsPlayerAdmin2[playerid] == 2)
    {
        new targetid, Text:JailTextDraw, reason[128], msg[64], name[46];
        if(sscanf(params, "us[128]", targetid, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /jail [id] [reason]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "That player is not online.");
        if(IsJailed[targetid] == true) return SendClientMessage(playerid, COLOR_WHITE, "That player is already jailed.");
        IsJailed[targetid] = true;
        GetPlayerName(playerid, name, sizeof(name));
        format(msg, sizeof(msg), "%s was jailed. Reason: %s. Time: 120sec.", name, reason);
        SendClientMessageToAll(COLOR_RED, msg);
        SetTimer("jailtime", 120000, false);
        SetPlayerInterior(targetid, 6);
        SetPlayerPos(targetid, 265.34756469727, 77.521759033203, 1001.0390625);
        JailTextDraw = TextDrawCreate(327.000000, 377.000000, "X");
        TextDrawAlignment(JailTextDraw, 2);
        TextDrawBackgroundColor(JailTextDraw, 255);
        TextDrawFont(JailTextDraw, 2);
        TextDrawLetterSize(JailTextDraw, 0.620000, 3.200000);
        TextDrawColor(JailTextDraw, -1);
        TextDrawSetOutline(JailTextDraw, 0);
        TextDrawSetProportional(JailTextDraw, 1);
        TextDrawSetShadow(JailTextDraw, 1);
        CountdownTextDraw(targetid, JailTextDraw, 120);
        return 1;
    }
    return 1;
}
Also, at your 'GetPlayerName' you are getting the playerid's name (AKA: The player who uses the command).
Should be:
pawn Код:
GetPlayerName(targetid, name, sizeof(name));
EDIT: Also don't forget to set IsJailed[playerid here] to 'false' when the player is unjailed (probably at your "jailtime")
Reply
#4

oh yeah that with the name its little mistake xD
btw that bool can u explain me for what is it i dont get it .. :/
Reply
#5

It doesn't have to be a boolean, you can make it:
pawn Код:
new IsJailed[ MAX_PLAYERS ];
or even:
pawn Код:
static IsJailed[ MAX_PLAYERS ];
But, using "static" is really not required here. Statics are used for this if I recall:
pawn Код:
public Callback( params ) {
    for( new i = 0; i < 5; ++i ) {
        static var[ i ];
    }
    // You can still use the "var[ i ]" outside the loop if you use "static", if I remember.
    var[ 0 ] = 0;
    var[ 1 ] = 0;
    var[ 2 ] = 0;
    var[ 3 ] = 0;
    var[ 4 ] = 0;
    return false;
}
and, if you used:
pawn Код:
public Callback( params ) {
    for( new i = 0; i < 5; ++i ) {
        new var[ i ];
    }
    // You now can't use the "var[ i ]"
    var[ 0 ] = 0;
    var[ 1 ] = 0;
    var[ 2 ] = 0;
    var[ 3 ] = 0;
    var[ 4 ] = 0;
    return false;
}
This will return errors, since the array didn't get passed out of the loop.
NOTE: This might not be what statics do, it's just what I think they do, I don't know if I remember right.
Reply
#6

Well as poster above said, it doesn't have to be a boolean. A boolean can only store whether it's true or false (1 or 0), and that's all that is needed (because the player can only be jailed or not jailed (No third possibility)
Reply
#7

dude this not working :/
idk why maybe cause i dont know how to make or have something wrong :/
Reply
#8

pawn Код:
CMD:jail(playerid, params[])
{
    if(IsPlayerAdmin2[playerid] == 2)
    {
        new targetid, Text:JailTextDraw, reason[128], msg[64], name[46];
        if(sscanf(params, "us[128]", targetid, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /jail [id] [reason]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "That player is not online.");
        if( GetPVarInt( targetid, "Jailed" ) == 1 ) return SendClientMessage( playerid, COLOR_WHITE, "That player is already in jail. " );
        GetPlayerName(playerid, name, sizeof(name));
        format(msg, sizeof(msg), "%s was jailed. Reason: %s. Time: 120sec.", name, reason);
        SendClientMessageToAll(COLOR_RED, msg);
        SetPVarInt( targetid, "Jailed", 1 );
        SetTimer("jailtime", 120000, false);
        SetPlayerInterior(targetid, 6);
        SetPlayerPos(targetid, 265.34756469727, 77.521759033203, 1001.0390625);
        JailTextDraw = TextDrawCreate(327.000000, 377.000000, "X");
        TextDrawAlignment(JailTextDraw, 2);
        TextDrawBackgroundColor(JailTextDraw, 255);
        TextDrawFont(JailTextDraw, 2);
        TextDrawLetterSize(JailTextDraw, 0.620000, 3.200000);
        TextDrawColor(JailTextDraw, -1);
        TextDrawSetOutline(JailTextDraw, 0);
        TextDrawSetProportional(JailTextDraw, 1);
        TextDrawSetShadow(JailTextDraw, 1);
        CountdownTextDraw(targetid, JailTextDraw, 120);
        return 1;
    }
    return 1;
}
Reply
#9

How does your "public jailtime(........)" look like?

You are calling it with 'SetTimer' I got a feeling you may have your "jailtime" containing a 'playerid' parameter, which represents the player you want to unjail. If that's correct, you would need to use SetTimerEx. Something like:

pawn Код:
SetTimerEx("jailtime", 120000, false, "d", targetid);
Reply
#10

Quote:
Originally Posted by Mikkel_Pedersen
Посмотреть сообщение
How does your "public jailtime(........)" look like?

You are calling it with 'SetTimer' I got a feeling you may have your "jailtime" containing a 'playerid' parameter, which represents the player you want to unjail. If that's correct, you would need to use SetTimerEx. Something like:

pawn Код:
SetTimerEx("jailtime", 120000, false, "d", targetid);
That's true, however, it wouldn't cause this problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)