Wtf is wrong
#1

Hello, it's me again with my garage system, i don't know how to fix this. I debugged and reworked code for over 1 hour without fixing anything. Basically, with /creategarage command, the garage is created, their position saved and so on.

BUT, it doesn't store "price" and "size" in the table!

pawn Code:
CMD:creategarage(playerid, params[])
{
    if(Player[playerid][AdminLevel] < 5) return 0;

    new id;

    new price, size;

    if(sscanf(params, "iI(0)", price, size))
    {
        SCM(playerid, COLOR_BELGREEN, "» [USAGE]: /creategarage [price] [size(default 0)]");
        return SCM(playerid, COLOR_BELGREEN, "» Size: 0 - Small Garage , 1 - Medium Garage, 2 - Big Garage.");
    }

    if((size < 0) || (size > 2)) return SCM(playerid, COLOR_ERROR, "» Size must be from 0 to 2.");
   
    id = CreateGarage(playerid, price, size);

    if(id == -1) return SCM(playerid, COLOR_ERROR, "» The server has reached the limit for garages.");
   
    SCMEX(playerid, COLOR_YELLOW, "» You have successfully created a garage. ID: %d - Price: %d - Size: %d", id, price, size);
    return 1;
}
CreateGarage:

pawn Code:
stock CreateGarage(playerid, price, size)
{
    for(new i = 0; i != MAX_GARAGES; i ++) if(!GarageInfo[i][garageExists])
    {
        GarageInfo[i][garageExists] = true;

        GetPlayerPos(playerid, GarageInfo[i][garagePos][0], GarageInfo[i][garagePos][1], GarageInfo[i][garagePos][2]);
        GetPlayerFacingAngle(playerid, GarageInfo[i][garagePos][3]);

        GarageInfo[i][garagePos][0] = GarageInfo[i][garagePos][0] + (1.5 * floatsin(-GarageInfo[i][garagePos][3], degrees));
        GarageInfo[i][garagePos][1] = GarageInfo[i][garagePos][1] + (1.5 * floatcos(-GarageInfo[i][garagePos][3], degrees));

        GarageInfo[i][garageVW] = GetPlayerVirtualWorld(playerid);
       
        GarageInfo[i][garagePrice] = price;
        GarageInfo[i][garageSize] = size;
       
        RefreshGarage(i);

        mysql_tquery(g_SQL, "INSERT INTO `garages` (`garageVW`) VALUES(0)", "OnGarageCreated", "d", i);
        return 1;
    }
    return -1;
}
pawn Code:
function OnGarageCreated(gid)
{
    if(gid == -1 || !GarageInfo[gid][garageExists]) return 0;

    GarageInfo[gid][garageID] = cache_insert_id();

    SaveGarage(gid);
    return 1;
}
When i create a garage automatically a textlabel is created where it shows the price, and guess what? The price is correct! Only on DB table while creating doesn't insert nothing.
Reply
#2

Well does SaveGarage save the price to the database? Show the function.
Reply
#3

Because maybe you haven't already inserted into the table the data of the price! Show me the SaveGarage function, to know whether it contains the save of the price or not.
Reply
#4

pawn Code:
stock SaveGarage(gid)
{
    new query[600];

    mysql_format(g_SQL, query, sizeof(query), "UPDATE `garages` SET `garageX` = '%.4f', `garageY` = '%.4f', `garageZ` = '%.4f', `garageA` = '%.4f', `garageVW` = '%d' WHERE `garageID` = '%d'",
    GarageInfo[gid][garagePos][0],
    GarageInfo[gid][garagePos][1],
    GarageInfo[gid][garagePos][2],
    GarageInfo[gid][garagePos][3],
    GarageInfo[gid][garageVW],
    GarageInfo[gid][garageID]);
    mysql_query(g_SQL, query);

    format(query, sizeof(query), "UPDATE `garages` SET `garageOwnerID` = '%d', `garageOwned` = '%d', `garagePrice` = '%d', `garagePlayerSellPrice` = '%d', `garageSize` = '%d' WHERE `garageID` = '%d'",
    GarageInfo[gid][garageOwnerID],
    GarageInfo[gid][garageOwned],
    GarageInfo[gid][garagePrice],
    GarageInfo[gid][garagePlayerSellPrice],
    GarageInfo[gid][garageSize]);
    mysql_query(g_SQL, query);
    return 1;
}
Reply
#5

PHP Code:
format(querysizeof(query), "UPDATE `garages` SET `garageOwnerID` = '%d', `garageOwned` = '%d', `garagePrice` = '%d', `garagePlayerSellPrice` = '%d', `garageSize` = '%d' WHERE `garageID` = '%d'",
    
GarageInfo[gid][garageOwnerID],
    
GarageInfo[gid][garageOwned],
    
GarageInfo[gid][garagePrice],
    
GarageInfo[gid][garagePlayerSellPrice],
    
GarageInfo[gid][garageSize]);
    
mysql_query(g_SQLquery); 
Here is your problem pal, you forgot to put the enum of the garage id..

change it to this..

PHP Code:
format(querysizeof(query), "UPDATE `garages` SET `garageOwnerID` = '%d', `garageOwned` = '%d', `garagePrice` = '%d', `garagePlayerSellPrice` = '%d', `garageSize` = '%d' WHERE `garageID` = '%d'",
    
GarageInfo[gid][garageOwnerID],
    
GarageInfo[gid][garageOwned],
    
GarageInfo[gid][garagePrice],
    
GarageInfo[gid][garagePlayerSellPrice],
    
GarageInfo[gid][garageSize],
    
GarageInfo[gid][garageID]);
    
mysql_query(g_SQLquery); 
That would do.
Reply
#6

So i spent 1 hour and half (almost) to fix this problem, and the solution was because i forgot to add garageID?

I don't wanna to live on this planet anymore.

Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)