buyhouse problem
#1

Hello guys i have a problem at house system.
i made asellhouse,sellhouse,and they are working,they load/save corectly,now i tried to make /buyhouse .it works until restart,when i restart...and then open the server again,the house is for sale again.

cmd:
PHP код:
YCMD:buyhouse(playeridparams[], help)
{
    new 
string[128];
    if(
PlayerData[playerid][HKey] != -1) return SendClientMessage(playeridCOLOR_WHITE,"{FFFFCC}Error: Detii deja o casa.");
    for(new 
1<= housesh++)
    {
        if(
PlayerToPoint(2.0playeridHouseInfo[h][hEntrancex], HouseInfo[h][hEntrancey], HouseInfo[h][hEntrancez]) && HouseInfo[h][hOwned] == 0)
        {
            if(
PlayerData[playerid][Level] < HouseInfo[h][hLevel]) return SendClientMessage(playeridCOLOR_WHITE,"{FFFFCC}Error: Ai nivel prea mic.");
            if(
PlayerData[playerid][Cash] < HouseInfo[h][hValue]) return SendClientMessage(playeridCOLOR_WHITE,"{FFFFCC}Error: Nu ai destui bani.");
            
PlayerData[playerid][HKey] = h;
            
HouseInfo[h][hOwned] = 1;
            
strmid(HouseInfo[h][hOwner], PlayerData[playerid][Name], 0strlen(PlayerData[playerid][Name]), 255);
            
GivePlayerCash(playerid,-HouseInfo[h][hValue]);
            
SendClientMessage(playeridCOLOR_WHITE,"{FFFFCC}Felicitari,ai achizitionat o casa!");
            
SetPlayerPos(playeridHouseInfo[h][hExitx], HouseInfo[h][hExity], HouseInfo[h][hExitz]);
            
mysql_format(SQLstring128,"UPDATE `users` SET `HouseKey`='%d' WHERE `ID`='%d' LIMIT 1",h,PlayerData[playerid][ID]);
            
mysql_tquery(SQLstring"""");
            
mysql_format(SQLstringsizeof(string), "UPDATE houses SET Owner='%s' WHERE id='%d'"HouseInfo[h][hOwner], h);
            
mysql_tquery(SQLstring"""");
            
mysql_format(SQLstringsizeof(string), "UPDATE houses SET Owned='1' Rent='0' , Rentabil='1' , WHERE id='%d'"h);
            
mysql_tquery(SQLstring"""");
            
OnPropTextdrawUpdate(1h);
            return 
1;
        }
    }
    return 
1;

Thanks for help.
Reply
#2

Here.

PHP код:
CMD:buyhouse(playeridparams[])
{
    new 
string[128];
    new 
playername[MAX_PLAYER_NAME];
    new 
sendername[MAX_PLAYER_NAME];
    new 
Float:oldposxFloat:oldposyFloat:oldposz;
    
GetPlayerName(playeridplayernamesizeof(playername));
    
GetPlayerPos(playeridoldposxoldposyoldposz);
    if(
IsPlayerInRangeOfPoint(playerid,5.00.00.00.0))
    {
// This is to prevent players from buying non-ready houses at the 0,0,0  coordinates
        
SendClientMessage(playeridCOLOR_WHITE"You can't purchase houses in this area.");
        return 
1;
    }
    for(new 
0sizeof(HouseInfo); h++)
    {
        if(
IsPlayerInRangeOfPoint(playerid,2.0,HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]))
        {
            if(
HouseInfo[h][hOwned] == 0)
            {
                
/*if(PlayerInfo[playerid][pLevel] < HouseInfo[h][hLevel])
                {
                    format(string, sizeof(string), "   You must be Level %d to purchase this!", HouseInfo[h][hLevel]);
                    SendClientMessage(playerid, COLOR_GRAD5, string);
                    return 1;
                }*/
                
if(PlayerInfo[playerid][pHouse] != INVALID_HOUSE_ID)
                {
                    
SendClientMessage(playeridCOLOR_GRAD5"You already own a house.");
                    return 
1;
                }
                if(
PlayerInfo[playerid][pHouse] == INVALID_HOUSE_ID)
                {
                    if(
GetPlayerCash(playerid) >= HouseInfo[h][hValue])
                    {
                        if(
GetPVarInt(playerid"BuyHouseConfirm") == 0)
                        {
                            
SetPVarInt(playerid"BuyHouseConfirm"1);
                            
SendClientMessage(playeridCOLOR_WHITE"You're about to buy this house. The money can't be returned once you have bought this house.");
                            
SendClientMessage(playeridCOLOR_WHITE"If you're sure you want to buy this house, please re-type the command (/buyhouse).");
                            return 
1;
                        }
                        
DeletePVar(playerid"BuyHouseConfirm");
                        
PlayerInfo[playerid][pHouse] = h;
                        
HouseInfo[h][hOwned] = 1;
                        
HouseInfo[h][hRentable] = 0;
                        
GetPlayerName(playeridsendernamesizeof(sendername));
                        
strmid(HouseInfo[h][hOwner], sendername0strlen(sendername), 255);
                        
GivePlayerCash(playerid,-HouseInfo[h][hValue]);
                        
SetPlayerInterior(playerid,HouseInfo[h][hHInteriorWorld]);
                        if(
HouseInfo[h][hCustomInterior] == 1)
                        {
                            
LoadObjectsForPlayer(playerid);
                        }
                        
format(stringsizeof(string), "* %s has entered their house."GetPlayerNameEx(playerid));
                        
ProxDetector(25.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        
SetPlayerPos(playerid,HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ]);
                          
SetPlayerFacingAngle(playerid,HouseInfo[h][hInteriorA]);
                        
SetCameraBehindPlayer(playerid);
                        
GameTextForPlayer(playerid"~w~Welcome Home~n~You can exit at any time by moving to this door and typing /exit."50003);
                        
PlayerInfo[playerid][pInt] = HouseInfo[h][hHInteriorWorld];
                        
SendClientMessage(playeridCOLOR_WHITE"Congratulations on your new purchase!");
                        
SendClientMessage(playeridCOLOR_WHITE"Type /househelp to review the help section!");
                         
PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
                        
PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
                        
GetPlayerIp(playeridPlayerInfo[playerid][pIP], 32);
                        
GetPlayerPos(playeridPlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
                        
GetPlayerFacingAngle(playeridPlayerInfo[playerid][pPos_r]);
                        
OnPlayerStatsUpdate(playerid);
                        
PlayerInfo[playerid][pVW] = h+6000;
                        
SetPlayerVirtualWorld(playeridh+6000);
                        
DestroyPickup(HouseInfo[h][hPickupID]);
                        
HouseInfo[h][hPickupID] = CreatePickup(127323HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]);
                        
format(stringsizeof(string), "House owner: %s\nLevel: %d\nID: %d",HouseInfo[h][hOwner],HouseInfo[h][hLevel],h);
                        
UpdateDynamic3DTextLabelText(HouseInfo[h][hTextID], COLOR_HOUSEGREENstring);
                        
SaveHouses();
                        new 
ip[32];
                        
GetPlayerIp(playerid,ip,sizeof(ip));
                        
format(string,sizeof(string),"%s (IP: %s) has bought house ID %d for $%d.",GetPlayerNameEx(playerid),ip,h,HouseInfo[h][hValue]);
                        
Log("logs/house.log"string);
                        return 
1;
                    }
                    else
                    {
                        
SendClientMessage(playeridCOLOR_WHITE"   You don't have the cash for that.");
                        return 
1;
                    }
                }
                
// (TEMPORARY - ZHAO NOTE) No second houses for now
                
else if(PlayerInfo[playerid][pHouse2] == INVALID_HOUSE_ID)
                {
                    if(
GetPlayerCash(playerid) > HouseInfo[h][hValue])
                    {
                        
PlayerInfo[playerid][pHouse2] = h;
                        
HouseInfo[h][hOwned] = 1;
                        
HouseInfo[h][hRentable] = 0;
                        
GetPlayerName(playeridsendernamesizeof(sendername));
                        
strmid(HouseInfo[h][hOwner], sendername0strlen(sendername), 255);
                        
GivePlayerCash(playerid,-HouseInfo[h][hValue]);
                        
SetPlayerInterior(playerid,HouseInfo[h][hHInteriorWorld]);
                        if(
HouseInfo[h][hCustomInterior] == 1)
                        {
                            
TogglePlayerControllable(playerid0);
                            
GameTextForPlayer(playerid"Objects loading..."40005);
                            
SetPVarInt(playerid"LoadingObjects"1);
                            
SetTimerEx("SafeLoadObjects"30000"d"playerid);
                        }
                        
SetPlayerPos(playerid,HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ]);
                         
SetPlayerFacingAngle(playerid,HouseInfo[h][hInteriorA]);
                        
SetCameraBehindPlayer(playerid);
                        
GameTextForPlayer(playerid"~w~Welcome Home~n~You can exit at any time by moving to this door and typing /exit."50003);
                        
PlayerInfo[playerid][pInt] = HouseInfo[h][hHInteriorWorld];
                        
SendClientMessage(playeridCOLOR_WHITE"Congratulations on your new purchase!");
                        
SendClientMessage(playeridCOLOR_WHITE"Type /help to review the property help section!");
                        
SaveHouses();
                        
OnPlayerStatsUpdate(playerid);
                        
PlayerInfo[playerid][pVW] = h+6000;
                        
SetPlayerVirtualWorld(playeridh+6000);
                        
DestroyPickup(HouseInfo[h][hPickupID]);
                        
HouseInfo[h][hPickupID] = CreatePickup(127323HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]);
                        
format(stringsizeof(string), "House owner: %s\nLevel: %d\nID: %d",HouseInfo[h][hOwner],HouseInfo[h][hLevel],h);
                        
UpdateDynamic3DTextLabelText(HouseInfo[h][hTextID], COLOR_HOUSEGREENstring);
                        new 
ip[32];
                        
GetPlayerIp(playerid,ip,sizeof(ip));
                        
format(string,sizeof(string),"%s (IP: %s) has bought house ID %d for $%d.",GetPlayerNameEx(playerid),ip,h,HouseInfo[h][hValue]);
                        
Log("logs/house.log"string);
                        return 
1;
                    }
                    else
                    {
                        
SendClientMessage(playeridCOLOR_WHITE"   You don't have the cash for that!");
                        return 
1;
                    }
                }
            }
            else
            {
                
SendClientMessage(playeridCOLOR_WHITE"This house is owned.");
            }
        }
    }
    return 
1;

And make sure you have this.

PHP код:
public OnGameModeExit()
{
    
SaveHouses(); 
Reply
#3

Код:
  mysql_format(SQL, string, sizeof(string), "UPDATE houses SET Owner='%s' WHERE id='%d'", HouseInfo[h][hOwner], h); 
            mysql_tquery(SQL, string, "", ""); 
            mysql_format(SQL, string, sizeof(string), "UPDATE houses SET Owned='1' Rent='0' , Rentabil='1' , WHERE id='%d'", h); 
            mysql_tquery(SQL, string, "", "");
You can easily put these together:
Код:
  mysql_format(SQL, string, sizeof(string), "UPDATE houses SET Owner='%s', Owned='1', Rentabil='1' WHERE id='%d'", HouseInfo[h][hOwner], h); 
            mysql_tquery(SQL, string, "", "");
Anyways, show us the mysql log. Usually the errors are written in there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)