SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/09/2014, 06:48 PM   #1
TheNerka
Huge Clucker
 
Join Date: Aug 2013
Posts: 240
Reputation: 2
Default How to load and save vehicles from MySQL R38?

How to load and save vehicles from MySQL R38?

My Enum:

Code:
enum vData
{
    Fullname[128],
    Number,
    Model,
    Float:PositionX,
    Float:PositionY,
    Float:PositionZ,
    Float:PositionA,
    Float:Health,
    Color1,
    Color2,
    Mod1,
    Mod2,
    Mod3,
    Mod4,
    Mod5,
    Mod6,
    Mod7,
    Mod8,
    Mod9,
    Mod10,
    Mod11,
    Mod12,
    Mod13,
    Mod14,
    Mod15,
    Mod16,
    Mod17,
    Trunk,
    DoorLock,
    Bonnet,
    Engine,
    Lights,
    Alarm,
}
new VehicleData[MAX_VEHICLES][vData];
Fullname is car owner name
TheNerka is offline   Reply With Quote
Old 09/09/2014, 07:35 PM   #2
Ox1gEN
Huge Clucker
 
Ox1gEN's Avatar
 
Join Date: Aug 2014
Location: New Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); printf("%f%f%f", x, y, z);
Posts: 358
Reputation: 29
Default Re: How to load and save vehicles from MySQL R38?

For strings(In your case number and name [Add a string length to Number]) you need to use cache_get_field_content(0, "YOUR-COLUMN-IN-TABLE", -YOUR-VARIABLE-TO-STORE-IT-IN-, -LENGTH-OF-VARIABLE-);

For floats you do cache_get_field_content_float find more about it in the wiki cause it's different from the regular get content and cache_get_field_content_int it's used the same as float but is different than the float one.

This is bassicly how to load and to save just use a simple UPDATE command.

e.g:


pawn Code:
CMD:YOUR-DESIRED-COMMAND(playerid, param[])
{
    new query[128];
    new Float:x, Float:y, Float:z;
    new veh = GetPlayerVehicleID(playerid);
    GetVehiclePos(veh, x, y, z);
    mysql_format(-YOUR-CONNECTION-, query, sizeof(query), "UPDATE vehicles SET PositionX = %f, PositionY = %f, PositionZ = %f WHERE VehicleID = %d", x, y, z, -YOUR-VARIABLE-TO-FETCH-THE-VEHICLE-ID);
    mysql_pquery(-YOUR-CONNECTION-, query);
    return 1;
}

Of-course you have to change most of it but this is just a small example.


EDIT: BTW I've used a command here but the whole point is for you to look at the mysql things and at the whole code itself, because this can be used at alot of places(e.g - at a saving vehicles stock).
Ox1gEN is offline   Reply With Quote
Old 10/09/2014, 01:08 PM   #3
TheNerka
Huge Clucker
 
Join Date: Aug 2013
Posts: 240
Reputation: 2
Exclamation Re: How to load and save vehicles from MySQL R38?

im scripted with auto load/ save car system

my save/load

