SA-MP Forums Archive
I can't get this code to work - House System - 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: I can't get this code to work - House System (/showthread.php?tid=537585)



I can't get this code to work - House System - Ox1gEN - 16.09.2014

So, I'm trying to create a house and insert it into the database, yet I'm getting errors, I've tried fixing them yet nothing freaking works.


Here's the code, I'd like an explanation why it doesn't work an how to fix it, thanks


pawn Код:
new query[180];

if(dialogid == DIALOG_SET_HOUSE_INTERIOR)
    {
        if(!response) return SendClientMessage(playerid, 0xFF0000FF, "You chose not to create any house and set an interior for it.");
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    SetPlayerInterior(playerid, 1);
                    SetPlayerVirtualWorld(playerid, 1000);
                    new Float:x, Float:y, Float:z;
                    new own = 0;
                    new ownr[MAX_PLAYER_NAME] = "ForSale";
                    GetPlayerPos(playerid, x, y, z);
                    mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('%s', %d, %d,%f, %f, %f, %f, %f, %f, %d, %d)", ownr, own, g_Price, x, y, z, 244.411987, 305.032989, 999.148437, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
                    mysql_pquery(g_Write, query, "OnHouseCreation_1", "d", playerid);
                    CreatePickup(1239, 23, x, y, z, -1);
                    SetTimerEx("HouseTimer_1", false, 1000, "d", playerid);
                }
            }
        }
        return 1;
    }  
    return 0;
}



Re: I can't get this code to work - House System - SilentSoul - 16.09.2014

pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('%s', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", ownr, own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Try this code, if it didn't work please show me your mysql.logs.


Re : Re: I can't get this code to work - House System - Ox1gEN - 16.09.2014

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('%s', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", ownr, own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Try this code, if it didn't work please show me your mysql.logs.
Ah.. Doesn't work sadly.

Here's the error (Forgot to show it in the original post):

pawn Код:
[17:33:17] [ERROR] mysql_format - destination size is too small
[17:33:17] [ERROR] CMySQLQuery::Execute[OnHouseCreation_1] - (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 '' at line 1
EDIT: Actually it works, lol..
Turns out that your syntax was right and I forgot to add a column called HouseOwner, like I added it I just didn't call it that...


Re: I can't get this code to work - House System - SilentSoul - 16.09.2014

It seems like the problem in your ownr string, its null.
pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('Forsale', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Also its not recommended to use ForSale name because some players can login with that name and he will be the owner of some houses.


Re: I can't get this code to work - House System - Ox1gEN - 16.09.2014

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
It seems like the problem in your ownr string, its null.
pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('Forsale', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Also its not recommended to use ForSale name because some players can login with that name and he will be the owner of some houses.
What should I use instead then?

I only wrote forsale because I want to compare it later on when a player attempts to buy a house.


Re: I can't get this code to work - House System - SilentSoul - 16.09.2014

Use something like FS because the player can't login with name lower than 3 letters.


EDIT: sorry just use a space on that string i forgot that the player can't login while he have spaces in his name use something like "For sale".


Re: I can't get this code to work - House System - Ox1gEN - 16.09.2014

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
Use something like FS because the player can't login with name lower than 3 letters.
Alright thanks