You're nowhere close to any house.
#1

I recently developed dynamic House System which always returns that we're not at the house even if we are when buying it.

I can send you anything required.

pawn Код:
CMD:buyprop(playerid,params[])
{
    new done=0;
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid,2,HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ]))
        {
            if(GetPlayerMoney(playerid) >= HouseInfo[i][hPrice])
            {
                if(pInfo[playerid][House] == 0)
                {
                    if(strcmp(HouseInfo[i][hOwner],"",false))
                    {
                        format(HouseInfo[i][hOwner],24,"%s",pName(playerid));
                        pInfo[playerid][House] = i;
                        format(string,sizeof(string),"You've successfully bought property named \"%s\"",HouseInfo[i][hName]);
                        SendClientMessage(playerid,COLOR_YELLOW,string);
                        format(string,sizeof(string),"purchased a property named %s",HouseInfo[i][hName]);
                        DestroyDynamicPickup(HouseInfo[i][hPickup]);
                        DestroyDynamicMapIcon(HouseInfo[i][hIcon]);
                        GivePlayerMoney(playerid,-HouseInfo[i][hPrice]);
                        format(string,sizeof(string),"Owner: %s",HouseInfo[i][hOwner]);
                        HouseInfo[i][hText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ], 50, INVALID_PLAYER_ID,INVALID_VEHICLE_ID, 0, -1,0);
                        HouseInfo[i][hPickup] = CreateDynamicPickup(1272,1,HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ],-1,0,-1,50.0);
                        format(query,sizeof(query),"INSERT INTO `timeline` (name,date,text) VALUES ('%s',CURDATE(),'%s')",pName(playerid),string);
                        mysql_query(query);
                        done=1;
                        return 1;
                    }
                    else return SendClientMessage(playerid,COLOR_GREY,"That house is already owned by someone else.");
                }
                else return SendClientMessage(playerid,COLOR_GREY,"You already own a house.");
            }
            else return SendClientMessage(playerid,COLOR_GREY,"You don't have enough money to buy this property.");
        }
        else return SendClientMessage(playerid,COLOR_GREY,"You're nowhere close to any house.");
    }
    return 1;
}
Reply
#2

Are houses loading successfully?
Reply
#3

Do not, repeat do not, ever return inside a loop unless you explicitly want to break out of it. Your case: if they're not in range of the very first house you break the loop, not even checking any of the other ones.

These two also shouldn't be inside the loop body:
pawn Код:
if(GetPlayerMoney(playerid) >= HouseInfo[i][hPrice])
            {
                if(pInfo[playerid][House] == 0)
                {
Process those before starting the loop.
Reply
#4

Any suggestion how to check if money is greater than the house price without loop? Or I create another loop above this one?

Plus, is there anyway I can covert those loops to foreach ones?

Thanks for replies!

+rep

EDIT: I realized it doesn't load the houses actually. Can't figure out what is wrong.

pawn Код:
stock LoadHouses()
{
    new id = 1;
    while(id < MAX_HOUSES)
    {
        format(query,sizeof(query),"SELECT * FROM `houses` WHERE `id` = '%d'",id);
        mysql_query(query);
        mysql_store_result();
        if(mysql_num_rows())
        {
            if(mysql_fetch_row_format(query,"|"))
            {
                sscanf(query,"p<|>fffis[128]ii",HouseInfo[id][hX],HouseInfo[id][hY],HouseInfo[id][hZ],HouseInfo[id][hInt],HouseInfo[id][hName],HouseInfo[id][hPrice],HouseInfo[id][hMoney]);
                CreateHouse(HouseInfo[id][hX],HouseInfo[id][hY],HouseInfo[id][hZ],HouseInfo[id][hInt],HouseInfo[id][hName],HouseInfo[id][hPrice]);
                HouseInfo[id][hIcon] = CreateDynamicMapIcon(HouseInfo[id][hX],HouseInfo[id][hY],HouseInfo[id][hZ],31,-1,-1,-1,-1,50.0);
            }
        }
        id++;
    }
    return 1;
}
Reply
#5

Still unresolved.
Reply
#6

pawn Код:
stock LoadHouses()
{
    new id = 1;
    while(id < MAX_HOUSES)
    {
        format(query,sizeof(query),"SELECT * FROM `houses` WHERE `id` = %d",id);
        mysql_query(query);
        mysql_store_result();
        if(mysql_num_rows())
        {
            if(mysql_fetch_row_format(query,"|"))
            {
                sscanf(query,"p<|>fffis[128]ii",HouseInfo[id][hX],HouseInfo[id][hY],HouseInfo[id][hZ],HouseInfo[id][hInt],HouseInfo[id][hName],HouseInfo[id][hPrice],HouseInfo[id][hMoney]);
                CreateHouse(HouseInfo[id][hX],HouseInfo[id][hY],HouseInfo[id][hZ],HouseInfo[id][hInt],HouseInfo[id][hName],HouseInfo[id][hPrice]);
                HouseInfo[id][hIcon] = CreateDynamicMapIcon(HouseInfo[id][hX],HouseInfo[id][hY],HouseInfo[id][hZ],31,-1,-1,-1,-1,50.0);
                printf("hX %f", HouseInfo[id][hX]);
            }
        }
        id++;
    }
    return 1;
}
Try to print some variables, see what it gives. Also you dont need ' ' in your query for integers and instead of MAX_HOUSES queries you can have only one 'SELECT * FROM `houses`'.
Reply
#7

Quote:
Originally Posted by Tayab
Посмотреть сообщение
Any suggestion how to check if money is greater than the house price without loop? Or I create another loop above this one?
Ah sorry, I overlooked. That can be in the loop. However, it's probably a better practice to first establish that they are, in fact, in range. You can break the loop at that point and access the array directly.

pawn Код:
new houseid = -1;
for(new i = 0; i < MAX_HOUSES; i++)
{
    if(IsPlayerInRangeOfPoint(playerid,2,HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ]))
    {
        houseid = i;
        break;
    }
}

if(houseid == -1)
{
    // Not in range
    return 1;
}

if(GetPlayerMoney(playerid) >= HouseInfo[houseid][hPrice])
{
    // etc, etc
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)