COMMAND PROBLEM: Help
#1

Hey erm, I have a problem... when I type /ar <id> even if it's invalid... it works if it's valid... but if it's an invalid id or i just type /ar it says you can't chase urself... why?

pawn Код:
CMD:chase(playerid, params[])
{
    new TargetID;
    if( GetPlayerTeam(playerid) == POLICE )
    {
        if( !sscanf( params, "u", TargetID) )
        {
            new Float:X, Float:Y, Float:Z, MString[128];
            if( TargetID == INVALID_PLAYER_ID ) return SCM( playerid, COLOR_RED, "Cant chase this person! ");
            if( TargetID == playerid ) return SCM( playerid, COLOR_RED, "Cant chase yourself! ");
            if( GetPlayerTeam(TargetID) == POLICE ) return SCM( playerid, COLOR_RED, "Cant chase a cop! ");
            ChaseTimer = SetTimerEx( "ChasePlayer", CHASEINTERVAL, 1, "ii", playerid, TargetID );
            GetPlayerPos( TargetID, X, Y, Z );
            SetPlayerCheckpoint( playerid, X, Y, Z, 5 );
            format( MString, sizeof MString, "You are chasing %s", GetName(TargetID) );
            SCM( playerid, COLOR_WHITE, MString );
            format( MString, sizeof MString, "%s is in persuit of %s", GetName(playerid), GetName(TargetID) );
            for( new i = 0; i < MAX_PLAYERS; i ++ )
            {
                if( GetPlayerTeam(i) == POLICE )
                {
                    SCM( i, COLOR_RED2, MString );
                }
            }
            Chasing[playerid] = 1;
            BeingChased[TargetID] = 1;
        } else return SCM( playerid, C_GREEN, "Usage: /chase <playerid> ");
    } else return SCM( playerid, C_RED, "You are not a cop and cannot use this command");
    return 1;
}

CMD:stopchase(playerid, params[])
{
    if( GetPlayerTeam(playerid) == POLICE )
    {
        Chasing[playerid] = 0;
        DisablePlayerCheckpoint(playerid);
        SendClientMessage( playerid, C_GREEN, "You stopped chasing your target!"); // this will work i think :p what about the undefined symbol mString? there yoo goes alright, also... io need the GetPlayerName function xD
    } else return SCM( playerid, COLOR_RED, "You are not a cop and cannot use this command! ");
    return 1;
}

CMD:ar(playerid, params[])
{
    new id, Float:x, Float:y, Float:z;
    if(GetPlayerTeam(playerid) != POLICE) return SCM(playerid, C_RED, "You have to be a police officer to do /arrest!");
    if( id == playerid ) return SCM( playerid, COLOR_RED, "Cant chase yourself! ");
    if(sscanf(params, "u", id)) return SCM(playerid, C_RED, "USAGE: /arrest <nick/id>");
    if(!IsPlayerConnected(id)) return SCM(playerid, C_RED, "This player isn't connected!");
    GetPlayerPos(id, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z)) return SCM(playerid, C_RED, "You aren't close enough to this player!");
    if(GetPlayerWantedLevel(id) < 3) return SCM(playerid, C_RED, "That player hasn't got a 3 + wanted level!");
    SendFMessage(id, COLOR_YELLOW, "Police Officer %s has arrested you!", GetName(playerid));
    GameTextForPlayer(id, "~r~~h~Arrested!", 4000, 3);
    SendFMessage(playerid, -1, "You have arrested %s", GetName(id));
    SendFMessageToAll(-1, "Police Officer %s has arrested %s", GetName(playerid), GetName(id));
    GivePlayerMoney(playerid, 1500);
    GivePlayerMoney(playerid, -1500);
    Jailplayer(id);
    Jailtimer[playerid] = SetTimer("releaseplayer", 60000, false);
    SetPlayerWantedLevel(id, 0);
    return 1;
}
Reply
#2

You're comparing the value of the id variable before sscanf has actually split it from the string and stored it. You should be comparing it after sscanf has done its job, because the variable is defaulting to 0 and your ID is probably 0, so it will never get any further than that. Just re-order them:

pawn Код:
if(sscanf(params, "u", id)) return SCM(playerid, C_RED, "USAGE: /arrest <nick/id>");
if( id == playerid ) return SCM( playerid, COLOR_RED, "Cant chase yourself! ");
Hope that makes sense!
Reply
#3

ahhh thanks very much
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)