SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 14/01/2015, 09:34 AM   #1
RedCounty
Big Clucker
 
Join Date: Nov 2013
Posts: 76
Reputation: 16
Default MySQL Load Issue

I have this code:

pawn Code:
forward loadPlayerVehiclesSQL(playerid);
public loadPlayerVehiclesSQL(playerid)
{
    new rows, fields, vehicleid=-1;
   
    cache_get_data(rows, fields, sqlConnection);
   
    for(new i = 0; i < rows && i < 3; i++)
    {
        vehicleid = CreateVehicle(cache_get_field_content_int(0, "Model", sqlConnection), cache_get_field_content_float(0, "X", sqlConnection), cache_get_field_content_float(0, "Y", sqlConnection), cache_get_field_content_float(0, "Z", sqlConnection), cache_get_field_content_float(0, "A", sqlConnection), cache_get_field_content_int(0, "Color1", sqlConnection), cache_get_field_content_int(0, "Color2", sqlConnection), -1);

        PlayerVehicles[vehicleid][pVehicleID] = cache_get_field_content_int(0, "ID", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleModel] = cache_get_field_content_int(0, "Model", sqlConnection);

        cache_get_field_content(0, "Owner", PlayerVehicles[vehicleid][pVehicleOwner], sqlConnection, 24);

        PlayerVehicles[vehicleid][pVehicleColor][1] = cache_get_field_content_int(0, "Color1", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleColor][2] = cache_get_field_content_int(0, "Color2", sqlConnection);

        PlayerVehicles[vehicleid][pVehiclePos][1] = cache_get_field_content_float(0, "X", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][2] = cache_get_field_content_float(0, "Y", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][3] = cache_get_field_content_float(0, "Z", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][4] = cache_get_field_content_float(0, "A", sqlConnection);

        cache_get_field_content(0, "Plate", PlayerVehicles[vehicleid][pVehiclePlate], sqlConnection, 10);

        SetVehicleNumberPlate(vehicleid, PlayerVehicles[vehicleid][pVehiclePlate]);
        SetVehicleToRespawn(vehicleid);

        ChangeVehiclePaintjob(vehicleid, 3);
        ChangeVehicleColor(vehicleid, PlayerVehicles[vehicleid][pVehicleColor][1], PlayerVehicles[vehicleid][pVehicleColor][2]);

        printf("Vehicle %s loaded (%d) from the database.", GetVehicleName(vehicleid), PlayerVehicles[vehicleid][pVehicleID]);
    }
    return 1;
}

It loads the vehicles just right, well - kind of right. It only loads 1, two times.

I have two vehicles in the database (`playervehicles`) table, one which is an Infernus (ID 400) and one which is a Landstalker (ID 401), it's currently loading the Landstalker two times and not touching the Infernus at all.


The system is designed to call upon a player logging in, which would ensure that the vehicles aren't being flooded at all times. Meaning, once logged in - this SQL is called and the vehicles which have the owner of my name are being loaded, then upon logging out, they're destroying. The whole thing is working perfectly, apart from the loading sector of it which is only loading one model, twice.

Any help is appreciated.
RedCounty is offline   Reply With Quote
Old 14/01/2015, 07:41 PM   #2
RedCounty
Big Clucker
 
Join Date: Nov 2013
Posts: 76
Reputation: 16
Default Re: MySQL Load Issue

pawn Code:
stock LoadPlayerVehicles(playerid)
{
    new query[128];
    mysql_format(sqlConnection, query, sizeof(query), "SELECT * FROM `playervehicles` WHERE `Owner`='%e'", playerName(playerid));
    mysql_function_query(sqlConnection, query, false, "loadPlayerVehiclesSQL", "i", playerid);
    return 1;
}

Here is the load function, anyone?
RedCounty is offline   Reply With Quote
Old 14/01/2015, 07:44 PM   #3
Dignity
High-roller
 
Dignity's Avatar
 
