Problem with house system - Can't buy houses
#1

Hi,

I've been trying to make a house system, but I came across a problem which I just can't seem to solve.
So say I create a house in Idlewood, then I buy it. It works fine. But as soon as I make another house somewhere else and I try to buy it, it will put me inside the first house I made (Idlewood) and when I exit and go back to the house which wasn't working. Nothing would change. You will still be able to buy the house, I keep trying and it doesn't work.

So in short words, I make a house in Idlewood and buy it but when I make a house somewhere else and try to buy it, it won't work.

Here is the code,

pawn Код:
if(dialogid == BUY_HOUSE && response==1)
    {
        switch(listitem)
        {
            case 0:
            {
                new id = 0, name[25], count = 0;

                if( count >= 3 )
                    return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You can't own more than 3 houses at a time");

                if( GetPlayerMoney(playerid) < hInfo[id][Price] )
                    return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You do not have enough money to buy this house");

                for(new i=1; i<=CreatedHouses; i++)
                {
                    id = i;
                    break;
                }
                for(new i=1; i<=CreatedHouses; i++)
                {
                    GetPlayerName(playerid, name, sizeof(name));
                    if(strcmp(name, hInfo[i][Owner]) == 0)
                    {
                        count++;
                    }
                }

                //count++;

                GetPlayerName(playerid, name, 25);
                hInfo[id][Owned] = 1;
                hInfo[id][Owner] = name;

                GivePlayerMoney( playerid, -hInfo[id][Price] );

                DestroyDynamicMapIcon(hInfo[id][Icon]);

                PutPlayerInHouse(playerid, id);

                new
                    str[300],
                    query[400];

                format(str, sizeof(str),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s", hInfo[id][Owner], hInfo[id][Price], (hInfo[id][Locked] == 1) ? ("Yes") : ("No"));
                UpdateDynamic3DTextLabelText(Text3D:hInfo[id][Label], 0xFF0000FF, str);

                format(query, sizeof(query), "UPDATE `"Houses_Table"` SET `Owned` = '%i', `Owner` = '%s' WHERE `ID` = '%i'",hInfo[id][Owned], hInfo[id][Owner], id);
                mysql_query(query);
            }
        }
    }
I can't seem to fix it
Reply
#2

PHP код:
if(dialogid == BUY_HOUSE && response==1)
    {
        switch(
listitem)
        {
            case 
0:
            {
                new 
id 0name[25], count 0;
                 for(new 
i=1i<=CreatedHousesi++)
                {
                    
GetPlayerName(playeridnamesizeof(name));
                    if(
strcmp(namehInfo[i][Owner]) == 0)
                    {
                        
count++;
                    }
                }
                if( 
count >= )
                    return 
SendClientMessage(playeridRED"ERROR:{FFFFFF} You can't own more than 3 houses at a time");
                if( 
GetPlayerMoney(playerid) < hInfo[id][Price] )
                    return 
SendClientMessage(playeridRED"ERROR:{FFFFFF} You do not have enough money to buy this house");
                for(new 
i=1i<=CreatedHousesi++)//pointless = this is your problem
                
{
                    
id i;
                    break;
                }
           
                
//count++;
                
GetPlayerName(playeridname25);
                
hInfo[id][Owned] = 1;
                
hInfo[id][Owner] = name;
                
GivePlayerMoneyplayerid, -hInfo[id][Price] );
                
DestroyDynamicMapIcon(hInfo[id][Icon]);
                
PutPlayerInHouse(playeridid);
                new
                    
str[300],
                    
query[400];
                
format(strsizeof(str),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s"hInfo[id][Owner], hInfo[id][Price], (hInfo[id][Locked] == 1) ? ("Yes") : ("No"));
                
UpdateDynamic3DTextLabelText(Text3D:hInfo[id][Label], 0xFF0000FFstr);
                
format(querysizeof(query), "UPDATE `"Houses_Table"` SET `Owned` = '%i', `Owner` = '%s' WHERE `ID` = '%i'",hInfo[id][Owned], hInfo[id][Owner], id);
                
mysql_query(query);
            }
        }
    } 
Reply
#3

Quote:
Originally Posted by Matess
Посмотреть сообщение
PHP код:
if(dialogid == BUY_HOUSE && response==1)
    {
        switch(
listitem)
        {
            case 
0:
            {
                new 
id 0name[25], count 0;
                 for(new 
i=1i<=CreatedHousesi++)
                {
                    
GetPlayerName(playeridnamesizeof(name));
                    if(
strcmp(namehInfo[i][Owner]) == 0)
                    {
                        
count++;
                    }
                }
                if( 
count >= )
                    return 
SendClientMessage(playeridRED"ERROR:{FFFFFF} You can't own more than 3 houses at a time");
                if( 
GetPlayerMoney(playerid) < hInfo[id][Price] )
                    return 
SendClientMessage(playeridRED"ERROR:{FFFFFF} You do not have enough money to buy this house");
                for(new 
i=1i<=CreatedHousesi++)//pointless = this is your problem
                
{
                    
id i;
                    break;
                }
           
                
//count++;
                
GetPlayerName(playeridname25);
                
hInfo[id][Owned] = 1;
                
hInfo[id][Owner] = name;
                
GivePlayerMoneyplayerid, -hInfo[id][Price] );
                
DestroyDynamicMapIcon(hInfo[id][Icon]);
                
PutPlayerInHouse(playeridid);
                new
                    
str[300],
                    
query[400];
                
format(strsizeof(str),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s"hInfo[id][Owner], hInfo[id][Price], (hInfo[id][Locked] == 1) ? ("Yes") : ("No"));
                
UpdateDynamic3DTextLabelText(Text3D:hInfo[id][Label], 0xFF0000FFstr);
                
format(querysizeof(query), "UPDATE `"Houses_Table"` SET `Owned` = '%i', `Owner` = '%s' WHERE `ID` = '%i'",hInfo[id][Owned], hInfo[id][Owner], id);
                
mysql_query(query);
            }
        }
    } 
Doesn't work.
Reply
#4

UPDATE: I have used the MySQL debug and added a message telling me the ID of the house I bought, and everytime I buy a house, it will only buy house id 1. So if I try to buy house id 2, it will put me in house id 1 and buy it

How can I fix this?

pawn Код:
[15:42:34] CMySQLHandler::Query(INSERT INTO `Houses` (ID, Owner, Owned, Locked, InteriorID, World, Price, OX, OY, OZ) VALUES ('1', 'None', '0', '0', '2', '1', '66', '2257.017333', '-1338.388793', '23.982807')) - An error has occured. (Error ID: 1062, Duplicate entry '1' for key 'PRIMARY')

[15:42:34] OnQueryError() - Called.

[15:42:37] >> mysql_query( Connection handle: 1 )

[15:42:37] CMySQLHandler::Query(INSERT INTO `Houses` (ID, Owner, Owned, Locked, InteriorID, World, Price, OX, OY, OZ) VALUES ('2', 'None', '0', '0', '1', '2', '66', '2256.829589', '-1349.249023', '24.189058')) - An error has occured. (Error ID: 1062, Duplicate entry '2' for key 'PRIMARY')

[15:42:37] OnQueryError() - Called.
Reply
#5

You using pickups or checkpoints?

What is the variable name of the created pickup/checkpoint?

E.G hInfo[id][DynamicCheckpointID]


EDIT: I didn't see your last post, the error in your code is

pawn Код:
for(new i=1; i<=CreatedHouses; i++)
                {
                    id = i;
                    break;
                }
That uses house ID 1 everytime.

BTW: don't use 25 for max player name, the max player name is actually 20 based on the client so use 21, or just use the define MAX_PLAYER_NAME which is set to 24.

pawn Код:
if(dialogid == BUY_HOUSE && response==1)
    {
        switch(listitem)
        {
            case 0:
            {
                new id = 0, name[MAX_PLAYER_NAME], count = 0;

                if( count >= 3 )
                    return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You can't own more than 3 houses at a time");

                if( GetPlayerMoney(playerid) < hInfo[id][Price] )
                    return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You do not have enough money to buy this house");

                for(new i = 1; i <= CreatedHouses; i++)
                {
                    if(InPlayerInDynamicCP(playerid, hInfo[i][Owner])) {// change this line!
                        id = i;
                        break;
                    }
                }
                GetPlayerName(playerid, name, MAX_PLAYER_NAME);
                for(new i = 1; i <= CreatedHouses; i++)
                {
                    if(hInfo[i][Owner][0] == '\0') continue; // Add this here to skip unowned houses.
                    if(strcmp(name, hInfo[i][Owner]) == 0)
                        count++;
                   
                }
                hInfo[id][Owned] = 1;
                hInfo[id][Owner] = name;

                GivePlayerMoney( playerid, -hInfo[id][Price] );

                DestroyDynamicMapIcon(hInfo[id][Icon]);

                PutPlayerInHouse(playerid, id);

                new
                    str[300],
                    query[400];

                format(str, sizeof(str),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s", hInfo[id][Owner], hInfo[id][Price], (hInfo[id][Locked] == 1) ? ("Yes") : ("No"));
                UpdateDynamic3DTextLabelText(Text3D:hInfo[id][Label], 0xFF0000FF, str);

                format(query, sizeof(query), "UPDATE `"Houses_Table"` SET `Owned` = '%i', `Owner` = '%s' WHERE `ID` = '%i'", hInfo[id][Owned], hInfo[id][Owner], id);
                mysql_query(query);
            }
        }
    }
Reply
#6

Quote:
Originally Posted by Kar
Посмотреть сообщение
You using pickups or checkpoints?

What is the variable name of the created pickup/checkpoint?

E.G hInfo[id][DynamicCheckpointID]


EDIT: I didn't see your last post, the error in your code is

pawn Код:
for(new i=1; i<=CreatedHouses; i++)
                {
                    id = i;
                    break;
                }
That uses house ID 1 everytime.

BTW: don't use 25 for max player name, the max player name is actually 20 based on the client so use 21, or just use the define MAX_PLAYER_NAME which is set to 24.

pawn Код:
if(dialogid == BUY_HOUSE && response==1)
    {
        switch(listitem)
        {
            case 0:
            {
                new id = 0, name[MAX_PLAYER_NAME], count = 0;

                if( count >= 3 )
                    return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You can't own more than 3 houses at a time");

                if( GetPlayerMoney(playerid) < hInfo[id][Price] )
                    return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You do not have enough money to buy this house");

                for(new i = 1; i <= CreatedHouses; i++)
                {
                    if(InPlayerInDynamicCP(playerid, hInfo[i][Owner])) {// change this line!
                        id = i;
                        break;
                    }
                }
                GetPlayerName(playerid, name, MAX_PLAYER_NAME);
                for(new i = 1; i <= CreatedHouses; i++)
                {
                    if(hInfo[i][Owner][0] == '\0') continue; // Add this here to skip unowned houses.
                    if(strcmp(name, hInfo[i][Owner]) == 0)
                        count++;
                   
                }
                hInfo[id][Owned] = 1;
                hInfo[id][Owner] = name;

                GivePlayerMoney( playerid, -hInfo[id][Price] );

                DestroyDynamicMapIcon(hInfo[id][Icon]);

                PutPlayerInHouse(playerid, id);

                new
                    str[300],
                    query[400];

                format(str, sizeof(str),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse Locked: %s", hInfo[id][Owner], hInfo[id][Price], (hInfo[id][Locked] == 1) ? ("Yes") : ("No"));
                UpdateDynamic3DTextLabelText(Text3D:hInfo[id][Label], 0xFF0000FF, str);

                format(query, sizeof(query), "UPDATE `"Houses_Table"` SET `Owned` = '%i', `Owner` = '%s' WHERE `ID` = '%i'", hInfo[id][Owned], hInfo[id][Owner], id);
                mysql_query(query);
            }
        }
    }
EDIT: Works perfectly. Thanks so much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)