MySQL Vehicle Saving Issue
#1

First i will start with.. Im not good at MySQL =/ so dont laugh at me or something -.-'


Error:
Код:
[Thu Mar 03 22:31:24 2011] Error (0): Function: mysql_store_result called when no result stored.
[Thu Mar 03 22:31:24 2011] Error (0): Function: mysql_store_result called when no prior successful query executed.
[Thu Mar 03 22:31:26 2011] Error (0): Failed to exeute query. 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 'VehPosX= '0.000000', VehPosY= '0.000000', VehPosZ= '0.000000', VehRot= '0.000000' at line 1.
Script:
pawn Код:
#include <a_samp>
#include <mysql>
#include <sscanf2>

native WP_Hash(buffer[], len, const str[]);

#define COLOUR_RED          0xFF0000FF
#define COLOUR_GREEN        0x00AF11FF
#define COLOUR_GREY         0x909090FF

#define MySQLhost           "localhost"
#define MySQLuser           "root"
#define MySQLpass           "mypass"
#define MySQLdb             "veh"

new MySQL:Unknown123;

enum VehicleInfo
{
    VehicleOwner,
    Model,
    VehPosX,
    VehPosY,
    VehPosZ,
    VehRot,
    //Plate,
    //Color 1,
    //Color 2,
    //PaintJob,
    //Vehicle Component1,
    //Vehicle Component2,
    //Vehicle Component3,
    //Vehicle Component...,
    //Vehicle Component....
}
new VehicleData[MAX_PLAYERS][VehicleInfo];

public OnFilterScriptInit()
{
    Unknown123 = mysql_init();
    mysql_connect(MySQLhost, MySQLuser, MySQLpass, MySQLdb, MySQL:Unknown123);
    return 1;
}

public OnFilterScriptExit()
{
    mysql_close(MySQL:Unknown123);
    return 1;
}

public OnPlayerConnect(playerid)
{
    LoadBoughtVehicles(playerid);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    SaveBoughtVehiclePos(playerid);
    return 1;
}

stock PlayerName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}

stock SaveBoughtVehiclePos(playerid)
{
    new queue[300];
   
    new vehicleid;
    vehicleid = GetPlayerVehicleID(playerid);

    new Float:vehx, Float:vehy, Float:vehz, Float:angle;
    GetVehiclePos(vehicleid, vehx, vehy, vehz);
    GetVehicleZAngle(vehicleid, angle);
   
    new TheModelID;
    TheModelID = GetVehicleModel(vehicleid);

    format(queue, sizeof(queue), "UPDATE `Vehicles` SET VehicleOwner= '%s', Model= '%d' VehPosX= '%f', VehPosY= '%f', VehPosZ= '%f', VehRot= '%f', WHERE ID= '%d'", PlayerName(playerid), TheModelID, vehx, vehy, vehz, angle, VehicleID());
    mysql_query(queue);
   
    mysql_free_result();
    return 1;
}

stock LoadBoughtVehicles(playerid)
{
    new row[999];
    new name[MAX_PLAYER_NAME];
    mysql_fetch_row(row, "|");
    sscanf(row, "p<|>s[24]sdffff", name, VehicleData[playerid][VehicleOwner], VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot]);
    AddStaticVehicle(VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot], 1, 1);
    mysql_free_result();
    mysql_store_result();
}

//How to unload? xD
//stock UnloadBoughtVehicles(...)

stock CreateBuyableVehicle(playerid, modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
{
    new queue[999];
   
    AddStaticVehicle(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2);

    SaveBoughtVehiclePos(playerid);
    format(queue, sizeof(queue), "INSERT INTO `Vehicles` (ID, VehicleOwner, Model, VehPosX, VehPosY, VehPosZ, VehRot) VALUES ('%d', '%s', '%d', '%f', '%f', '%f', '%f')", VehicleID(), PlayerName(playerid), modelid, spawn_x, spawn_y, spawn_z, angle);
    mysql_query(queue);
}

//Commands
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(vehicle, 7, cmdtext);
    return 0;
}

dcmd_vehicle(playerid, params[])
{
    #pragma unused params
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    CreateBuyableVehicle(playerid, 526, X, Y, Z, 0, -1, -1);
    SendClientMessage(playerid, 0xFF0000FF, "OMG Fail -.-");
    return 1;
}

stock VehicleID()
{
    new RandomVehicleID = random(999999999999999999999999) + 0;
    #pragma unused RandomVehicleID
    return 1;
}
/*

Really.. The "VehicleID()"
is supposed to.. if the ID slot 1, is used then it will be slot ID 2
and if 2 is used then it will be slot ID 3.. then so on

*/
Reply
#2

Well first of all you're missing a comma in your update query after the model, which is causing the third error.

