Variables of house reset when you buy it!
#1

Hello guys, I have a new problem with my house system :/

So basicly, when I buy a house and than I want to lock it or sell it it says nothing hah, so I made a debug on /buyhouse /sellhouse /lockhouse and /unlockhouse adn I saw that variables are all on 0, what to do? On login it loads prefectly but huh... Also I tried in those commands to put a loading again but doesn't work, take a look on the code!

Also when I buy my house and then do a /gmx it works perfectly so problem is in variables, why?
pawn Код:
enum hInfo
{
    hOwner[24],
    Float: hEnterX,
    Float: hEnterY,
    Float: hEnterZ,
    Float: hExitX,
    Float: hExitY,
    Float: hExitZ,
    hInterior,
    hPrice,
    hVirtualWorld,
    hOwned,
    hLocked,
    Text3D:hLabel,
    hPickup
};
new HouseInfo[MAX_HOUSE][hInfo];

new hstring[128], HQuery[3000], HouseID, savingstring[4000], string[128];
new bool:PlayerHaveHouse[MAX_PLAYERS] = false;

forward OnPlayerEnterHouse(playerid);
forward OnPlayerExitHouse(playerid);

stock CreateHouse(Float: EnterX, Float: EnterY, Float: EnterZ, Interior, Float: InteriorX, Float: InteriorY, Float: InteriorZ, Price, VirtualWorld)
{
    format(HQuery, sizeof(HQuery), "SELECT * FROM `house` WHERE `HouseID` = %d", HouseID);
    mysql_query(HQuery);
    mysql_store_result();
    if(mysql_num_rows() == 0)
    {
        HouseInfo[HouseID][hEnterX] = EnterX;
        HouseInfo[HouseID][hEnterY] = EnterY;
        HouseInfo[HouseID][hEnterZ] = EnterZ;
        HouseInfo[HouseID][hExitX] = InteriorX;
        HouseInfo[HouseID][hExitY] = InteriorY;
        HouseInfo[HouseID][hExitZ] = InteriorZ;
        HouseInfo[HouseID][hInterior] = Interior;
        HouseInfo[HouseID][hVirtualWorld] = VirtualWorld;
        HouseInfo[HouseID][hPrice] = Price;
        format(hstring, sizeof(hstring), "For sale!\nPrice: %d\nHouse ID: %d\nType /buyhouse to buy house!", Price, HouseID);
        format(HQuery, sizeof(HQuery), "INSERT INTO `house` (`User`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`, `Interior`, `Price`, `VirtualWorld`, `Owned`, `Locked`, `HouseID`) VALUES");
        format(HQuery, sizeof(HQuery), "%s  ('None', %f, %f, %f, %f, %f, %f, %d, %d, %d, 0, 0, %d)", HQuery, HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ], HouseInfo[HouseID][hExitX], HouseInfo[HouseID][hExitY], HouseInfo[HouseID][hExitZ], HouseInfo[HouseID][hInterior], HouseInfo[HouseID][hPrice], HouseInfo[HouseID][hVirtualWorld], HouseID);
        mysql_query(HQuery);
        printf("House ID %d created", HouseID);
        printf("X: %f Y: %f Z: %f", HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ]);
        HouseInfo[HouseID][hLabel] = Create3DTextLabel(hstring, 0x21DD00FF, EnterX, EnterY, EnterZ, 40.0, 0);
        HouseInfo[HouseID][hPickup] = CreatePickup(1273, 23, EnterX, EnterY, EnterZ, 0);
    }
    else
    {
        if(mysql_fetch_row_format(HQuery, "|"))
        {
            mysql_fetch_field_row(savingstring, "User");
            format(HouseInfo[HouseID][hOwner], 24, "%s", savingstring);
            mysql_fetch_field_row(savingstring, "EnterX"); HouseInfo[HouseID][hEnterX] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "EnterY"); HouseInfo[HouseID][hEnterY] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "EnterZ"); HouseInfo[HouseID][hEnterZ] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "ExitX"); HouseInfo[HouseID][hExitX] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "ExitY"); HouseInfo[HouseID][hExitY] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "ExitZ"); HouseInfo[HouseID][hExitZ] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "Interior"); HouseInfo[HouseID][hInterior] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "Price"); HouseInfo[HouseID][hPrice] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "VirtualWorld"); HouseInfo[HouseID][hVirtualWorld] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "Owned"); HouseInfo[HouseID][hOwned] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "Locked"); HouseInfo[HouseID][hLocked] = strval(savingstring);
            printf("House ID %d loaded", HouseID);
            printf("House owner %s of house %d", HouseInfo[HouseID][hOwner], HouseID);
            //printf("Interior: %d, Price: %d, VirtualWorld: %d, Owned: %d, Locked: %d, EnterX: %f, EnterY: %f, EnterZ: %f", HouseInfo[HouseID][hInterior], HouseInfo[HouseID][hPrice], HouseInfo[HouseID][hVirtualWorld], HouseInfo[HouseID][hOwned], HouseInfo[HouseID][hLocked], HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ]);
            if(HouseInfo[HouseID][hOwned] == 1)
            {
                format(hstring, sizeof(hstring), "Owner: %s\nHouse ID: %d", HouseInfo[HouseID][hOwner], HouseID);
                HouseInfo[HouseID][hLabel] = Create3DTextLabel(hstring, 0x21DD00FF, HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ], 40.0, 0);
                HouseInfo[HouseID][hPickup] = CreatePickup(1239, 23, HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ], 0);
            }
            else
            {
                format(hstring, sizeof(hstring), "For sale!\nPrice: %d\nHouse ID: %d\nType /buyhouse to buy house!", Price, HouseID);
                HouseInfo[HouseID][hLabel] = Create3DTextLabel(hstring, 0x21DD00FF, HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ], 40.0, 0);
                HouseInfo[HouseID][hPickup] = CreatePickup(1273, 23, HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ], 0);
            }
        }
    }
    mysql_free_result();
    HouseID++;
    return 1;
}

