Sellvehicle command [You can't sell to yourself]
#1

Ey guys, I've got a sellvehicle command, but how can I make it that we can't sell our vehicles to ourselves?
I dont know how to do it? any help?, post me the new code if it's not impossible!
pawn Код:
}
    if(strcmp(cmd, "/sellvehicle", true) == 0)
    {
        new pvehicleid = GetPlayerVehicleID(playerid);
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            new price = strvalEx(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if(ProxDetectorS(7.0, playerid, giveplayerid))
                {
                    if(IsPlayerInAnyVehicle(playerid))
                    {
                        if(PlayerVehicleID1[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 1;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID2[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 2;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID3[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 3;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID4[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 4;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID5[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 5;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else
                        {
                            SendClientMessage(playerid,COLOR_GREY," You are not at a vehicle that you own.");
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid,COLOR_GREY," You are not at any vehicle.");
                    }
                }
                else
                {
                    SendClientMessage(playerid,COLOR_GREY," You are not near the player.");
                }
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY," Player Not Connected.");
            }
        }
        return 1;
    }
Thank you!
Reply
#2

Compare playerid with giveplayerid and disallow the command if it returns true (matching IDs)

Example:
pawn Код:
if( giveplayerid == playerid )
    return SendClientMessage( playerid, 0xFF0000AA, "[ERROR] {FFFFFF}You can't sell to yourself." );
Reply
#3

Can you post the new code?
Reply
#4

So I just did the thing and when I wanted to test it kept appearing "You can't sell yourself" even if I wanted to sell it to someone else, here's the code buddy

pawn Код:
if(strcmp(cmd, "/sellvehicle", true) == 0)
    {
        new pvehicleid = GetPlayerVehicleID(playerid);
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            new price = strvalEx(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if( giveplayerid == playerid )    return SendClientMessage( playerid, 0xFF0000AA, "[ERROR] {FFFFFF}You can't sell to yourself." );
                if(ProxDetectorS(7.0, playerid, giveplayerid))
                {
                    if(IsPlayerInAnyVehicle(playerid))
                    {
                        if(PlayerVehicleID1[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 1;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID2[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 2;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID3[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 3;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID4[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 4;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID5[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 5;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else
                        {
                            SendClientMessage(playerid,COLOR_GREY," You are not at a vehicle that you own.");
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid,COLOR_GREY," You are not at any vehicle.");
                    }
                }
                else
                {
                    SendClientMessage(playerid,COLOR_GREY," You are not near the player.");
                }
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY," Player Not Connected.");
            }
        }
        return 1;
    }
Reply
#5

any help?
Reply
#6

pawn Код:
}
    if(strcmp(cmd, "/sellvehicle", true) == 0)
    {
        new pvehicleid = GetPlayerVehicleID(playerid);
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            new price = strvalEx(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if(ProxDetectorS(7.0, playerid, giveplayerid))
                {
                    if(IsPlayerInAnyVehicle(playerid))
                    {
                        if(PlayerVehicleID1[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 1;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID2[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 2;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID3[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 3;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID4[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 4;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID5[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 5;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else
                        {
                            SendClientMessage(playerid,COLOR_GREY," You are not at a vehicle that you own.");
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid,COLOR_GREY," You are not at any vehicle.");
                    }
                }
                else
                {
                    SendClientMessage(playerid,COLOR_GREY," You are not near the player.");
                }
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY," Player Not Connected.");
            else
            {
    if( giveplayerid == playerid )
    return SendClientMessage( playerid, 0xFF0000AA, "[ERROR] {FFFFFF}You can't sell to yourself." );
            }
        }
        return 1;
    }
That might work.
Reply
#7

no it didn't work, it just bugged off my script cuz of brackets thanks for the try anyway bro .. any other help?
Reply
#8

Try this:

pawn Код:
if(strcmp(cmd, "/sellvehicle", true) == 0)
    {
        new pvehicleid = GetPlayerVehicleID(playerid);
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
                return 1;
            }
            if(playerid == giveplayerid)
            {
                SendClientMessageEx(playerid, COLOR_GREY, "You can not use this command on yourself.");
                return 1;
            }
            new price = strvalEx(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if(ProxDetectorS(7.0, playerid, giveplayerid))
                {
                    if(IsPlayerInAnyVehicle(playerid))
                    {
                        if(PlayerVehicleID1[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 1;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID2[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 2;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID3[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 3;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID4[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 4;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else if(PlayerVehicleID5[playerid] == pvehicleid)
                        {
                            SellVehicleOffer[giveplayerid] = playerid;
                            SellVehicleOfferTime[giveplayerid] = 60;
                            SellVehiclePrice[giveplayerid] = price;
                            SellVehicleSlot[giveplayerid] = 5;
                            format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            format(string,sizeof(string),"%s has just offered to sell you his %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
                            SendClientMessage(giveplayerid,COLOR_YELLOW,string);
                        }
                        else
                        {
                            SendClientMessage(playerid,COLOR_GREY," You are not at a vehicle that you own.");
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid,COLOR_GREY," You are not at any vehicle.");
                    }
                }
                else
                {
                    SendClientMessage(playerid,COLOR_GREY," You are not near the player.");
                }
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY," Player Not Connected.");
            }
        }
        return 1;
    }
Reply
#9

Thanks bro, it worked and I tested it! +REPed!
Reply
#10

No Problem!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)