it takes the ID as the price!?
#1

So, this is my code..
pawn Код:
if(strcmp(cmd, "/sellhouseto", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetPlayerName(playerid, playername, sizeof(playername));
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(giveplayerid != INVALID_PLAYER_ID)
            {
                if(!strlen(tmp))
                {
                    SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                    return 1;
                }
                new price,house;
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                house = PlayerInfo[playerid][pHouseKey];
                price = strval(tmp);
                if(price < 1 || price > 2000000) return SCM(playerid, COLOR_GRAD1, "Price can't be lower than 1 or higher than 2000000!");
                if(PlayerInfo[playerid][pHouseKey] == 9999)
                {
                    SCM(playerid, COLOR_WHITE, "You don't own a house.");
                    return 1;
                }
                if(PlayerInfo[playerid][pHouseKey] != 9999 && strcmp(playername, HouseInfo[PlayerInfo[playerid][pHouseKey]][hOwner], true) == 0)
                {
                    format(string, sizeof(string),"%s Has offered you to buy his house for %i $.",playername, price);
                    SCM(giveplayerid, COLOR_RLRPGBLUE, string);
                    SCM(giveplayerid, COLOR_LIGHTGREEN,"To accept the offer, type /accept house");
                    format(string, sizeof(string),"You offered %s to buy your house for %i $.",giveplayer);
                    SCM(playerid, COLOR_RLRPGBLUE, string);
                    OfferHouse[giveplayerid] = playerid;
                    HouseInfo[house][hValue] = price;
                    OfferHouseKey[giveplayerid] = house;
                }
            }
            else
            {
                SCM(playerid, COLOR_GREY,"Player is not online");
                return 1;
            }
        }
        return 1;
    }
When someone do this cmd and offer the house to for example id 1, then the price will be 1 even if you offer the house for example 50000!? If you take id 2 the price will be 2 no matter what you type as the price it takes the ID of the player you're offering it to.. Why?
Reply
#2

I suggest you to move your commands to ZCMD. It's MUCH easier.
Reply
#3

Quote:
Originally Posted by kamiliuxliuxliux
Посмотреть сообщение
I suggest you to move your commands to ZCMD. It's MUCH easier.
I didn't want any suggestions. I wanted an awnser on my question. I know zcmd is easier but I don't want to re-make all my cmds into zcmd and sscanf
Reply
#4

Quote:
Originally Posted by Don_Cage
Посмотреть сообщение
I didn't want any suggestions. I wanted an awnser on my question. I know zcmd is easier but I don't want to re-make all my cmds into zcmd and sscanf
Using ZCMD would make it a lot clearer and easier to understand why it isnt working.

Anyway, it looks like you have only used strtok once on the variable tmp and you are using that for both the playerid and price. I don't exactly know how strtok works, but that looks like it is the cause of the problem.

Код:
tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(giveplayerid != INVALID_PLAYER_ID)
            {
                if(!strlen(tmp))
                {
                    SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                    return 1;
                }
                new price,house;
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                house = PlayerInfo[playerid][pHouseKey];
                price = strval(tmp); 
Reply
#5

You could literally use Find and Replace (CTRL + F) and a regex expression to switch all of your commands to YCMD or ZCMD in about 5 seconds.
Reply
#6

There you go:
pawn Код:
if(strcmp(cmd, "/sellhouseto", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetPlayerName(playerid, playername, sizeof(playername));
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(giveplayerid != INVALID_PLAYER_ID)
            {
                if(!strlen(tmp))
                {
                    SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                    return 1;
                }
                new price,house;
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                house = PlayerInfo[playerid][pHouseKey];
                tmp = strtok(cmdtext, idx);
                price = strval(tmp);
                if(price < 1 || price > 2000000) return SCM(playerid, COLOR_GRAD1, "Price can't be lower than 1 or higher than 2000000!");
                if(PlayerInfo[playerid][pHouseKey] == 9999)
                {
                    SCM(playerid, COLOR_WHITE, "You don't own a house.");
                    return 1;
                }
                if(PlayerInfo[playerid][pHouseKey] != 9999 && strcmp(playername, HouseInfo[PlayerInfo[playerid][pHouseKey]][hOwner], true) == 0)
                {
                    format(string, sizeof(string),"%s Has offered you to buy his house for %i $.",playername, price);
                    SCM(giveplayerid, COLOR_RLRPGBLUE, string);
                    SCM(giveplayerid, COLOR_LIGHTGREEN,"To accept the offer, type /accept house");
                    format(string, sizeof(string),"You offered %s to buy your house for %i $.",giveplayer);
                    SCM(playerid, COLOR_RLRPGBLUE, string);
                    OfferHouse[giveplayerid] = playerid;
                    HouseInfo[house][hValue] = price;
                    OfferHouseKey[giveplayerid] = house;
                }
            }
            else
            {
                SCM(playerid, COLOR_GREY,"Player is not online");
                return 1;
            }
        }
        return 1;
    }
Reply
#7

Quote:
Originally Posted by BlackSirrah239
Посмотреть сообщение
Using ZCMD would make it a lot clearer and easier to understand why it isnt working.

Anyway, it looks like you have only used strtok once on the variable tmp and you are using that for both the playerid and price. I don't exactly know how strtok works, but that looks like it is the cause of the problem.

Код:
tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(giveplayerid != INVALID_PLAYER_ID)
            {
                if(!strlen(tmp))
                {
                    SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                    return 1;
                }
                new price,house;
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                house = PlayerInfo[playerid][pHouseKey];
                price = strval(tmp); 
Quote:
Originally Posted by R0
Посмотреть сообщение
There you go:
pawn Код:
if(strcmp(cmd, "/sellhouseto", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetPlayerName(playerid, playername, sizeof(playername));
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(giveplayerid != INVALID_PLAYER_ID)
            {
                if(!strlen(tmp))
                {
                    SCM(playerid, COLOR_GRAD1, "USAGE: /sellhouseto [playerid/PartOfName] [price]");
                    return 1;
                }
                new price,house;
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                house = PlayerInfo[playerid][pHouseKey];
                tmp = strtok(cmdtext, idx);
                price = strval(tmp);
                if(price < 1 || price > 2000000) return SCM(playerid, COLOR_GRAD1, "Price can't be lower than 1 or higher than 2000000!");
                if(PlayerInfo[playerid][pHouseKey] == 9999)
                {
                    SCM(playerid, COLOR_WHITE, "You don't own a house.");
                    return 1;
                }
                if(PlayerInfo[playerid][pHouseKey] != 9999 && strcmp(playername, HouseInfo[PlayerInfo[playerid][pHouseKey]][hOwner], true) == 0)
                {
                    format(string, sizeof(string),"%s Has offered you to buy his house for %i $.",playername, price);
                    SCM(giveplayerid, COLOR_RLRPGBLUE, string);
                    SCM(giveplayerid, COLOR_LIGHTGREEN,"To accept the offer, type /accept house");
                    format(string, sizeof(string),"You offered %s to buy your house for %i $.",giveplayer);
                    SCM(playerid, COLOR_RLRPGBLUE, string);
                    OfferHouse[giveplayerid] = playerid;
                    HouseInfo[house][hValue] = price;
                    OfferHouseKey[giveplayerid] = house;
                }
            }
            else
            {
                SCM(playerid, COLOR_GREY,"Player is not online");
                return 1;
            }
        }
        return 1;
    }
Thansk, forgot that strtok
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)