SA-MP Forums Archive
Weird Delete House Bug :/ - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Weird Delete House Bug :/ (/showthread.php?tid=464292)



Weird Delete House Bug :/ - AphexCCFC - 16.09.2013

Hello. There's one more bug issue in my house script. All houses work even when I restart the game mode unless I delete a house, then the rest don't work once the game mode has restarted (weird as hell). I've looked through my code like a thousand times and cannot find out why.

/deletehouse command:

pawn Код:
CMD:deletehouse(playerid, params[])
{
    new string[256], query[1000], houseid;
    if(sscanf(params, "i", houseid)) return SendClientMessage(playerid, -1, ""Grey"Syntax"White": /deletehouse [house id].");
    if(houseid < 1)
    {
        SendClientMessage(playerid, -1, ""Red"Error"White": The house ID must be over 1.");
        return 1;
    }
    if(houseid != HouseInfo[houseid][hID])
    {
        SendClientMessage(playerid, -1, ""Red"Error"White": That house ID does not exist.");
        return 1;
    }
    DestroyDynamicPickup(HouseInfo[houseid][hPickUp]);
    DestroyDynamic3DTextLabel(HouseInfo[houseid][hText]);
    format(query, sizeof(query), "DELETE FROM `houses` WHERE ID='%d'", houseid);
    mysql_query(query);
    format(string, sizeof(string), ""Green"Notice"White": You have deleted house ID %d.", houseid);
    SendClientMessage(playerid, -1, string);
    LoadHouses();
    return 1;
}
This stock somehow may be the problem. None of the variables are fetched from the database after the /deletehouse command is used, but only after the server is restarted.

pawn Код:
stock LoadHouses()
{
    new query[1500], savingstring[20], string[256];
    new houseid = 1;
    mysql_query("SELECT * FROM `houses`");
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(savingstring, "ID"); HouseInfo[houseid][hID] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Address"); format(HouseInfo[houseid][hAddress], 100, "%s", savingstring);
        mysql_fetch_field_row(savingstring, "Owner"); format(HouseInfo[houseid][hOwner], MAX_PLAYER_NAME, "%s", savingstring);
        mysql_fetch_field_row(savingstring, "Owned"); HouseInfo[houseid][hOwned] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Price"); HouseInfo[houseid][hPrice] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "X"); HouseInfo[houseid][hX] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "Y"); HouseInfo[houseid][hY] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "Z"); HouseInfo[houseid][hZ] = floatstr(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, "EnterA"); HouseInfo[houseid][hEnterA] = 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, "ExitA"); HouseInfo[houseid][hExitA] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "Interior"); HouseInfo[houseid][hInterior] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "VirtualWorld"); HouseInfo[houseid][hVirtualWorld] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Type"); HouseInfo[houseid][hType] = strval(savingstring);
        HouseInfo[houseid][hPickUp] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hX], HouseInfo[houseid][hY], HouseInfo[houseid][hZ], 0);
        format(string, sizeof(string), "ID: %d\n"Fuschia"Address"White": %s\n"Fuschia"Owner"White": %s\n"Fuschia"Price"White": $%d", HouseInfo[houseid][hID], HouseInfo[houseid][hAddress], HouseInfo[houseid][hOwner], HouseInfo[houseid][hPrice]);
        HouseInfo[houseid][hText] = CreateDynamic3DTextLabel(string, -1, HouseInfo[houseid][hX], HouseInfo[houseid][hY], HouseInfo[houseid][hZ], 20.0);
        houseid++;
    }
    printf("All houses have been successfully loaded.");
    mysql_free_result();
    return 1;
}
I would highly appreciate it if someone could clear my frustration, the help will make my house script complete once and for all


Re: Weird Delete House Bug :/ - AphexCCFC - 16.09.2013

Someone please help, I cannot find the reason for this, giving me a headache <.<


Re: Weird Delete House Bug :/ - Konstantinos - 16.09.2013

Don't use auto-increment if you're about to remove houses. Just start normal from 0.

pawn Код:
mysql_fetch_field_row(savingstring, "ID"); HouseInfo[houseid][hID] = strval(savingstring);
If the first house IDs in the database is for example 2,5 (let's say some of them has been removed), then it'll be like that:

pawn Код:
// ---

HouseInfo[1][hID] is 2 // house 1 has houseid stored as 2
HouseInfo[2][hID] is 5 // house 2 has houseid stored as 5

// ---
which makes no sense. Start from 0 and when you remove a house, update the houseid by decreasing - 1 until all the house IDs are in order.


Re: Weird Delete House Bug :/ - AphexCCFC - 16.09.2013

I'm not using auto increment but my house ids start at 1. I have a command /createhouse <house I'd> so it allows me to choose which house ID to create. You think it should work if I decrease -1 off the house ID's above the one created? So say I create house ID 5. All house ID's above 5 I should -1 them?


Re: Weird Delete House Bug :/ - AphexCCFC - 16.09.2013

I meant so say I delete house ID 5


Re: Weird Delete House Bug :/ - AphexCCFC - 16.09.2013

Please guys I really need your help.


Re: Weird Delete House Bug :/ - AphexCCFC - 17.09.2013

Bump