The house is already bought but its not!? D:
#1

Hello mates so i have a problem
I had created 2 houses
I can buy the first correctly
but when i go at the second it says that this house is already bought whats could be the problem?
here is my buyhouse command
PHP код:
CMD:buyhouse(playerid,params[])
{
    new 
hid GetHouseID(playerid);
    new 
price;
    
HouseInfo[hid][HPrice] = price;
    if(
GetPlayerMoney(playerid) < price) return SendClientMessage(playerid, -1""COL_RED"SERVER"COL_WHITE": You don't have so much money to buy the house");
    if(
HouseInfo[hid][HOwned] == 1) return SendClientMessage(playerid,-1,""COL_RED"SERVER"COL_WHITE"You can't buy this house because it is already bought!");
    if(
HouseInfo[hid][HOwnerID] == pinfo[playerid][ID]) return SendClientMessage(playerid, -1""COL_RED"You can't buy your own house!");
    if(!
IsPlayerNearHouse(playerid)) return SendClientMessage(playerid, -1""COL_RED"SERVER"COL_WHITE"You can't buy a house if you are not near it!");
    
ShowPlayerDialog(playerid,DIALOG_BUYHOUSE,DIALOG_STYLE_INPUT,"BUY A HOUSE",""COL_RED"You want to buy a house! Since you can afford it please insert HouseName you want!","OK","Cancel");
    return 
1;

and here is my gethouse id function
PHP код:
stock GetHouseID(playerid)
{
    for(new 
i=0i<MAX_HOUSESi++)
    {
        if(
IsPlayerInRangeOfPoint(playerid1HouseInfo[i][XExit], HouseInfo[i][YExit], HouseInfo[i][ZExit]))
        {
            return 
i;
        }
        else if(
IsPlayerInRangeOfPoint(playerid1HouseInfo[i][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt]))
        {
            return 
i;
        }
    }
    return 
INVALID_HOUSE_ID;

Reply
#2

It is more than likely a problem with how HOwned is being loaded/saved, or how your houses are created.
Can you show how those are handled?
Reply
#3

PHP код:
function CreateHouse(Float:Xen,Float:Yen,Float:Zen,Float:Xex,Float:Yex,Float:Zex,virtualworld,interiorid,price)
{
        static 
hCount;
    new 
hid hCounthCount += 1;
    new 
string[100];
    new 
query[350];
    
hid += 1;
    
HouseInfo[hid][XEnt] = Xen;
    
HouseInfo[hid][YEnt] = Yen;
    
HouseInfo[hid][ZEnt] = Zen;
    
HouseInfo[hid][XExit] = Xex;
    
HouseInfo[hid][YExit] = Yex;
    
HouseInfo[hid][ZExit] = Zex;
    
HouseInfo[hid][HVirtualWorld] = virtualworld;
    
HouseInfo[hid][HInterior] = interiorid;
    
HouseInfo[hid][HPrice] = price;
    
HouseInfo[hid][HOwned] = 0;
    
HouseInfo[hid][HLocked] = 0;
    
HouseInfo[hid][HOwnerID] = -1;
    
format(string,sizeof(string),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",price);
    
HouseInfo[hid][H3D] = CreateDynamic3DTextLabel(stringCOLOR_YELLOWXen,  Yen,  Zen40.0);
    
mysql_format(mysql,query,sizeof(query), "INSERT INTO `houses` (`Xent`, `Yent`, `Zent`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld`, `HInterior`, `HPrice`,\
    `HOwned`, `HLocked`) VALUES (%f, %f, %f, %f, %f, %f, %d, %d, %d, 0, 0)"
Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
       
mysql_tquery(mysqlquery"RegisterHouse","i",hid); 

    return 
1;

LoadHouses function
PHP код:
LoadHouses()
{
    new 
Cache:result,rows;
    new 
label[250];
    
result mysql_query(mysql"SELECT * FROM `houses`");
    if((
rows cache_num_rows()))
    {
        for(new 
i=0rowsi++)
        {
            
HouseInfo[i][XEnt] = cache_get_field_content_float(i"XEnt"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
            
HouseInfo[i][YEnt] = cache_get_field_content_float(i"YEnt"); //Above
            
HouseInfo[i][ZEnt] = cache_get_field_content_float(i"ZEnt");//Above
            
HouseInfo[i][XExit] = cache_get_field_content_float(i"XExit");//Above. Since player's position is a float, we use cache_get_field_content_float
            
HouseInfo[i][YExit] = cache_get_field_content_float(i"YExit");//Above
            
HouseInfo[i][ZExit] = cache_get_field_content_float(i"ZExit");//Above
            
HouseInfo[i][HVirtualWorld] = cache_get_field_content_int(i"HVirtualWorld");
            
HouseInfo[i][HInterior] = cache_get_field_content_int(i"HInterior");
            
HouseInfo[i][HPrice] = cache_get_field_content_int(i"HPrice");
            
HouseInfo[i][HOwnerID] = cache_get_field_content_int(0"HOwnerID");
            
HouseInfo[i][HOwned] = cache_get_field_content_int(i"HOwned");
            
HouseInfo[i][HLocked] = cache_get_field_content_int(i"HLocked");
            
cache_get_field_content(i"HName"HouseInfo[i][HName], 30);
            if(
HouseInfo[i][HOwned] == 1)
        {
                
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[i][HName]);
                
HouseInfo[i][H3D] = CreateDynamic3DTextLabel(labelCOLOR_YELLOWHouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
        }
        
        else if(
HouseInfo[i][HOwned] == 0)
        {
            
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",HouseInfo[i][HPrice]);
            
HouseInfo[i][H3D] = CreateDynamic3DTextLabel(labelCOLOR_YELLOWHouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);

        }
        }
        
printf("Successfully Loaded All Houses! ( %d )",rows);
    }
    else
    {
        print(
"There are no houses to load!");
    }
        
cache_delete(result);

Reply
#4

Have you checked out the mysql field for the 2nd house?
Does it say HOwned 1 or 0?
Reply
#5

I Guess the problem is my buyhouse function and the 1st query that i don't use "WHERE `hID` = %d"
i guess?
So i changed it
from
PHP код:
function BuyHouse(playerid)
{
    new 
query[400],label[150];
    new 
houseid GetHouseID(playerid);
    
HouseInfo[houseid][HOwned] = true;
    
mysql_format(mysql,query,sizeof(query), "UPDATE `houses` SET `HOwned` = 1",HouseInfo[houseid][HOwned]);
      
mysql_query(mysqlquery);
    
mysql_format(mysql,query,sizeof(query),"UPDATE `houses` SET `HOwnerID`= %d WHERE `hID` = '%d'",pinfo[playerid][ID],HouseInfo[houseid][HOwned],HouseInfo[houseid][hID]);
    
mysql_query(mysql,query);
    
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[houseid][HName]);
    
UpdateDynamic3DTextLabelText(HouseInfo[houseid][H3D],COLOR_YELLOW,label);
    return 
1;

to
PHP код:
function BuyHouse(playerid)
{
    new 
query[400],label[150];
    new 
houseid GetHouseID(playerid);
    
HouseInfo[houseid][HOwned] = true;
    
//mysql_format(mysql,query,sizeof(query), "UPDATE `houses` SET `HOwned` = 1",HouseInfo[houseid][HOwned]);
      //mysql_query(mysql, query);
    
mysql_format(mysql,query,sizeof(query),"UPDATE `houses` SET `HOwnerID`= %d, SET `HOwned` = 1 WHERE `hID` = '%d'",pinfo[playerid][ID],HouseInfo[houseid][HOwned],HouseInfo[houseid][hID]);
    
mysql_query(mysql,query);
    
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[houseid][HName]);
    
UpdateDynamic3DTextLabelText(HouseInfo[houseid][H3D],COLOR_YELLOW,label);
    return 
1;

And going to test it.
Reply
#6

Also the
Код:
mysql_format(mysql,query,sizeof(query), "UPDATE `houses` SET `HOwned` = 1",HouseInfo[houseid][HOwned]);
part is unnecessary because you already defined the value.

EDIT:

Also this part of your code is broken:
Код:
    mysql_format(mysql,query,sizeof(query),"UPDATE `houses` SET `HOwnerID`= %d, SET `HOwned` = 1 WHERE `hID` = '%d'",pinfo[playerid][ID],HouseInfo[houseid][HOwned],HouseInfo[houseid][hID]);
You're currently setting the value of hID to be equal to hOwned, because once again you defined the the HOwned yourself.
Reply
#7

PHP код:
function BuyHouse(playerid)
{
    new 
query[400],label[150];
    new 
houseid GetHouseID(playerid);
    
HouseInfo[houseid][HOwned] = true;
    
mysql_format(mysql,query,sizeof(query),"UPDATE `houses` SET `HOwnerID`= '%d', SET `HOwned` = 1 WHERE `hID` = '%d'",pinfo[playerid][ID],HouseInfo[houseid][hID]);
    
mysql_query(mysql,query);
    
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[houseid][HName]);
    
UpdateDynamic3DTextLabelText(HouseInfo[houseid][H3D],COLOR_YELLOW,label);
    return 
1;

Changed it as you said
though it doesnt update the table since there is a syntax according to mysql_log
pawn Код:
01:32:56] [DEBUG] mysql_format - connection: 1, len: 200, format: "UPDATE `houses` SET `HName` = '%s' WHERE `hID` = '%d'"
[01:32:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `houses` SET `HName` = 'test' WHERE `hID` = '0'", callback: "(null)", format: "(null)"
[01:32:56] [DEBUG] mysql_format - connection: 1, len: 400, format: "UPDATE `houses` SET `HOwnerID`= '%d', SET `HOwned` = 1 WHERE `hID` = '%d'"
[01:32:56] [DEBUG] mysql_query - connection: 1, query: "UPDATE `houses` SET `HOwnerID`= '1', SET `HOwned` = 1 WHERE `hID", use_cache: true
[01:32:56] [DEBUG] CMySQLQuery::Execute - starting query execution
[01:32:56] [ERROR] CMySQLQuery::Execute - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET `HOwned` = 1 WHERE `hID` = '0'' at line 1
[01:32:56] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[01:32:56] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 0.451 milliseconds
[01:32:56] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
Also it says where `hid` = 0 but my 1st house starts from houseid 1 D:
Lot problems pff
Reply
#8

Replace HouseInfo[houseid][hID] with houseid on BuyHouse mysql format.
Reply
#9

Quote:
Originally Posted by CmZxC
Посмотреть сообщение
Replace HouseInfo[houseid][hID] with houseid on BuyHouse mysql format.
I did and now it updates the text label from the other Post LMAO
still got the same problem
i noticed that it updates the howned column and set it to 1 but hownerid and hname remains the same as there is an sql syntax error?
Also even it says it updates hname to test it doesnt set the hname at the house id since it says HID= 0 and i don't get why?
pawn Код:
[01:52:15] [DEBUG] mysql_format - connection: 1, len: 400, format: "UPDATE `houses` SET `HOwnerID`= '%d', SET `HOwned` = 1 WHERE `hID` = '%d'"
[01:52:15] [DEBUG] mysql_query - connection: 1, query: "UPDATE `houses` SET `HOwnerID`= '1', SET `HOwned` = 1 WHERE `hID", use_cache: true
[01:52:15] [DEBUG] CMySQLQuery::Execute - starting query execution
[01:52:15] [ERROR] CMySQLQuery::Execute - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET `HOwned` = 1 WHERE `hID` = '0'' at line 1
[01:52:15] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[01:52:15] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 0.640 milliseconds
Do i need to change something at createhouse function?
Reply
#10

Код:
[01:52:15] [DEBUG] mysql_format - connection: 1, len: 400, format: "UPDATE `houses` SET `HOwnerID`= '%d',
 SET `HOwned` = 1 WHERE `hID` = '%d'"
You have a second "SET" in your format.
"UPDATE `houses` SET `HOwnerID`= '%d', SET `HOwned` = 1 WHERE `hID` = '%d'"

Remove the second SET, keep everything else.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)