SA-MP Forums Archive
buy house problem [mysql r33] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: buy house problem [mysql r33] (/showthread.php?tid=639007)



buy house problem [mysql r33] - Jumberi - 10.08.2017

Hey,

i got some problem with my script, so basically everything works good on this house script, when im creating house im buying and House Owner and house owned columns isnt changing and so basically i just need ur help guys,

there is a code

PHP Code:
forward LoadHouse();
public 
LoadHouse()
{
mysql_tquery(MySQLCon, "SELECT * FROM "HOUSES_TABLE" ORDER BY `ID` ASC", "OnHouseLoad", ""); 
}

PHP Code:
forward OnHouseLoad();
public 
OnHouseLoad() {
    new 
rows, fields, houseLoadTime;
    
cache_get_data(rows, fields);
    if(!
rows)
        return 
printf("[House] No houses to load.");
    if(
rows) {
        
houseLoadTime = GetTickCount();
        for(new 
i = 0; i < rows; i++) {
            
HouseInfo[houses][hID] = cache_get_row_int(i, 0, MySQLCon);
            
HouseInfo[houses][hExt][0] = cache_get_row_float(i, 1, MySQLCon);
            
HouseInfo[houses][hExt][1] = cache_get_row_float(i, 2, MySQLCon);
            
HouseInfo[houses][hExt][2] = cache_get_row_float(i, 3, MySQLCon);
            
HouseInfo[houses][hInt][0] = cache_get_row_float(i, 4, MySQLCon);
            
HouseInfo[houses][hInt][1] = cache_get_row_float(i, 5, MySQLCon);
            
HouseInfo[houses][hInt][2] = cache_get_row_float(i, 6, MySQLCon);
            
HouseInfo[houses][hInterior] = cache_get_row_int(i, 7, MySQLCon);
            
cache_get_row(i, 8, HouseInfo[houses][hOwner], MySQLCon, MAX_PLAYER_NAME);
            
HouseInfo[houses][hPrice] = cache_get_row_int(i, 9, MySQLCon);
            
HouseInfo[houses][hOwned] = cache_get_row_int(i, 10, MySQLCon);
            
HouseInfo[houses][hType] = cache_get_row_int(i, 11, MySQLCon);
            if(
HouseInfo[houses][hOwned] == 0) {
                
HouseInfo[houses][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houses][hExt][0], HouseInfo[houses][hExt][1], HouseInfo[houses][hExt][2]);
            }
            else {
                
HouseInfo[houses][hPickup] = CreateDynamicPickup(1239, 1, HouseInfo[houses][hExt][0], HouseInfo[houses][hExt][1], HouseInfo[houses][hExt][2]);
            }
            
houses++;
        }
        
printf("Loaded %d houses in %02d ms.", houses, GetTickCount() - houseLoadTime);
    }
    return 
1;
} 
buyhouse

PHP Code:
CMD:buyhouse(playerid) {
    for(new 
h; h < houses; h++) {
        if(
IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[h][hExt][0], HouseInfo[h][hExt][1], HouseInfo[h][hExt][2])) {
            if(!
HouseInfo[h][hOwned]) {
                if(
pInfo[playerid][pMoney] < HouseInfo[h][hPrice])
                    return 
SendClientMessage(playerid, COLOR_RED, "ERROR: {FFFFFF}You have insufficient funds to do this action('s).");
                if(
pInfo[playerid][pHouseKey] > 1)
                    return 
SendClientMessage(playerid, COLOR_RED, "ERROR: {FFFFFF}You already own a house.");
                
SendClientMessage(playerid, COLOR_WHITE, "Property has been {2BFF00}purchased.");
                
pInfo[playerid][pHouseKey] = 1;
                
HouseInfo[h][hOwned] = 1;
                
HouseInfo[h][hOwner] = GetName(playerid);
                
GiveCash(playerid, -HouseInfo[h][hPrice]);
                
DestroyDynamicPickup(HouseInfo[h][hPickup]);
                
HouseInfo[h][hPickup] = CreateDynamicPickup(1239, 1, HouseInfo[h][hExt][0], HouseInfo[h][hExt][1], HouseInfo[h][hExt][2]);
            }
        }
    }
    return 
1;
} 
and if u know the solution of this please respond!


Re: buy house problem [mysql r33] - Misiur - 10.08.2017

Well, you don't save the new values in buyhouse, so why would they change.


Re: buy house problem [mysql r33] - JaydenJason - 10.08.2017

There's no update query?


Re: buy house problem [mysql r33] - Shaheen - 10.08.2017

u need to make an update query and when player buys a house it should be updated


Re: buy house problem [mysql r33] - Jumberi - 10.08.2017

Quote:
Originally Posted by Misiur
View Post
Well, you don't save the new values in buyhouse, so why would they change.
guys i forgot to show u savehouse

PHP Code:
tock SaveHouses() {
    new 
Query[325];
    for(new 
h; h < houses; h++) {
        
format(Query, sizeof Query, "UPDATE `houses` SET `ExtX`=%0.2f,`ExtY`=%0.2f,`ExtZ`=%0.2f,`IntX`=%0.2f,`IntY`=%0.2f,`IntZ`=%0.2f,`Interior`=%d,`Owner`='%s',`Price`=%d,`Owned`=%d,`Type`=%d WHERE `ID`=%d",
        
HouseInfo[h][hExt][0],
        
HouseInfo[h][hExt][1],
        
HouseInfo[h][hExt][2],
        
HouseInfo[h][hInt][0],
        
HouseInfo[h][hInt][1],
        
HouseInfo[h][hInt][2],
        
HouseInfo[h][hInterior],
        
HouseInfo[h][hOwner],
        
HouseInfo[h][hPrice],
        
HouseInfo[h][hOwned],
        
HouseInfo[h][hType],
        
HouseInfo[h][hID]);
        
mysql_tquery(MySQLCon, Query, "", "");
    }
    return 
1;
}