SA-MP Forums Archive
Doesn't insert data. - 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: Doesn't insert data. (/showthread.php?tid=505017)



Doesn't insert data. - Binx - 06.04.2014

Could someone tell me why this command doesn't insert data and returns "Unknown command":
pawn Код:
CMD:createhouse(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
        new Float:IX, Float:IY, Float:IZ, Float:EX, Float:EY, Float:EZ, interior, price, hprice, Float:hexteriorX, Float:hexteriorY, Float:hexteriorZ, Float:hinteriorX, Float:hinteriorY, Float:hinteriorZ, hinteriorInt, hlocked;
        if(sscanf(params, "fffdd", IX, IY, IZ, interior, price)) return SendClientMessage(playerid, COLOR_ORANGE, "/createhouse [Interior X], [Interior Y], [Interior Z], interiorID, price");
        GetPlayerPos(playerid, EX, EY, EZ);
        new houseid = -1;

        for(new i = 1; i < MAX_HOUSES; i++)
        {
            if(HouseInfo[houseid][EPosX] == 1)
            {
                houseid = i;
                break;
            }
        }
        format(String, sizeof(String), "INSERT INTO houses (owner, price, exteriorX, exteriorY, exteriorZ, interiorX, interiorY, interiorZ, interiorInt, locked) VALUES");
        format(String, sizeof(String), "%s (%d, %f, %f, %f, %f, %f, %f, %d, '1')", String, hprice, hexteriorX, hexteriorY, hexteriorZ, hinteriorX, hinteriorY, hinteriorZ, hinteriorInt, hlocked);
        mysql_query(String);

        SendClientMessage(playerid, COLOR_WHITE, "House created!");

        HouseInfo[houseid][HID] = mysql_insert_id();
        HouseInfo[houseid][Price] = hprice;
        HouseInfo[houseid][EPosX] = hexteriorX;
        HouseInfo[houseid][EPosY] = hexteriorY;
        HouseInfo[houseid][EPosZ] = hexteriorZ;
        HouseInfo[houseid][IPosX] = hinteriorX;
        HouseInfo[houseid][IPosY] = hinteriorY;
        HouseInfo[houseid][IPosZ] = hinteriorZ;
        HouseInfo[houseid][Interior] = hinteriorInt;
        HouseInfo[houseid][Locked] = hlocked;
       
        CreatePickup(1273, 1, hexteriorX, hexteriorY, hexteriorZ, -1);
        Create3DTextLabel("[House]\nNot owned", COLOR_ORANGE, hexteriorX, hexteriorY, hexteriorZ, 40.0, 0, 0);
    }
    return true;
}



Re: Doesn't insert data. - Corekt - 06.04.2014

I assume you're using ZCMD. Are you returning 0 anywhere under

pawn Код:
OnPlayerCommandReceived(playerid, cmdtext[])
or
pawn Код:
OnPlayerCommandPerformed(playerid, cmdtext[], success)
?


Re: Doesn't insert data. - Konstantinos - 06.04.2014

pawn Код:
if(HouseInfo[houseid][EPosX] == 1)
houseid is -1; therebefore a run time error 4: Array index out of bounds for accessing element at negative index -1. Replace with:
pawn Код:
if(HouseInfo[i][EPosX] == 1)
That will fix the unknown command and probably the query problem. If it still doesn't insert the data, make sure that String array's size is enough to store the whole text.


Re: Doesn't insert data. - Binx - 06.04.2014

It inserts the data, but sets everything to 0.

I get ingame:
House Created!
Unknown command.


Re: Doesn't insert data. - Konstantinos - 06.04.2014

I see. After the "House Created!" message, you use houseid in arrays but you don't know for sure that it has been assigned another value or it's still -1. An if statement after the loop that would check if houseid is -1 and returning an error message would help to prevent it.

About the query, the interior coordinates has been assigned in IX, IY, IZ the interior in interior and the price in price variables but you insert in the query hprice, hexteriorX, hexteriorY, hexteriorZ, hinteriorX, hinteriorY, hinteriorZ, hinteriorInt instead which are 0 by default.


Re: Doesn't insert data. - Binx - 06.04.2014

I modified it again:
pawn Код:
CMD:createhouse(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
        new Float:IX, Float:IY, Float:IZ, Float:EX, Float:EY, Float:EZ, interior, price, locked;
        if(sscanf(params, "fffdd", IX, IY, IZ, interior, price)) return SendClientMessage(playerid, COLOR_ORANGE, "/createhouse [Interior X], [Interior Y], [Interior Z], interiorID, price");
        GetPlayerPos(playerid, EX, EY, EZ);
        new houseid = -1;

        for(new i = 1; i < MAX_HOUSES; i++)
        {
            if(HouseInfo[i][EPosX] == 1)
            {
                houseid = i;
                break;
            }
        }
        format(String, sizeof(String), "INSERT INTO houses (price, EPosX, EPosY, EPosZ, IPosX, IPosY, IPosZ, Interior, Locked) VALUES");
        format(String, sizeof(String), "%s (%d, %f, %f, %f, %f, %f, %f, %d, '1')", String, price, EX, EY, EZ, IX, IY, IZ, interior, locked);
        mysql_query(String);

        SendClientMessage(playerid, COLOR_WHITE, "House created!");

        HouseInfo[houseid][HID] = mysql_insert_id();
        HouseInfo[houseid][Price] = price;
        HouseInfo[houseid][EPosX] = EX;
        HouseInfo[houseid][EPosY] = EY;
        HouseInfo[houseid][EPosZ] = EZ;
        HouseInfo[houseid][IPosX] = IX;
        HouseInfo[houseid][IPosY] = IY;
        HouseInfo[houseid][IPosZ] = IZ;
        HouseInfo[houseid][Interior] = interior;
        HouseInfo[houseid][Locked] = locked;
       
        //CreatePickup(1273, 1, hexteriorX, hexteriorY, hexteriorZ, -1);
        //Create3DTextLabel("[House]\nNot owned", COLOR_ORANGE, hexteriorX, hexteriorY, hexteriorZ, 40.0, 0, 0);
    }
    return true;
}
This is what the table returns.
(Number 4)



Re: Doesn't insert data. - Konstantinos - 06.04.2014

It seems like only EPosX has been saved as float and the rest as integers. Are you sure the datatype of the rest in the table is FLOAT as well as for EPosX field?

In order to prevent a run time error 4 again if the slots are full, after the loop:
pawn Код:
if (houseid == -1) return SendClientMessage(playerid, -1, "No more house slots available.");



Re: Doesn't insert data. - Binx - 06.04.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It seems like only EPosX has been saved as float and the rest as integers. Are you sure the datatype of the rest in the table is FLOAT as well as for EPosX field?

In order to prevent a run time error 4 again if the slots are full, after the loop:
pawn Код:
if (houseid == -1) return SendClientMessage(playerid, -1, "No more house slots available.");
The pos saving is fixed.

"unknown command" is still there.


Re: Doesn't insert data. - Konstantinos - 06.04.2014

Are you sure that you've changed those we told about before? An easier way to find those would be by loading crashdetect plugin and using debug info.

crashdetect plugin: https://github.com/Zeex/samp-plugin-...es/tag/v4.13.1
debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info

re-compile, start the server and execute the command. If it displays the unknown command, post your server log.


Re: Doesn't insert data. - Binx - 06.04.2014

Fixed it.
This was causing the error so I made a custom stock to replace it. Thanks a lot though!
pawn Код:
for(new i = 1; i < MAX_HOUSES; i++)
        {
            if(HouseInfo[i][EPosX] == 1)
            {
                houseid = i;
                break;
            }
        }