MYSQL r7 /createhouse
#1

Hi! I`m trying to make a /createhouse command but the query does not execute. Can you help me, please? ( I use R7 )

The command:

pawn Код:
YCMD:createhouse(playerid, params[], help)
{      
    enum houseType{
    Float:exitX,
    Float:exitY,
    Float:exitZ,
    interior
    };
    new Float:type[20][houseType]={
        {2283.04,-1140.28,1050.90,11}, // 1
        {-42.59,1405.47,1084.43,8}, // 2
        {299.78,309.89,1003.30,4}, //3
        {2308.77,-1212.94,1049.02,6}, //4
        {2233.64,-1115.26,1050.88,5}, //5
        {2218.40,-1076.18,1050.48,1}, //6
        {387.22,1471.70,1080.19,15}, //7
        {223.20,1287.08,1082.14,1}, //8
        {235.34,1186.68,1080.26,3}, //9
        {491.07,1398.50,1080.26,2}, //10
        {24.04,1340.17,1084.38,10}, //11
        {-283.44,1470.93,1084.38,15}, //12
        {-260.49,1456.75,1084.37,4}, //13
        {83.03,1322.28,1083.87,9}, //14
        {2317.89,-1026.76,1050.22,9}, //15
        {2495.98,-1692.08,1014.74,3}, //16
        {226.30,1114.24,1080.99,5}, //17
        {234.19,1063.73,1084.21,6}, //18
        {2324.53,-1149.54,1050.71,12}, //19
        {140.17,1366.07,1083.65,5} //20
    };
    new connhandle = playerConnectHandle[playerid];
    new Float:X;
    new Float:Y;
    new Float:Z;  
    GetPlayerPos(playerid, X, Y, Z);
    new queryy[1024];
    new theTypeID;
    new theName[64];
    new thePrice;


    if(sscanf(params, "is[64]i",theTypeID, theName, thePrice)) return 1;
    sscanf(params, "is[64]i", theTypeID, theName, thePrice);
    new interiorr = floatround(type[theTypeID][interior], floatround_round);
    format(query, sizeof(query), "INSERT INTO `houses` (`X`,`Y`,`Z`,`EX`,`EY`,`EZ`,`interior`,`name`, `price`, `locked`, `rent`, ) VALUES (%f, %f, %f, %f, %f, %f, %i, '%s', %i, %i, %i)",X, Y, Z, type[theTypeID][exitX], type[theTypeID][exitY], type[theTypeID][exitZ], interiorr, theName, thePrice, 1, 0);
    mysql_function_query(connhandle, queryy, true, "zaFunction", "");
    return 1;
}
forward zaFunction();
public zaFunction(){
    new rows;
    new fields;
    cache_get_data(rows, fields);
    printf("Numarul casei: %i", rows);
    return 1;
}
Reply
#2

First, you only need to use sscanf once when doing it this way

pawn Код:
if(sscanf(params, "is[64]i",theTypeID, theName, thePrice)) return 1; // Keep this line
sscanf(params, "is[64]i", theTypeID, theName, thePrice); // Remove this line
Your problem is that at the end of the values you have defined a ',' you have either missed one or added an extra ',' without defining another table column.

Copy and Paste this fix.

pawn Код:
format(query, sizeof(query), "INSERT INTO `houses` (`X`,`Y`,`Z`,`EX`,`EY`,`EZ`,`interior`,`name`, `price`, `locked`, `rent`) VALUES (%f, %f, %f, %f, %f, %f, %i, '%s', %i, %i, %i)",X, Y, Z, type[theTypeID][exitX], type[theTypeID][exitY], type[theTypeID][exitZ], interiorr, theName, thePrice, 1, 0);
mysql_function_query(connhandle, query, true, "zaFunction", "");
Problem Solved.
Reply
#3

Solved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)