Code:
forward LoadVehicleData();
public LoadVehicleData()
{
    AntiDeAMX();
    for(new vehicleid = 1;vehicleid<100;vehicleid++)
    {
        cache_get_field_content(0, "Fullname", VehicleData[vehicleid][Fullname], Mysql_users, 129);
        cache_get_field_content(0, "Number", VehicleData[vehicleid][Number], Mysql_users, 126);
        VehicleData[vehicleid][Model] = cache_get_field_content_int(0, "Model", Mysql_users);
        VehicleData[vehicleid][PositionX] = cache_get_field_content_float(0, "PositionX", Mysql_users);
        VehicleData[vehicleid][PositionY] = cache_get_field_content_float(0, "PositionY", Mysql_users);
        VehicleData[vehicleid][PositionZ] = cache_get_field_content_float(0, "PositionZ", Mysql_users);
        VehicleData[vehicleid][PositionA] = cache_get_field_content_float(0, "PositionA", Mysql_users);
        VehicleData[vehicleid][Health] = cache_get_field_content_float(0, "Health", Mysql_users);
        VehicleData[vehicleid][Color1] = cache_get_field_content_int(0, "Color1", Mysql_users);
        VehicleData[vehicleid][Color2] = cache_get_field_content_int(0, "Color2", Mysql_users);
        VehicleData[vehicleid][Mod1] = cache_get_field_content_int(0, "Mod1", Mysql_users);
        VehicleData[vehicleid][Mod2] = cache_get_field_content_int(0, "Mod2", Mysql_users);
        VehicleData[vehicleid][Mod3] = cache_get_field_content_int(0, "Mod3", Mysql_users);
        VehicleData[vehicleid][Mod4] = cache_get_field_content_int(0, "Mod4", Mysql_users);
        VehicleData[vehicleid][Mod5] = cache_get_field_content_int(0, "Mod5", Mysql_users);
        VehicleData[vehicleid][Mod6] = cache_get_field_content_int(0, "Mod6", Mysql_users);
        VehicleData[vehicleid][Mod7] = cache_get_field_content_int(0, "Mod7", Mysql_users);
        VehicleData[vehicleid][Mod8] = cache_get_field_content_int(0, "Mod8", Mysql_users);
        VehicleData[vehicleid][Mod9] = cache_get_field_content_int(0, "Mod9", Mysql_users);
        VehicleData[vehicleid][Mod10] = cache_get_field_content_int(0, "Mod10", Mysql_users);
        VehicleData[vehicleid][Mod11] = cache_get_field_content_int(0, "Mod11", Mysql_users);
        VehicleData[vehicleid][Mod12] = cache_get_field_content_int(0, "Mod12", Mysql_users);
        VehicleData[vehicleid][Mod13] = cache_get_field_content_int(0, "Mod13", Mysql_users);
        VehicleData[vehicleid][Mod14] = cache_get_field_content_int(0, "Mod14", Mysql_users);
        VehicleData[vehicleid][Mod15] = cache_get_field_content_int(0, "Mod15", Mysql_users);
        VehicleData[vehicleid][Mod16] = cache_get_field_content_int(0, "Mod16", Mysql_users);
        VehicleData[vehicleid][Mod17] = cache_get_field_content_int(0, "Mod17", Mysql_users);
        VehicleData[vehicleid][Trunk] = cache_get_field_content_int(0, "Trunk", Mysql_users);
        VehicleData[vehicleid][DoorLock] = cache_get_field_content_int(0, "DoorLock", Mysql_users);
        VehicleData[vehicleid][Bonnet] = cache_get_field_content_int(0, "Bonnet", Mysql_users);
        VehicleData[vehicleid][Engine] = cache_get_field_content_int(0, "Engine", Mysql_users);
        VehicleData[vehicleid][Lights] = cache_get_field_content_int(0, "Lights", Mysql_users);
        VehicleData[vehicleid][Alarm] = cache_get_field_content_int(0, "Alarm", Mysql_users);

        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod1]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod2]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod3]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod4]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod5]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod6]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod7]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod8]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod9]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod10]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod11]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod12]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod13]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod14]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod15]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod16]);
        AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod17]);
        SetVehicleHealth(vehicleid, VehicleData[vehicleid][Health]);
        SetVehicleNumberPlate(vehicleid, VehicleData[vehicleid][Number]);
        CreateVehicle(VehicleData[vehicleid][Model], VehicleData[vehicleid][PositionX], VehicleData[vehicleid][PositionY], VehicleData[vehicleid][PositionZ], VehicleData[vehicleid][PositionA], VehicleData[vehicleid][Color1], VehicleData[vehicleid][Color2], 1000);
        SetVehicleParamsEx(VehicleData[vehicleid][Model], VehicleData[vehicleid][Engine], VehicleData[vehicleid][Lights], VehicleData[vehicleid][Alarm], VehicleData[vehicleid][DoorLock], VehicleData[vehicleid][Bonnet], VehicleData[vehicleid][Trunk], 0);
    }
    return 1;
}