stock GetName(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    return pName;
}

YCMD:buyhouse(playerid, params[], help)
{
    #pragma unused help
    #pragma unused params
    for(new i = 0; i < MAX_HOUSE; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]))
        {
            if(HouseInfo[i][hOwned] == 1) return SendClientMessage(playerid, COLOR_KRED, "House is already owned!");
            if(GetPlayerMoney(playerid) < HouseInfo[i][hPrice]) return SendClientMessage(playerid, COLOR_KRED, "You don't have enough money!");
            if(PlayerHaveHouse[playerid] == true) return SendClientMessage(playerid, COLOR_KRED, "You have house already!");
           
            PlayerHaveHouse[playerid] = true;
            format(HouseInfo[HouseID][hOwner], 24, "%s", GetName(playerid));
            HouseInfo[i][hOwned] = 1;
            DestroyPickup(HouseInfo[i][hPickup]);
            HouseInfo[i][hPickup] = CreatePickup(1239, 23, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ], 0);
            format(hstring, sizeof(hstring), "Owner: %s\nHouse ID: %d", GetName(playerid), i);
            Update3DTextLabelText(HouseInfo[i][hLabel], 0x21DD00FF, hstring);
            GivePlayerMoney(playerid, -HouseInfo[i][hPrice]);
            SendClientMessage(playerid, COLOR_LIME, "House bought!");
           
            format(HQuery, sizeof(HQuery), "UPDATE `house` SET `User` = '%s', `Owned` = 1 WHERE `HouseID` = %d", GetName(playerid), i);
            mysql_query(HQuery);
            printf("Interior: %d, Price: %d, VirtualWorld: %d, Owned: %d, Locked: %d, EnterX: %f, EnterY: %f, EnterZ: %f", HouseInfo[HouseID][hInterior], HouseInfo[HouseID][hPrice], HouseInfo[HouseID][hVirtualWorld], HouseInfo[HouseID][hOwned], HouseInfo[HouseID][hLocked], HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ]);
            if(mysql_fetch_row_format(HQuery, "|"))
            {
                mysql_fetch_field_row(savingstring, "User");
                format(HouseInfo[i][hOwner], 24, "%s", savingstring);
                mysql_fetch_field_row(savingstring, "EnterX"); HouseInfo[i][hEnterX] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "EnterY"); HouseInfo[i][hEnterY] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "EnterZ"); HouseInfo[i][hEnterZ] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "ExitX"); HouseInfo[i][hExitX] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "ExitY"); HouseInfo[i][hExitY] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "ExitZ"); HouseInfo[i][hExitZ] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "Interior"); HouseInfo[i][hInterior] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "Price"); HouseInfo[i][hPrice] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "VirtualWorld"); HouseInfo[i][hVirtualWorld] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "Owned"); HouseInfo[i][hOwned] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "Locked"); HouseInfo[i][hLocked] = strval(savingstring);
            }
        }
    }
    return 1;
}

