Why does this not work ?
#1

Why does this not give a error message if the player is not connected ?

It is meant to say " ERROR:Player is not connected " But instead it just says " Unknown Command "


Please Help


Код:
CMD:jail(playerid, params[])
    {
        if(PlayerData[ID][AdminLevel] >= 1)
        {
            new targetid, minutes; //define the player's name and the minutes of jailing
            if(sscanf(params, "ri", targetid, minutes)) return SendClientMessage(playerid, COLOR_RED,"Usage: /jail <playerid> <minutes>"); //detects the wrong params and show the usage
            if(minutes <= 0 || minutes > 60) return SendClientMessage(playerid, COLOR_RED, "Minutes can't be less than 0 or more than 60!"); //we won't let a player suffer more than 1 hour, and not less than 1 minute
            
            if(PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_RED, "You can't jail higher level admins!"); //the performer can't jail higher admins!
            if(!IsPlayerConnected(targetid)) //if the ID doesn't exist, return an error-message
            return SendClientMessage(playerid, COLOR_GREY, "ERROR:Player is not connected!");
            else
            {
                new str[128]; //create a new string
                format(str, sizeof(str), "Administrator %s has jailed %s for %d minutes!", PlayerName(playerid), PlayerName(targetid), minutes); //get the admin's name, the player's and show the minutes
                SendClientMessageToAll(COLOR_LIGHTBLUE,str); //let everybody know what you did, this will send the message to everyone
                JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false); //now HERE we're setting the jailtimer from the variable created, it will calculate the milliseconds to seconds, multiplicated with the amount of minutes we gave
                SetPlayerPos(targetid, 215.09, 109.67, 999.02); //Sets the player's position to the jail in LS
        SetPlayerInterior(targetid, 10); //this will set the player's interior to an jail-interior
        inJail[targetid] = true; //now, here we'll check, if the player's in jail, we'll set the value to "true", means that he IS in jail
        GameTextForPlayer(targetid, "~p~JAILED", 10000, 6); //this is for decorating and writing a big "JAILED" for the player
        PlayerPlaySound(targetid,1057,0.0,0.0,0.0); //that's also a small sound, for decoration
        }
    }
        else return SendClientMessage(playerid, COLOR_RED, "You have to be level 4 to use this command!"); //if he isn't allowed to use this command, send him this message
        return 1;
    }
Please Help
Reply
#2

Try de-bugging it, the script stops working before it checks the player is connected.
Reply
#3

Quote:
Originally Posted by Marricio
Посмотреть сообщение
Try de-bugging it, the script stops working before it checks the player is connected.

So how would i make this bit of code work


Код:
if(!IsPlayerConnected(targetid)) //if the ID doesn't exist, return an error-message
            	return SendClientMessage(playerid, COLOR_GREY, "ERROR:Player is not connected!");
Please Help Please
Reply
#4

pawn Код:
CMD:jail(playerid, params[])
{
    if(PlayerData[ID][AdminLevel] >= 1)
    {
        new targetid, minutes; //define the player's name and the minutes of jailing
        if( sscanf( params, "ri", targetid, minutes ) )
            return SendClientMessage( playerid, COLOR_RED,"Usage: /jail <playerid> <minutes>" ); //detects the wrong params and show the usage

        if( minutes <= 0 || minutes > 60 )
            return SendClientMessage( playerid, COLOR_RED, "Minutes can't be less than 0 or more than 60!" ); //we won't let a player suffer more than 1 hour, and not less than 1 minute

        if( PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin] )
            return SendClientMessage( playerid, COLOR_RED, "You can't jail higher level admins!" ); //the performer can't jail higher admins!

        if( !IsPlayerConnected( targetid ) ) //if the ID doesn't exist, return an error-message
            return SendClientMessage(playerid, COLOR_GREY, "ERROR:Player is not connected!");
       
        new str[128]; //create a new string
        format(str, sizeof(str), "Administrator %s has jailed %s for %d minutes!", PlayerName(playerid), PlayerName(targetid), minutes); //get the admin's name, the player's and show the minutes
        SendClientMessageToAll(COLOR_LIGHTBLUE,str); //let everybody know what you did, this will send the message to everyone
        JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false); //now HERE we're setting the jailtimer from the variable created, it will calculate the milliseconds to seconds, multiplicated with the amount of minutes we gave
        SetPlayerPos(targetid, 215.09, 109.67, 999.02); //Sets the player's position to the jail in LS
        SetPlayerInterior(targetid, 10); //this will set the player's interior to an jail-interior
        inJail[targetid] = true; //now, here we'll check, if the player's in jail, we'll set the value to "true", means that he IS in jail
        GameTextForPlayer(targetid, "~p~JAILED", 10000, 6); //this is for decorating and writing a big "JAILED" for the player
        PlayerPlaySound(targetid,1057,0.0,0.0,0.0); //that's also a small sound, for decoration
    }

    else
        return SendClientMessage(playerid, COLOR_RED, "You have to be level 4 to use this command!"); //if he isn't allowed to use this command, send him this message
    return 1;
}
Reply
#5

Quote:
Originally Posted by Marricio
Посмотреть сообщение
pawn Код:
CMD:jail(playerid, params[])
{
    if(PlayerData[ID][AdminLevel] >= 1)
    {
        new targetid, minutes; //define the player's name and the minutes of jailing
        if( sscanf( params, "ri", targetid, minutes ) )
            return SendClientMessage( playerid, COLOR_RED,"Usage: /jail <playerid> <minutes>" ); //detects the wrong params and show the usage

        if( minutes <= 0 || minutes > 60 )
            return SendClientMessage( playerid, COLOR_RED, "Minutes can't be less than 0 or more than 60!" ); //we won't let a player suffer more than 1 hour, and not less than 1 minute

        if( PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin] )
            return SendClientMessage( playerid, COLOR_RED, "You can't jail higher level admins!" ); //the performer can't jail higher admins!

        if( !IsPlayerConnected( targetid ) ) //if the ID doesn't exist, return an error-message
            return SendClientMessage(playerid, COLOR_GREY, "ERROR:Player is not connected!");
       
        new str[128]; //create a new string
        format(str, sizeof(str), "Administrator %s has jailed %s for %d minutes!", PlayerName(playerid), PlayerName(targetid), minutes); //get the admin's name, the player's and show the minutes
        SendClientMessageToAll(COLOR_LIGHTBLUE,str); //let everybody know what you did, this will send the message to everyone
        JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false); //now HERE we're setting the jailtimer from the variable created, it will calculate the milliseconds to seconds, multiplicated with the amount of minutes we gave
        SetPlayerPos(targetid, 215.09, 109.67, 999.02); //Sets the player's position to the jail in LS
        SetPlayerInterior(targetid, 10); //this will set the player's interior to an jail-interior
        inJail[targetid] = true; //now, here we'll check, if the player's in jail, we'll set the value to "true", means that he IS in jail
        GameTextForPlayer(targetid, "~p~JAILED", 10000, 6); //this is for decorating and writing a big "JAILED" for the player
        PlayerPlaySound(targetid,1057,0.0,0.0,0.0); //that's also a small sound, for decoration
    }

    else
        return SendClientMessage(playerid, COLOR_RED, "You have to be level 4 to use this command!"); //if he isn't allowed to use this command, send him this message
    return 1;
}
Just tested that and it did not work
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)