Join Date: May 2013
Location: Belgium
Posts: 1,657
Reputation: 1205
Default Re: MySQL Load Issue

Quote:
Originally Posted by RedCounty View Post
pawn Code:
for(new i = 0; i < rows && i < 3; i++)
This part of the loop is most likely causing the issue:

pawn Code:
i < 3;

Try changing the operator to "<=" instead of "<".


EDIT: I just re-read your post and realize how illogical my solution sounds. Either way, it's still worth a try.
Dignity is offline   Reply With Quote
Old 14/01/2015, 08:06 PM   #4
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,096
Reputation: 96
Default Re: MySQL Load Issue

I don't know why are you making a loop as you're not even using it,

try this
pawn Code:
forward loadPlayerVehiclesSQL(playerid);
public loadPlayerVehiclesSQL(playerid)
{
    new rows, fields, vehicleid=-1;

    cache_get_data(rows, fields, sqlConnection);

    for(new i; i < rows; i++)
    {
        vehicleid = CreateVehicle(cache_get_field_content_int(i, "Model", sqlConnection), cache_get_field_content_float(i, "X", sqlConnection), cache_get_field_content_float(i, "Y", sqlConnection), cache_get_field_content_float(i, "Z", sqlConnection), cache_get_field_content_float(i, "A", sqlConnection), cache_get_field_content_int(i, "Color1", sqlConnection), cache_get_field_content_int(i, "Color2", sqlConnection), -1);

        PlayerVehicles[vehicleid][pVehicleID] = cache_get_field_content_int(i, "ID", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleModel] = cache_get_field_content_int(i, "Model", sqlConnection);

        cache_get_field_content(i, "Owner", PlayerVehicles[vehicleid][pVehicleOwner], sqlConnection, 24);
        cache_get_field_content(i, "Plate", PlayerVehicles[vehicleid][pVehiclePlate], sqlConnection, 10);

        PlayerVehicles[vehicleid][pVehicleColor][1] = cache_get_field_content_int(i, "Color1", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleColor][2] = cache_get_field_content_int(i, "Color2", sqlConnection);

        PlayerVehicles[vehicleid][pVehiclePos][1] = cache_get_field_content_float(i, "X", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][2] = cache_get_field_content_float(i, "Y", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][3] = cache_get_field_content_float(i, "Z", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][4] = cache_get_field_content_float(i, "A", sqlConnection);

        SetVehicleNumberPlate(vehicleid, PlayerVehicles[vehicleid][pVehiclePlate]);
        SetVehicleToRespawn(vehicleid);
       
        ChangeVehiclePaintjob(vehicleid, 3);
        ChangeVehicleColor(vehicleid, PlayerVehicles[vehicleid][pVehicleColor][1], PlayerVehicles[vehicleid][pVehicleColor][2]);

        printf("Vehicle %s loaded (%d) from the database.", GetVehicleName(vehicleid), PlayerVehicles[vehicleid][pVehicleID]);
    }
    return 1;
}
and if it didn't work please show me how do you save cars.
xVIP3Rx is offline   Reply With Quote
Old 14/01/2015, 09:03 PM   #5
RedCounty
Big Clucker
 
Join Date: Nov 2013
Posts: 76
Reputation: 16
Default Re: MySQL Load Issue

I found the issue out as you posted above, it's because I didn't have it looping lol.

Thanks!
RedCounty 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
How to load stuff from mysql using a loop, to load alot of stuff at once Ox1gEN Scripting Help 21 13/10/2014 06:29 PM
[MYSQL] does not load hariboo Scripting Help 6 24/09/2013 07:15 AM
MySQL Connection Issue in mysql.log Vexus Scripting Help 0 06/08/2013 09:33 AM
Mysql Vehicle Load Issue/bug Abreezy Scripting Help 9 14/04/2012 05:33 PM
Slow MySQL load, or script issue? Devine Help Archive 13 16/11/2009 09:09 PM


All times are GMT. The time now is 06:18 AM.


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