YCMD:sellhouse(playerid, params[], help)
{
    #pragma unused help
    #pragma unused params
    for(new i = 0; i < MAX_HOUSE; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]))
        {
            if(!strcmp(HouseInfo[i][hOwner], GetName(playerid), false))
            {
                PlayerHaveHouse[playerid] = false;
                format(HouseInfo[HouseID][hOwner], 24, "None");
                HouseInfo[i][hOwned] = 0;
                HouseInfo[i][hLocked] = 0;
                DestroyPickup(HouseInfo[i][hPickup]);
                HouseInfo[i][hPickup] = CreatePickup(1273, 23, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ], 0);
                format(hstring, sizeof(hstring), "For sale!\nPrice: %d\nHouse ID: %d\nType /buyhouse to buy house!", HouseInfo[i][hPrice], i);
                Update3DTextLabelText(HouseInfo[i][hLabel], 0x21DD00FF, hstring);
                GivePlayerMoney(playerid, HouseInfo[i][hPrice]);
                SendClientMessage(playerid, COLOR_LIME, "House sold!");

                format(HQuery, sizeof(HQuery), "UPDATE `house` SET `User` = 'None', `Owned` = 0, `Locked` = 0 WHERE `HouseID` = %d", i);
                mysql_query(HQuery);
                printf("Interior: %d, Price: %d, VirtualWorld: %d, Owned: %d, Locked: %d, EnterX: %f, EnterY: %f, EnterZ: %f", HouseInfo[HouseID][hInterior], HouseInfo[HouseID][hPrice], HouseInfo[HouseID][hVirtualWorld], HouseInfo[HouseID][hOwned], HouseInfo[HouseID][hLocked], HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ]);
                mysql_fetch_row_format(HQuery, "|");
                mysql_fetch_field_row(savingstring, "User");
                format(HouseInfo[i][hOwner], 24, "%s", savingstring);
                mysql_fetch_field_row(savingstring, "EnterX"); HouseInfo[i][hEnterX] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "EnterY"); HouseInfo[i][hEnterY] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "EnterZ"); HouseInfo[i][hEnterZ] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "ExitX"); HouseInfo[i][hExitX] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "ExitY"); HouseInfo[i][hExitY] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "ExitZ"); HouseInfo[i][hExitZ] = floatstr(savingstring);
                mysql_fetch_field_row(savingstring, "Interior"); HouseInfo[i][hInterior] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "Price"); HouseInfo[i][hPrice] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "VirtualWorld"); HouseInfo[i][hVirtualWorld] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "Owned"); HouseInfo[i][hOwned] = strval(savingstring);
                mysql_fetch_field_row(savingstring, "Locked"); HouseInfo[i][hLocked] = strval(savingstring);
            }
        }
    }
    return 1;
}

YCMD:lockhouse(playerid, params[], help)
{
    #pragma unused help
    #pragma unused params
    for(new i = 0; i < MAX_HOUSE; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]))
        {
            if(!strcmp(HouseInfo[i][hOwner], GetName(playerid), false))
            {
                HouseInfo[i][hLocked] = 1;
                SendClientMessage(playerid, COLOR_YELLOW, "House is locked!");

                format(HQuery, sizeof(HQuery), "UPDATE `house` SET `Locked` = 1 WHERE `HouseID` = %d", i);
                mysql_query(HQuery);
                printf("Interior: %d, Price: %d, VirtualWorld: %d, Owned: %d, Locked: %d, EnterX: %f, EnterY: %f, EnterZ: %f", HouseInfo[HouseID][hInterior], HouseInfo[HouseID][hPrice], HouseInfo[HouseID][hVirtualWorld], HouseInfo[HouseID][hOwned], HouseInfo[HouseID][hLocked], HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ]);
            }
        }
    }
    return 1;
}

YCMD:unlockhouse(playerid, params[], help)
{
    #pragma unused help
    #pragma unused params
    for(new i = 0; i < MAX_HOUSE; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]))
        {
            if(!strcmp(HouseInfo[i][hOwner], GetName(playerid), false))
            {
                HouseInfo[i][hLocked] = 0;
                SendClientMessage(playerid, COLOR_YELLOW, "House is unlocked!");

                format(HQuery, sizeof(HQuery), "UPDATE `house` SET `Locked` = 0 WHERE `HouseID` = %d", i);
                mysql_query(HQuery);
                printf("Interior: %d, Price: %d, VirtualWorld: %d, Owned: %d, Locked: %d, EnterX: %f, EnterY: %f, EnterZ: %f", HouseInfo[HouseID][hInterior], HouseInfo[HouseID][hPrice], HouseInfo[HouseID][hVirtualWorld], HouseInfo[HouseID][hOwned], HouseInfo[HouseID][hLocked], HouseInfo[HouseID][hEnterX], HouseInfo[HouseID][hEnterY], HouseInfo[HouseID][hEnterZ]);
            }
        }
    }
    return 1;
}

Edit: God damn I'm such a noob, I always fix it when I post it here haahahh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)