id 0 cant /tk id 1 please help stock
#1

hey it seems like everytime i try give the closes player to me a ticket it give it my self with i am id 0 heres my code

PHP код:
cmd(tkplayeridparams[])
{
    foreach(new 
ID Player)
    {
     if(!
IsPlayerConnected(ID)) return SendClientMessage(playerid, -1"Not conected");
    if(
ID != playerid//this checks if the ID from the loop isnt you, if it was you it will avoid it.
    
{
        return 
0;
    }
    if(!
IsCop(playerid))
        return 
SendClientMessage(playeridCOLOR_RED"Only Cops/Army can use this command.");
    new 
string[120];
    if(
GetDistanceBetweenPlayers(playeridID) > 4)
    {
        return 
SendClientMessage(playeridCOLOR_RED"That player is too far away to Ticket.");
    }
    new 
pwl GetPlayerWantedLevel(ID);
    if(
pwl == 1)
    {
        
format(string120"[COP ACTION] You have been fined by officer %s. You have been charged $1,000"PlayerInfo(playerid));
        
SendClientMessage(IDCOLOR_DODGERBLUEstring);
        
format(string120"[COP ACTION] You have fined %s. You have recieved a collection prize."PlayerInfo(ID));
        
SendClientMessage(playeridCOLOR_DODGERBLUEstring);
        
format(string120"[DISPATCH] Officer %s has fined %s. He is no longer wanted."PlayerInfo(playerid), PlayerInfo(ID));
        
SendCopMessage(string);
        
SetPlayerWantedLevel(ID0);
        
IncreaseScore(playerid1);
        
GivePlayerMoney(playerid2500);
        
GivePlayerMoney(ID, -1000);
    }
    if(
pwl == 2)
    {
         
format(string120"[COP ACTION] You have been fined by officer %s. You have been charged $2,000"PlayerInfo(playerid));
        
SendClientMessage(IDCOLOR_DODGERBLUEstring);
        
format(string120"[COP ACTION] You have fined %s. You have recieved a collection prize."PlayerInfo(ID));
        
SendClientMessage(playeridCOLOR_DODGERBLUEstring);
        
format(string120"[DISPATCH] Officer %s has fined %s. He is no longer wanted."PlayerInfo(playerid), PlayerInfo(ID));
        
SendCopMessage(string);
        
SetPlayerWantedLevel(ID0);
        
IncreaseScore(playerid1);
        
GivePlayerMoney(playerid2500);
        
GivePlayerMoney(ID, -2000);
    }
     if(
pwl == 3)
    {
         
format(string120"[COP ACTION] You have been fined by officer %s. You have been charged $3,000"PlayerInfo(playerid));
        
SendClientMessage(IDCOLOR_DODGERBLUEstring);
        
format(string120"[COP ACTION] You have fined %s. You have recieved a collection prize."PlayerInfo(ID));
        
SendClientMessage(playeridCOLOR_DODGERBLUEstring);
        
format(string120"[DISPATCH] Officer %s has fined %s. He is no longer wanted."PlayerInfo(playerid), PlayerInfo(ID));
        
SendCopMessage(string);
        
SetPlayerWantedLevel(ID0);
        
IncreaseScore(playerid1);
        
GivePlayerMoney(playerid2500);
        
GivePlayerMoney(ID, -3000);
    }
    else
    {
        if(
pwl == 0)
        {
            return 
SendClientMessage(playeridCOLOR_YELLOW"["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"player is innocent!");
        }
        if(
pwl == 4)
        {
            return 
SendClientMessage(playeridCOLOR_YELLOW"["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
        if(
pwl == 5)
        {
            return 
SendClientMessage(playeridCOLOR_YELLOW"["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
        if(
pwl == 6)
        {
            return 
SendClientMessage(playeridCOLOR_YELLOW"["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
    }
    }
    return 
1;

Reply
#2

You used v in a wrong way.
pawn Код:
if(ID != playerid) //this checks if the ID from the loop isnt you, if it was you it will avoid it.
    {
        return 0;
    }
Do this:
pawn Код:
cmd(tk, playerid, params[])
{
    foreach(new ID : Player)
    {
    if(ID != playerid) //this checks if the ID from the loop isnt you, if it was you it will avoid it.
    {
    if(!IsCop(playerid))
        return SendClientMessage(playerid, COLOR_RED, "Only Cops/Army can use this command.");
    new string[120];
    if(GetDistanceBetweenPlayers(playerid, ID) > 4)
    {
        return SendClientMessage(playerid, COLOR_RED, "That player is too far away to Ticket.");
    }
    new pwl = GetPlayerWantedLevel(ID);
    if(pwl == 1)
    {
        format(string, 120, "[COP ACTION] You have been fined by officer %s. You have been charged $1,000", PlayerInfo(playerid));
        SendClientMessage(ID, COLOR_DODGERBLUE, string);
        format(string, 120, "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(ID));
        SendClientMessage(playerid, COLOR_DODGERBLUE, string);
        format(string, 120, "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(ID));
        SendCopMessage(string);
        SetPlayerWantedLevel(ID, 0);
        IncreaseScore(playerid, 1);
        GivePlayerMoney(playerid, 2500);
        GivePlayerMoney(ID, -1000);
    }
    if(pwl == 2)
    {
         format(string, 120, "[COP ACTION] You have been fined by officer %s. You have been charged $2,000", PlayerInfo(playerid));
        SendClientMessage(ID, COLOR_DODGERBLUE, string);
        format(string, 120, "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(ID));
        SendClientMessage(playerid, COLOR_DODGERBLUE, string);
        format(string, 120, "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(ID));
        SendCopMessage(string);
        SetPlayerWantedLevel(ID, 0);
        IncreaseScore(playerid, 1);
        GivePlayerMoney(playerid, 2500);
        GivePlayerMoney(ID, -2000);
    }
     if(pwl == 3)
    {
         format(string, 120, "[COP ACTION] You have been fined by officer %s. You have been charged $3,000", PlayerInfo(playerid));
        SendClientMessage(ID, COLOR_DODGERBLUE, string);
        format(string, 120, "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(ID));
        SendClientMessage(playerid, COLOR_DODGERBLUE, string);
        format(string, 120, "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(ID));
        SendCopMessage(string);
        SetPlayerWantedLevel(ID, 0);
        IncreaseScore(playerid, 1);
        GivePlayerMoney(playerid, 2500);
        GivePlayerMoney(ID, -3000);
    }
    else
    {
        if(pwl == 0)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"player is innocent!");
        }
        if(pwl == 4)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
        if(pwl == 5)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
        if(pwl == 6)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
    }
    }
    }
    return 1;
}
Reply
#3

Why are you using foreach to code commands?

Use this format below to do so (You'll need sscanf):
pawn Код:
cmd(tk, playerid, params[])
{
    new lookupid;
    sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
    if(lookupid == -1)
    {
        // No player was entered.
    }
    else if(lookupid == cellmin)
    {
        // Multiple matches found.
    }
    else if(lookupid == INVALID_PLAYER_ID)
    {
        // Entered player is not connected.
    }
    else
    {
        // Found just one player.
    }
    return 1;
}
pawn Код:
cmd(tk, playerid, params[])
{
    new lookupid;
    sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
    if(lookupid == -1) return SendClientMessage(playerid, -1, "Usage: /tk (id/name).");
    else if(lookupid == cellmin) return SendClientMessage(playerid, -1, "Multiple matches found for the specific phrase.");
    else if(lookupid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "That player isn't connected to the server right now.");
    else
    {
        new string[144], pwl = GetPlayerWantedLevel(lookupid);
        if(!IsCop(playerid)) return SendClientMessage(playerid, COLOR_RED, "Only Cops/Army can use this command.");
        if(GetDistanceBetweenPlayers(playerid, lookupid) > 4) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to Ticket.");
        else if(pwl == 1)
        {
            format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $1,000", PlayerInfo(playerid));
            SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
            SendClientMessage(playerid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
            SendCopMessage(string);
            SetPlayerWantedLevel(lookupid, 0);
            IncreaseScore(playerid, 1);
            GivePlayerMoney(playerid, 2500);
            GivePlayerMoney(lookupid, -1000);
        }
        else if(pwl == 2)
        {
            format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $2,000", PlayerInfo(playerid));
            SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
            SendClientMessage(playerid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
            SendCopMessage(string);
            SetPlayerWantedLevel(lookupid, 0);
            IncreaseScore(playerid, 1);
            GivePlayerMoney(playerid, 2500);
            GivePlayerMoney(lookupid, -2000);
        }
        else if(pwl == 3)
        {
            format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $3,000", PlayerInfo(playerid));
            SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
            SendClientMessage(playerid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
            SendCopMessage(string);
            SetPlayerWantedLevel(lookupid, 0);
            IncreaseScore(playerid, 1);
            GivePlayerMoney(playerid, 2500);
            GivePlayerMoney(lookupid, -3000);
        }
        else
        {
            if(pwl == 0) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"player is innocent!");
            else if(pwl == 4) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
            else if(pwl == 5) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
            else if(pwl == 6) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Why are you using foreach to code commands?

Use this format below to do so (You'll need sscanf):
pawn Код:
cmd(tk, playerid, params[])
{
    new lookupid;
    sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
    if(lookupid == -1)
    {
        // No player was entered.
    }
    else if(lookupid == cellmin)
    {
        // Multiple matches found.
    }
    else if(lookupid == INVALID_PLAYER_ID)
    {
        // Entered player is not connected.
    }
    else
    {
        // Found just one player.
    }
    return 1;
}
pawn Код:
cmd(tk, playerid, params[])
{
    new lookupid;
    sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
    if(lookupid == -1) return SendClientMessage(playerid, -1, "Usage: /tk (id/name).");
    else if(lookupid == cellmin) return SendClientMessage(playerid, -1, "Multiple matches found for the specific phrase.");
    else if(lookupid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "That player isn't connected to the server right now.");
    else
    {
        new string[144], pwl = GetPlayerWantedLevel(lookupid);
        if(!IsCop(playerid)) return SendClientMessage(playerid, COLOR_RED, "Only Cops/Army can use this command.");
        if(GetDistanceBetweenPlayers(playerid, lookupid) > 4) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to Ticket.");
        else if(pwl == 1)
        {
            format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $1,000", PlayerInfo(playerid));
            SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
            SendClientMessage(playerid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
            SendCopMessage(string);
            SetPlayerWantedLevel(lookupid, 0);
            IncreaseScore(playerid, 1);
            GivePlayerMoney(playerid, 2500);
            GivePlayerMoney(lookupid, -1000);
        }
        else if(pwl == 2)
        {
            format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $2,000", PlayerInfo(playerid));
            SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
            SendClientMessage(playerid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
            SendCopMessage(string);
            SetPlayerWantedLevel(lookupid, 0);
            IncreaseScore(playerid, 1);
            GivePlayerMoney(playerid, 2500);
            GivePlayerMoney(lookupid, -2000);
        }
        else if(pwl == 3)
        {
            format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $3,000", PlayerInfo(playerid));
            SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
            SendClientMessage(playerid, COLOR_DODGERBLUE, string);
            format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
            SendCopMessage(string);
            SetPlayerWantedLevel(lookupid, 0);
            IncreaseScore(playerid, 1);
            GivePlayerMoney(playerid, 2500);
            GivePlayerMoney(lookupid, -3000);
        }
        else
        {
            if(pwl == 0) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"player is innocent!");
            else if(pwl == 4) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
            else if(pwl == 5) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
            else if(pwl == 6) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
    }
    return 1;
}
i am testing them i try the sscanf but i dont want to /tk id i want nearest player

lets see foreach
Reply
#5

Quote:
Originally Posted by [D]ry[D]esert
Посмотреть сообщение
You used v in a wrong way.
pawn Код:
if(ID != playerid) //this checks if the ID from the loop isnt you, if it was you it will avoid it.
    {
        return 0;
    }
Do this:
pawn Код:
cmd(tk, playerid, params[])
{
    foreach(new ID : Player)
    {
    if(ID != playerid) //this checks if the ID from the loop isnt you, if it was you it will avoid it.
    {
    if(!IsCop(playerid))
        return SendClientMessage(playerid, COLOR_RED, "Only Cops/Army can use this command.");
    new string[120];
    if(GetDistanceBetweenPlayers(playerid, ID) > 4)
    {
        return SendClientMessage(playerid, COLOR_RED, "That player is too far away to Ticket.");
    }
    new pwl = GetPlayerWantedLevel(ID);
    if(pwl == 1)
    {
        format(string, 120, "[COP ACTION] You have been fined by officer %s. You have been charged $1,000", PlayerInfo(playerid));
        SendClientMessage(ID, COLOR_DODGERBLUE, string);
        format(string, 120, "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(ID));
        SendClientMessage(playerid, COLOR_DODGERBLUE, string);
        format(string, 120, "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(ID));
        SendCopMessage(string);
        SetPlayerWantedLevel(ID, 0);
        IncreaseScore(playerid, 1);
        GivePlayerMoney(playerid, 2500);
        GivePlayerMoney(ID, -1000);
    }
    if(pwl == 2)
    {
         format(string, 120, "[COP ACTION] You have been fined by officer %s. You have been charged $2,000", PlayerInfo(playerid));
        SendClientMessage(ID, COLOR_DODGERBLUE, string);
        format(string, 120, "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(ID));
        SendClientMessage(playerid, COLOR_DODGERBLUE, string);
        format(string, 120, "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(ID));
        SendCopMessage(string);
        SetPlayerWantedLevel(ID, 0);
        IncreaseScore(playerid, 1);
        GivePlayerMoney(playerid, 2500);
        GivePlayerMoney(ID, -2000);
    }
     if(pwl == 3)
    {
         format(string, 120, "[COP ACTION] You have been fined by officer %s. You have been charged $3,000", PlayerInfo(playerid));
        SendClientMessage(ID, COLOR_DODGERBLUE, string);
        format(string, 120, "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(ID));
        SendClientMessage(playerid, COLOR_DODGERBLUE, string);
        format(string, 120, "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(ID));
        SendCopMessage(string);
        SetPlayerWantedLevel(ID, 0);
        IncreaseScore(playerid, 1);
        GivePlayerMoney(playerid, 2500);
        GivePlayerMoney(ID, -3000);
    }
    else
    {
        if(pwl == 0)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"player is innocent!");
        }
        if(pwl == 4)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
        if(pwl == 5)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
        if(pwl == 6)
        {
            return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
        }
    }
    }
    }
    return 1;
}
[D]ry[D]esert your worked thank alot +rep

and SickAttackit you made it to be /tk [id] and when i tryed it it still did same thing
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)