buyhouse command problem
#1

Hello, I made this command.. but when i buy a house, and try to buy another, it says this house is already owned, but it isn't.. also, the label isn't updating, and the Owner isn't being updated in MySQL

Код:
CMD:buy(playerid,params[])
{
for(new i = 0; i < MAX_HOUSES;i++)//Loop threw all houses.
{
if(!IsPlayerInRangeOfPoint(playerid,8.0,hInfo[i][HouseEX],hInfo[i][HouseEY],hInfo[i][HouseEZ])) continue;//Check if the player is near a house checkpoint
//if(GetPlayerMoney(playerid) < HInfo[i][Price]) return SendClientMessage(playerid,-1,"You don't have enough money");//Checking the players money, to see if he has enough to buy the house.

if(hInfo[i][HouseOwned] == 1) return SendClientMessage(playerid,-1,"This house is already owned");//Checking if the house is already owned.
hInfo[i][HouseOwned] = 1;//Setting the house owned var to 1.
new hName[24],string[145], query[100];//Creating the necessary vars.
GetPlayerName(playerid,hName,sizeof(hName));//Retrieving the player's name.

format(query, sizeof(query), "UPDATE * `houses` SET `HouseOwner` = '%s', `HouseOwned` = '1' WHERE `HouseEX` = '%f'", hName, hInfo[playerid][HouseEX]);
mysql_tquery(dbHandle, query);

format(string, 145, "{FFD700}House Title(%i): {FFFFFF}%s\n{FFD700}House Owner: {FFFFFF}%s\n {FFD700}House Price: {FFFFFF}$%d", hInfo[i][HouseID], hInfo[i][HouseTitle], hInfo[i][HousePrice]);
Update3DTextLabelText(hInfo[i][HouseDetails],0xFF0000FF,string);//Updating the label with a red color
GivePlayerMoney(playerid,-hInfo[i][HousePrice]);
return 1;
}
SendClientMessage(playerid,-1,"You aren't near a house!");
return 1;
}
and MySQL LOGS
Код:
[13:26:26] [ERROR] CMySQLQuery::Execute[] - (error #1062) Duplicate entry '1' for key 'PRIMARY'
[13:26:36] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* `houses` SET `HouseOwner` = 'g__htc1', `HouseOwned` = '1' WHERE `HouseEX` = '-' at line 1
Thanks in advance
Reply
#2

screen houses sql?
Reply
#3

PHP код:
CMD:buy(playerid,params[])
{
    new 
count;
    for(new 
0MAX_HOUSES;i++)//Loop threw all houses.
    
{
        if(
IsPlayerInRangeOfPoint(playerid,8.0hInfo[i][HouseEX],hInfo[i][HouseEY], hInfo[i][HouseEZ]))
        {
            
count++;
            
//if(GetPlayerMoney(playerid) < HInfo[i][Price]) return SendClientMessage(playerid,-1,"You don't have enough money");//Checking the players money, to see if he has enough to buy the house.
            //GivePlayerMoney(playerid, -hInfo[i][HousePrice]);
            // CHECK IF PLAYER ALREADY OWN A HOUSE
            
if(hInfo[i][HouseOwned] == 1) return SendClientMessage(playerid,-1,"This house is already owned");//Checking if the house is already owned.
            
hInfo[i][HouseOwned] = 1;//Setting the house owned var to 1.
            
new hName[24],string[145], query[100];//Creating the necessary vars.
            
GetPlayerName(playerid,hName,sizeof(hName));//Retrieving the player's name.
            // WHAT IS HouseEX?? HouseID should be there.
            
format(querysizeof(query), "UPDATE `houses` SET `HouseOwner` = '%s', `HouseOwned` = '1' WHERE `HouseEX` = '%f'"hNamehInfo[playerid][HouseEX]);
            
mysql_tquery(dbHandlequery);
            
format(string145"{FFD700}House Title(%i): {FFFFFF}%s\n{FFD700}House Owner: {FFFFFF}%s\n {FFD700}House Price: {FFFFFF}$%d"hInfo[i][HouseID], hInfo[i][HouseTitle], hInfo[i][HousePrice]);
            
Update3DTextLabelText(hInfo[i][HouseDetails],0xFF0000FF,string);//Updating the label with a red color
            
SendClientMessage(playerid, -1"House bought.");
        }
        return 
1;
    }
    if(!
count) return SendClientMessage(playerid, -1"You aren't near a house!");
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)