[FIXED] Buy house problem :'(
#1

hi i got once more error....

when the player is got a house, he still can buy another house....
what dan i do to make the player can only buy 1 house?

here's my /buyhouse command
pawn Код:
CMD:buyhouse(playerid,params[])
{
    #pragma unused params
    new str1[128], housenumber, rows;
    housenumber = GetHouseID(playerid);
    if(housenumber == -1) return SendClientMessageLang(playerid, COLOR_RED, ""Err" You're not near from a house icon", ""Err" Anda sedang tidak berada didekat icon rumah!");

    format(str1, sizeof(str1), "SELECT * FROM `House` WHERE `Name` = '%s'", params);
    mysql_query(str1);
    mysql_store_result();
    /*if(mysql_num_rows() != 0)
    {
        SendClientMessageLang(playerid, COLOR_RED, ""Err" You can only own 1 house!!", ""Err" Anda hanya boleh memiliki 1 rumah!");
    }*/

    rows = mysql_num_rows();
    if(rows == 0)
    {
        if (strcmp(hInfo[housenumber][Name],"For Sale",true)) return SendClientMessageLang(playerid, COLOR_RED, ""Err" This house is not for sale!", ""Err" Rumah ini tidak dijual!");
        if(GetPlayerMoney(playerid)<hInfo[housenumber][Cost]) return SendClientMessageLang(playerid, COLOR_RED, ""Err" Not enough money!", ""Err" Uang anda tidak cukup untuk membeli rumah!");
        if(pInfo[playerid][pDay]<TimeMin) return SendClientMessageLang(playerid, COLOR_RED, ""Err" You need to play for 3 days in-game to buy a house!", ""Err" Anda harus bermain 3 hari in-game untuk membeli rumah!");
        SendClientMessageLang(playerid, COLOR_YELLOW, ""Inf" House succefully bought!", ""Inf" Rumah berhasil dibeli!");

        SetPlayerMoney(playerid,GetPlayerMoney(playerid)-hInfo[housenumber][Cost]);
        format(str1, sizeof(str1), "UPDATE `House` SET `Name` = '%s', `Locked` = '0' WHERE `Houseid` = '%d'", pName(playerid), housenumber);
        mysql_query(str1);
        format(hInfo[housenumber][Name] , 24, pName(playerid));
        hInfo[housenumber][Locked] = 0;

        DestroyPickup(HousePickup[housenumber]);
        HousePickup[housenumber] = CreatePickup(1272, 23, hInfo[housenumber][iconx], hInfo[housenumber][icony], hInfo[housenumber][iconz]);
    }
    else
    {
        SendClientMessageLang(playerid, COLOR_RED, ""Err" You can only own 1 house!!", ""Err" Anda hanya boleh memiliki 1 rumah!");
    }
    mysql_free_result();
    return 1;
}
Reply
#2

EDIT:

fixed...

i forgotten to change this line

pawn Код:
format(str1, sizeof(str1), "SELECT * FROM `House` WHERE `Name` = '%s'", params);
into
pawn Код:
format(str1, sizeof(str1), "SELECT * FROM `House` WHERE `Name` = '%s'", pName(playerid));
a very small mistake can make you crazy
Reply
#3

add this to your code -

Код:
if(PlayerInfo[playerid][pHouseOwned] == 1) return SendClientMessage(playerid, -1, "You already own a house");
Hope this helps you out.

Add you own Variable there, you will have to create a new player enum though
Reply
#4

no i just forgotten to change the format
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)