House help please
#1

Basically I'm trying to make it so if you already own a house you won't be able to buy a new one, but currently as soon as I get in range of the house I'm able to buy it and it won't show any error messages...

pawn Код:
CMD:buyhouse(playerid,params[])
{
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(strcmp(HouseInfo[i][hOwner], PlayerInfo[playerid][Name]) == 0) return SendClientMessage(playerid, RED, "You have a house already.");
        if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]))
        {
            if(strcmp(HouseInfo[i][hOwner], "State") == 0)
            {
                if(PlayerInfo[playerid][Money] < HouseInfo[i][hCost]) return SendClientMessage(playerid, RED, "You do not have enough money.");
                new Query[70], DBResult:Result;
                format(Query, sizeof(Query), "UPDATE houses SET owner = '%s' WHERE id = %d", DB_Escape(PlayerInfo[playerid][Name]), i);
                Result = db_query(CNRDB, Query);
                if(Result)
                {
                    GivePlayerMoneyEx(playerid, -HouseInfo[i][hCost]);
                    format(HouseInfo[i][hOwner], 21, "%s", PlayerInfo[playerid][Name]);
                    new HLInfo[85];
                    format(HLInfo, sizeof(HLInfo), "%s\nOwner: %s\nCost: %d\nID: %d", HouseInfo[i][hName], HouseInfo[i][hOwner], HouseInfo[i][hCost], i);
                    UpdateDynamic3DTextLabelText(House[i], 0x00FF00FF, HLInfo), HLInfo = "\0";
                    SendClientMessage(playerid, SERVER, "You bought the house.");
                    break;
                }
                else if(!Result) SendClientMessage(playerid, RED, "Database error.");
                db_free_result(Result);
            }
            else SendClientMessage(playerid, RED, "This house is not for sale.");
        }
    }
    return 1;
}
Is there a way to fix this or do I need to make a variable to see if player has a house or not?
Reply
#2

Try something like this
pawn Код:
if(strcmp(HouseInfo[i][hOwner], PlayerInfo[playerid][Name]) < 1) return SendClientMessage(playerid, RED, "You have a house already.")
Reply
#3

To simplify this i would just send an request to the db to check if the user already has a house:

then if he exists with either Name or OwnerId inside the houses table, return the SCM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)