forward SaveVehicleData();
public SaveVehicleData()
{
    AntiDeAMX();
    for(new vehicleid = 1;vehicleid<500;vehicleid++)
    {
        new objective;
        GetVehiclePos(vehicleid, VehicleData[vehicleid][PositionX],VehicleData[vehicleid][PositionY],VehicleData[vehicleid][PositionZ]);
        GetVehicleZAngle(vehicleid,VehicleData[vehicleid][PositionA]);
        GetVehicleHealth(vehicleid, VehicleData[vehicleid][Health]);
        GetVehicleParamsEx(VehicleData[vehicleid][Model], VehicleData[vehicleid][Engine], VehicleData[vehicleid][Lights], VehicleData[vehicleid][Alarm], VehicleData[vehicleid][DoorLock], VehicleData[vehicleid][Bonnet], VehicleData[vehicleid][Trunk], objective);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod1]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod2]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod3]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod4]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod5]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod6]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod7]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod8]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod9]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod10]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod11]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod12]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod13]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod14]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod15]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod16]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod17]);

        mysql_format(Mysql_users, query, sizeof(query), "UPDATE `"MASINU_LENTELE"` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', Health='%f', Color1='%d', Color2='%d', Mod1='%d', Mod2='%d', Mod3='%d', Mod4='%d', Mod5='%d', Mod6='%d', Mod7='%d'",\
        VehicleData[vehicleid][Fullname],
        VehicleData[vehicleid][Number],
        VehicleData[vehicleid][Model],
        VehicleData[vehicleid][PositionX],
        VehicleData[vehicleid][PositionY],
        VehicleData[vehicleid][PositionZ],
        VehicleData[vehicleid][PositionA],
        VehicleData[vehicleid][Health],
        VehicleData[vehicleid][Color1],
        VehicleData[vehicleid][Color2],
        VehicleData[vehicleid][Mod1],
        VehicleData[vehicleid][Mod2],
        VehicleData[vehicleid][Mod3],
        VehicleData[vehicleid][Mod4],
        VehicleData[vehicleid][Mod5],
        VehicleData[vehicleid][Mod6],
        VehicleData[vehicleid][Mod7]);

        mysql_format(Mysql_users, query, sizeof(query), "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk='%d', DoorLock='%d', Bonnet='%d', Engine='%d', Lights='%d', Alarm='%d' WHERE Fullname='%e'",\
        query,
        VehicleData[vehicleid][Mod8],
        VehicleData[vehicleid][Mod9],
        VehicleData[vehicleid][Mod10],
        VehicleData[vehicleid][Mod11],
        VehicleData[vehicleid][Mod12],
        VehicleData[vehicleid][Mod13],
        VehicleData[vehicleid][Mod14],
        VehicleData[vehicleid][Mod15],
        VehicleData[vehicleid][Mod16],
        VehicleData[vehicleid][Mod17],
        VehicleData[vehicleid][Trunk],
        VehicleData[vehicleid][Lights],
        VehicleData[vehicleid][Bonnet],
        VehicleData[vehicleid][Engine],
        VehicleData[vehicleid][Alarm],
        VehicleData[vehicleid][Fullname]);
        mysql_tquery(Mysql_users, query, "", "");
    }
}
when im login, got flood 2MB/5s mysql_log:

Code:
...
[21:36:26] [DEBUG] cache_get_field_content - row: 0, field_name: "Fullname", connection: 1, max_len: 129
[21:36:26] [WARNING] cache_get_field_content - no active cache
[21:36:26] [DEBUG] cache_get_field_content - row: 0, field_name: "Number", connection: 1, max_len: 126
[21:36:26] [WARNING] cache_get_field_content - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Model", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_float - row: 0, field_name: "PositionX", connection: 1
[21:36:26] [WARNING] cache_get_field_content_float - no active cache
[21:36:26] [DEBUG] cache_get_field_content_float - row: 0, field_name: "PositionY", connection: 1
[21:36:26] [WARNING] cache_get_field_content_float - no active cache
[21:36:26] [DEBUG] cache_get_field_content_float - row: 0, field_name: "PositionZ", connection: 1
[21:36:26] [WARNING] cache_get_field_content_float - no active cache
[21:36:26] [DEBUG] cache_get_field_content_float - row: 0, field_name: "PositionA", connection: 1
[21:36:26] [WARNING] cache_get_field_content_float - no active cache
[21:36:26] [DEBUG] cache_get_field_content_float - row: 0, field_name: "Health", connection: 1
[21:36:26] [WARNING] cache_get_field_content_float - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Color1", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Color2", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod1", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod2", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod3", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod4", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod5", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod6", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod7", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod8", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod9", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod10", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod11", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod12", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod13", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod14", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod15", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod16", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Mod17", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Trunk", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "DoorLock", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Bonnet", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Engine", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Lights", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:36:26] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Alarm", connection: 1
[21:36:26] [WARNING] cache_get_field_content_int - no active cache
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `accounts` SET Fullname='%e', Password='%e', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', Health='%f',..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Warnings='%d', Warning1Reason='%e', Warning2Reason='%e', Warning3Reason='%e', WarnedBy1='%e', WarnedBy2='%e', WarnedBy3='%e'..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Helper='%d', Money='%d', MoneyBank='%d', Score='%d', Skin='%d', Hour='%d', Min='%d', Sec='%d', Kills='%d', Deaths='%d', Kred..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Weapon1='%d', Weapon1a='%d', Weapon2='%d', Weapon2a='%d', Weapon3='%d', Weapon3a='%d', Weapon4='%d', Weapon4a='%d', Weapon5=..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Weapon7='%d', Weapon7a='%d', Weapon8='%d', Weapon8a='%d', Weapon9='%d', Weapon9a='%d', Weapon10='%d', Weapon10a='%d', Weapon..."
[21:37:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `accounts` SET Fullname='The_Nerka', Password='41479FC4C3", callback: "(null)", format: "(null)"
[21:37:56] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `vehicles` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', He..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk=..."
[21:37:56] [ERROR] mysql_format - no value for specifier "%e" available
[21:37:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `vehicles` SET Fullname='', Number='', Model='0', Positio", callback: "(null)", format: "(null)"
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `vehicles` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', He..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk=..."
[21:37:56] [ERROR] mysql_format - no value for specifier "%e" available
[21:37:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `vehicles` SET Fullname='', Number='', Model='0', Positio", callback: "(null)", format: "(null)"
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `vehicles` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', He..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk=..."
[21:37:56] [ERROR] mysql_format - no value for specifier "%e" available
[21:37:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `vehicles` SET Fullname='', Number='', Model='0', Positio", callback: "(null)", format: "(null)"
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `vehicles` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', He..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk=..."
[21:37:56] [ERROR] mysql_format - no value for specifier "%e" available
[21:37:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `vehicles` SET Fullname='', Number='', Model='0', Positio", callback: "(null)", format: "(null)"
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `vehicles` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', He..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk=..."
[21:37:56] [ERROR] mysql_format - no value for specifier "%e" available
[21:37:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `vehicles` SET Fullname='', Number='', Model='0', Positio", callback: "(null)", format: "(null)"
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `vehicles` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', He..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk=..."
[21:37:56] [ERROR] mysql_format - no value for specifier "%e" available
[21:37:56] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `vehicles` SET Fullname='', Number='', Model='0', Positio", callback: "(null)", format: "(null)"
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "UPDATE `vehicles` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', He..."
[21:37:56] [DEBUG] mysql_format - connection: 1, len: 4098, format: "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk=..."
TheNerka is offline   Reply With Quote
Old 10/09/2014, 02:36 PM   #4
Ox1gEN
Huge Clucker
 
Ox1gEN's Avatar
 
Join Date: Aug 2014
Location: New Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); printf("%f%f%f", x, y, z);
Posts: 358
Reputation: 29
Default Re: How to load and save vehicles from MySQL R38?

Well, you haven't retreived any data...

Use:

new rows, fields;
cache_get_data(rows, fields);
if(rows)
{
//Your code to load/save or whatever
}

In your loading code, and in the saving code just save it using a simple mysql query.
Ox1gEN is offline   Reply With Quote
Old 10/09/2014, 02:59 PM   #5
TheNerka
Huge Clucker
 
Join Date: Aug 2013
Posts: 240
Reputation: 2
Default Re: How to load and save vehicles from MySQL R38?

not saving car pos and not loading
TheNerka is offline   Reply With Quote
Old 10/09/2014, 04:01 PM   #6
Ox1gEN
Huge Clucker
 
Ox1gEN's Avatar
 
Join Date: Aug 2014
Location: New Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); printf("%f%f%f", x, y, z);
Posts: 358
Reputation: 29
Default Re: How to load and save vehicles from MySQL R38?

pawn Code:
forward LoadVehicleData();
public LoadVehicleData()
{
    AntiDeAMX();
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {  
        for(new vehicleid = 1;vehicleid<100;vehicleid++)
        {
            cache_get_field_content(0, "Fullname", VehicleData[vehicleid][Fullname], Mysql_users, 129);
            cache_get_field_content(0, "Number", VehicleData[vehicleid][Number], Mysql_users, 126);
            VehicleData[vehicleid][Model] = cache_get_field_content_int(0, "Model", Mysql_users);
            VehicleData[vehicleid][PositionX] = cache_get_field_content_float(0, "PositionX", Mysql_users);
            VehicleData[vehicleid][PositionY] = cache_get_field_content_float(0, "PositionY", Mysql_users);
            VehicleData[vehicleid][PositionZ] = cache_get_field_content_float(0, "PositionZ", Mysql_users);
            VehicleData[vehicleid][PositionA] = cache_get_field_content_float(0, "PositionA", Mysql_users);
            VehicleData[vehicleid][Health] = cache_get_field_content_float(0, "Health", Mysql_users);
            VehicleData[vehicleid][Color1] = cache_get_field_content_int(0, "Color1", Mysql_users);
            VehicleData[vehicleid][Color2] = cache_get_field_content_int(0, "Color2", Mysql_users);
            VehicleData[vehicleid][Mod1] = cache_get_field_content_int(0, "Mod1", Mysql_users);
            VehicleData[vehicleid][Mod2] = cache_get_field_content_int(0, "Mod2", Mysql_users);
            VehicleData[vehicleid][Mod3] = cache_get_field_content_int(0, "Mod3", Mysql_users);
            VehicleData[vehicleid][Mod4] = cache_get_field_content_int(0, "Mod4", Mysql_users);
            VehicleData[vehicleid][Mod5] = cache_get_field_content_int(0, "Mod5", Mysql_users);
            VehicleData[vehicleid][Mod6] = cache_get_field_content_int(0, "Mod6", Mysql_users);
            VehicleData[vehicleid][Mod7] = cache_get_field_content_int(0, "Mod7", Mysql_users);
            VehicleData[vehicleid][Mod8] = cache_get_field_content_int(0, "Mod8", Mysql_users);
            VehicleData[vehicleid][Mod9] = cache_get_field_content_int(0, "Mod9", Mysql_users);
            VehicleData[vehicleid][Mod10] = cache_get_field_content_int(0, "Mod10", Mysql_users);
            VehicleData[vehicleid][Mod11] = cache_get_field_content_int(0, "Mod11", Mysql_users);
            VehicleData[vehicleid][Mod12] = cache_get_field_content_int(0, "Mod12", Mysql_users);
            VehicleData[vehicleid][Mod13] = cache_get_field_content_int(0, "Mod13", Mysql_users);
            VehicleData[vehicleid][Mod14] = cache_get_field_content_int(0, "Mod14", Mysql_users);
            VehicleData[vehicleid][Mod15] = cache_get_field_content_int(0, "Mod15", Mysql_users);
            VehicleData[vehicleid][Mod16] = cache_get_field_content_int(0, "Mod16", Mysql_users);
            VehicleData[vehicleid][Mod17] = cache_get_field_content_int(0, "Mod17", Mysql_users);
            VehicleData[vehicleid][Trunk] = cache_get_field_content_int(0, "Trunk", Mysql_users);
            VehicleData[vehicleid][DoorLock] = cache_get_field_content_int(0, "DoorLock", Mysql_users);
            VehicleData[vehicleid][Bonnet] = cache_get_field_content_int(0, "Bonnet", Mysql_users);
            VehicleData[vehicleid][Engine] = cache_get_field_content_int(0, "Engine", Mysql_users);
            VehicleData[vehicleid][Lights] = cache_get_field_content_int(0, "Lights", Mysql_users);
            VehicleData[vehicleid][Alarm] = cache_get_field_content_int(0, "Alarm", Mysql_users);

            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod1]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod2]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod3]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod4]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod5]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod6]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod7]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod8]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod9]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod10]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod11]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod12]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod13]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod14]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod15]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod16]);
            AddVehicleComponent(vehicleid, VehicleData[vehicleid][Mod17]);
            SetVehicleHealth(vehicleid, VehicleData[vehicleid][Health]);
            SetVehicleNumberPlate(vehicleid, VehicleData[vehicleid][Number]);
            CreateVehicle(VehicleData[vehicleid][Model], VehicleData[vehicleid][PositionX], VehicleData[vehicleid][PositionY], VehicleData[vehicleid][PositionZ], VehicleData[vehicleid][PositionA], VehicleData[vehicleid][Color1], VehicleData[vehicleid][Color2], 1000);
            SetVehicleParamsEx(VehicleData[vehicleid][Model], VehicleData[vehicleid][Engine], VehicleData[vehicleid][Lights], VehicleData[vehicleid][Alarm], VehicleData[vehicleid][DoorLock], VehicleData[vehicleid][Bonnet], VehicleData[vehicleid][Trunk], 0);
        }
    }
    return 1;
}