pawn Код:
format(queue, sizeof(queue), "UPDATE `Vehicles` SET VehicleOwner= '%s', Model= '%d', VehPosX= '%f', VehPosY= '%f', VehPosZ= '%f', VehRot= '%f', WHERE ID= '%d'", PlayerName(playerid), TheModelID, vehx, vehy, vehz, angle, VehicleID());
Second of all you're trying to fetch results without a query nevery happening? Not to mention you free the result and then call the store function again? It doesn't make any sense. I assume you're trying to achieve something like so:

pawn Код:
stock LoadBoughtVehicles(playerid)
{
    new row[999];
    new name[MAX_PLAYER_NAME];
    mysql_query("SELECT * FROM `Vehicles`"); // Do the query to select the data from the table
    mysql_store_result(); // Store all of the information
    while(mysql_fetch_row(row, "|")) // Format the information in the row variable with | as the delimiter
    {
        sscanf(row, "p<|>s[24]sdffff", name, VehicleData[playerid][VehicleOwner], VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot]);
        CreateVehicle(VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot], 1, 1,100);
    }
    mysql_free_result(); // We're done with all of the results, free the stored data and move on...
}
Read the comments in this code and it should make more sense. Also you can only use AddStaticVehicle in OnGameModeInit and OnFilterScriptInit, so you need to use something like CreateVehicle instead, which I replaced in that example code.

Hope that helps.
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Well first of all you're missing a comma in your update query after the model, which is causing the third error.

pawn Код:
format(queue, sizeof(queue), "UPDATE `Vehicles` SET VehicleOwner= '%s', Model= '%d', VehPosX= '%f', VehPosY= '%f', VehPosZ= '%f', VehRot= '%f', WHERE ID= '%d'", PlayerName(playerid), TheModelID, vehx, vehy, vehz, angle, VehicleID());
Second of all you're trying to fetch results without a query nevery happening? Not to mention you free the result and then call the store function again? It doesn't make any sense. I assume you're trying to achieve something like so:

pawn Код:
stock LoadBoughtVehicles(playerid)
{
    new row[999];
    new name[MAX_PLAYER_NAME];
    mysql_query("SELECT * FROM `Vehicles`"); // Do the query to select the data from the table
    mysql_store_result(); // Store all of the information
    while(mysql_fetch_row(row, "|")) // Format the information in the row variable with | as the delimiter
    {
        sscanf(row, "p<|>s[24]sdffff", name, VehicleData[playerid][VehicleOwner], VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot]);
        CreateVehicle(VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot], 1, 1,100);
    }
    mysql_free_result(); // We're done with all of the results, free the stored data and move on...
}
Read the comments in this code and it should make more sense. Also you can only use AddStaticVehicle in OnGameModeInit and OnFilterScriptInit, so you need to use something like CreateVehicle instead, which I replaced in that example code.

Hope that helps.
Thanks! Helped alot.

and the:
pawn Код:
stock VehicleID()
{
    new RandomVehicleID = random(999999999999999999999999) + 0;
    #pragma unused RandomVehicleID
    return 1;
}
is bugging something, i also added a command on bottom on scrip like i want it.. but i dont know how to make it =/
can you or someone else Give me a Example or make it for me? :P
Reply
#4

I don't understand what that function is supposed to do? I even read your comment. You can't set a vehicles ID, the server handles that. Do you mean the model ID? I'm not sure what you mean to be honest.
Reply
#5

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
I don't understand what that function is supposed to do? I even read your comment. You can't set a vehicles ID, the server handles that. Do you mean the model ID? I'm not sure what you mean to be honest.
Gah -.- My english :P

I dont really know why i added it too :P I just looked at a "MySQL Player Saving System" and i did something like that.

So it dont have any effect?, so i can remove it? :S

But what should i add after those "WHERE Something= '%d'" then =/
Reply
#6

Don't you already have the vehicleid in the context? So just add vehicleid?
Reply
#7

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Don't you already have the vehicleid in the context? So just add vehicleid?
What you mean xD
Reply
#8

You have vehicleid defined in that context, so why do you need a function to get the vehicleid? Just put vehicleid in as the last argument in the format? For example:

pawn Код:
format(queue, sizeof(queue), "UPDATE `Vehicles` SET VehicleOwner= '%s', Model= '%d' VehPosX= '%f', VehPosY= '%f', VehPosZ= '%f', VehRot= '%f', WHERE ID= '%d'", PlayerName(playerid), TheModelID, vehx, vehy, vehz, angle, vehicleid);
Reply
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
You have vehicleid defined in that context, so why do you need a function to get the vehicleid? Just put vehicleid in as the last argument in the format? For example:

pawn Код:
format(queue, sizeof(queue), "UPDATE `Vehicles` SET VehicleOwner= '%s', Model= '%d' VehPosX= '%f', VehPosY= '%f', VehPosZ= '%f', VehRot= '%f', WHERE ID= '%d'", PlayerName(playerid), TheModelID, vehx, vehy, vehz, angle, vehicleid);
Oh i didnt Notice that LoL, anyway Thanks!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)