EDIT: How would you expect it to load if you're not saving it correctly, check your saving query.
Ox1gEN is offline   Reply With Quote
Old 10/09/2014, 05:28 PM   #7
TheNerka
Huge Clucker
 
Join Date: Aug 2013
Posts: 240
Reputation: 2
Default Re: How to load and save vehicles from MySQL R38?

my savevehicle

Code:
forward SaveVehicleData();
public SaveVehicleData()
{
    AntiDeAMX();
    for(new vehicleid = 1;vehicleid<500;vehicleid++)
    {
        new objective;
        GetVehiclePos(vehicleid, VehicleData[vehicleid][PositionX],VehicleData[vehicleid][PositionY],VehicleData[vehicleid][PositionZ]);
        GetVehicleZAngle(vehicleid,VehicleData[vehicleid][PositionA]);
        GetVehicleHealth(vehicleid, VehicleData[vehicleid][Health]);
        GetVehicleParamsEx(VehicleData[vehicleid][Model], VehicleData[vehicleid][Engine], VehicleData[vehicleid][Lights], VehicleData[vehicleid][Alarm], VehicleData[vehicleid][DoorLock], VehicleData[vehicleid][Bonnet], VehicleData[vehicleid][Trunk], objective);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod1]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod2]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod3]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod4]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod5]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod6]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod7]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod8]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod9]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod10]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod11]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod12]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod13]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod14]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod15]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod16]);
        GetVehicleComponentInSlot(vehicleid, VehicleData[vehicleid][Mod17]);

        mysql_format(Mysql_users, query, sizeof(query), "UPDATE `"MASINU_LENTELE"` SET Fullname='%e', Number='%e', Model='%d', PositionX='%f', PositionY='%f', PositionZ='%f', PositionA='%f', Health='%f', Color1='%d', Color2='%d', Mod1='%d', Mod2='%d', Mod3='%d', Mod4='%d', Mod5='%d', Mod6='%d', Mod7='%d'",\
        VehicleData[vehicleid][Fullname],
        VehicleData[vehicleid][Number],
        VehicleData[vehicleid][Model],
        VehicleData[vehicleid][PositionX],
        VehicleData[vehicleid][PositionY],
        VehicleData[vehicleid][PositionZ],
        VehicleData[vehicleid][PositionA],
        VehicleData[vehicleid][Health],
        VehicleData[vehicleid][Color1],
        VehicleData[vehicleid][Color2],
        VehicleData[vehicleid][Mod1],
        VehicleData[vehicleid][Mod2],
        VehicleData[vehicleid][Mod3],
        VehicleData[vehicleid][Mod4],
        VehicleData[vehicleid][Mod5],
        VehicleData[vehicleid][Mod6],
        VehicleData[vehicleid][Mod7]);

        mysql_format(Mysql_users, query, sizeof(query), "%s, Mod8='%d', Mod9='%d', Mod10='%d', Mod11='%d', Mod12='%d', Mod13='%d', Mod14='%d', Mod15='%d', Mod16='%d', Mod17='%d', Trunk='%d', DoorLock='%d', Bonnet='%d', Engine='%d', Lights='%d', Alarm='%d' WHERE Fullname='%e'",\
        query,
        VehicleData[vehicleid][Mod8],
        VehicleData[vehicleid][Mod9],
        VehicleData[vehicleid][Mod10],
        VehicleData[vehicleid][Mod11],
        VehicleData[vehicleid][Mod12],
        VehicleData[vehicleid][Mod13],
        VehicleData[vehicleid][Mod14],
        VehicleData[vehicleid][Mod15],
        VehicleData[vehicleid][Mod16],
        VehicleData[vehicleid][Mod17],
        VehicleData[vehicleid][Trunk],
        VehicleData[vehicleid][Lights],
        VehicleData[vehicleid][Bonnet],
        VehicleData[vehicleid][Engine],
        VehicleData[vehicleid][Alarm],
        VehicleData[vehicleid][Fullname]);
        mysql_tquery(Mysql_users, query, "", "");
    }
}
TheNerka is offline   Reply With Quote
Old 11/09/2014, 12:40 PM   #8
TheNerka
Huge Clucker
 
Join Date: Aug 2013
Posts: 240
Reputation: 2
Default Re: How to load and save vehicles from MySQL R38?

....
TheNerka is offline   Reply With Quote
Old 11/09/2014, 12:52 PM   #9
Ox1gEN
Huge Clucker
 
Ox1gEN's Avatar
 
Join Date: Aug 2014
Location: New Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); printf("%f%f%f", x, y, z);
Posts: 358
Reputation: 29
Default Re: How to load and save vehicles from MySQL R38?

Gimmie the log of the saving query.
Ox1gEN is offline   Reply With Quote
Old 11/09/2014, 01:06 PM   #10
TheNerka
Huge Clucker
 
Join Date: Aug 2013
Posts: 240
Reputation: 2
Default Re: How to load and save vehicles from MySQL R38?

Not give log, but onplayerdisconnect have SaveVehiclePos();

UPDATE: created cmd with vehicle save got log:

Code:
[16:06:57] [DEBUG] cache_get_data - connection: 1
[16:06:57] [WARNING] cache_get_data - no active cache
TheNerka is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save then load [MYSQL] anou1 Scripting Help 4 16/01/2014 10:13 AM
[FilterScript] Load, Spawn & Save Vehicles woaha Filterscripts 9 13/07/2013 07:04 PM
Load Vehicles + MYSQL Stefand Scripting Help 2 04/06/2013 02:44 PM
Mysql load all vehicles from a table. Admigo Scripting Help 1 27/04/2013 08:27 PM
MySQL: Vehicles don't load... Tee Help Archive 0 08/08/2011 09:13 AM


All times are GMT. The time now is 03:26 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.