SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 31/01/2020, 12:44 PM   #1
OsmanMalagic
Little Clucker
 
Join Date: Jul 2016
Location: EX-YU
Posts: 40
Reputation: 51
Default MySQL load vehicles issue

Hi guys, i have one issue with my Vehicles.
I created saving system using MySQL but my loading system not working properly.
Vehicle ID must be 1 because the car is private, and ID must go from 1 to 1000.
System loading different ID (last Car ID created on server).
I using enum CarInfo for vehicles..

PHP Code:
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `vehicles`");
mysql_pquery(mysqlquery"LoadVehicles""");

forward LoadVehicles();
public 
LoadVehicles()
{
    new 
rowsfieldscountdata[24];
    
cache_get_data(rowsfields);
    for(new 
0rowsi++)
    {
        for(new 
1sizeof(CarInfo); j++)
        {
            
cache_get_field_content(i"ID"data); CarInfo[j][cID] = strval(data);
            
cache_get_field_content(i"CarID"data); CarInfo[j][cCarID] = strval(data);
            
cache_get_field_content(i"Owned"data); CarInfo[j][cOwned] = strval(data);
            
cache_get_field_content(i"Owner"data); strmid(CarInfo[j][cOwner], data0strlen(data), 64);
            
cache_get_field_content(i"Model"data); CarInfo[j][cModel] = strval(data);
            
cache_get_field_content(i"Location_X"data); CarInfo[j][cLocationx] = floatstr(data);
            
cache_get_field_content(i"Location_Y"data); CarInfo[j][cLocationy] = floatstr(data);
            
cache_get_field_content(i"Location_Z"data); CarInfo[j][cLocationz] = floatstr(data);
            
cache_get_field_content(i"Angle"data); CarInfo[j][cAngle] = floatstr(data);
            
cache_get_field_content(i"Color_1"data); CarInfo[j][cColorOne] = strval(data);
            
cache_get_field_content(i"Color_2"data); CarInfo[j][cColorTwo] = strval(data);
            
cache_get_field_content(i"VirtualWorld"data); CarInfo[j][cVirWorld] = strval(data);

            if(
CarInfo[j][cOwned] == || CarInfo[j][cModel] == 0)
            {
                
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(510, -804.53843791.850639.4313+jCarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
            }
            else
            {
                
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(CarInfo[j][cModel], CarInfo[j][cLocationx], CarInfo[j][cLocationy], CarInfo[j][cLocationz]+1.0CarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
            }
            
count++;
            break;
        }
    }
    return 
1;

What i do wrong?
OsmanMalagic is offline   Reply With Quote
Old 31/01/2020, 02:26 PM   #2
SiaReyes
Gangsta
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 622
Reputation: 57
Default Re: MySQL load vehicles issue

pawn Code:
forward LoadVehicles();
public LoadVehicles()
{
    new rows, fields, count, data[24], id;
    cache_get_data(rows, fields);
    for(new i = 0; i < rows; i++)
    {

            id = cache_get_field_content_int(i, "ID");
            CarInfo[id][cID] = id;

            cache_get_field_content(i, "CarID", data);
            CarInfo[id][cCarID] = strval(data);
            cache_get_field_content(i, "Owned", data);
            CarInfo[id][cOwned] = strval(data);
            cache_get_field_content(i, "Owner", data);
            strmid(CarInfo[id][cOwner], data, 0, strlen(data), 64);
            cache_get_field_content(i, "Model", data);
            CarInfo[id][cModel] = strval(data);
            cache_get_field_content(i, "Location_X", data); CarInfo[id][cLocationx] = floatstr(data);
            cache_get_field_content(i, "Location_Y", data); CarInfo[id][cLocationy] = floatstr(data);
            cache_get_field_content(i, "Location_Z", data); CarInfo[id][cLocationz] = floatstr(data);

            cache_get_field_content(i, "Angle", data);
            CarInfo[id][cAngle] = floatstr(data);
            cache_get_field_content(i, "Color_1", data);
            CarInfo[id][cColorOne] = strval(data);
            cache_get_field_content(i, "Color_2", data);
            CarInfo[id][cColorTwo] = strval(data);
            cache_get_field_content(i, "VirtualWorld", data);
            CarInfo[id][cVirWorld] = strval(data);

            if(CarInfo[id][cOwned] == 0 || CarInfo[id][cModel] == 0)
            {
                CarInfo[id][cCarID] = NBC_AddStaticVehicleEx(510, -804.5384, 3791.8506, 39.4313+j, CarInfo[id][cAngle], CarInfo[id][cColorOne], CarInfo[id][cColorTwo], 60000, 0);
            }
            else
            {
                CarInfo[id][cCarID] = NBC_AddStaticVehicleEx(CarInfo[id][cModel], CarInfo[id][cLocationx], CarInfo[id][cLocationy], CarInfo[id][cLocationz]+1.0, CarInfo[id][cAngle], CarInfo[id][cColorOne], CarInfo[id][cColorTwo], 60000, 0);
            }
            count++;
    }
    return 1;
}

Try this.
SiaReyes is offline   Reply With Quote
Old 31/01/2020, 08:21 PM   #3
OsmanMalagic
Little Clucker
 
Join Date: Jul 2016
Location: EX-YU
Posts: 40
Reputation: 51
Default Re: MySQL load vehicles issue

Quote:
Originally Posted by SiaReyes View Post
pawn Code:
forward LoadVehicles();
public LoadVehicles()
{
    new rows, fields, count, data[24], id;
    cache_get_data(rows, fields);
    for(new i = 0; i < rows; i++)
    {

            id = cache_get_field_content_int(i, "ID");
            CarInfo[id][cID] = id;

            cache_get_field_content(i, "CarID", data);
            CarInfo[id][cCarID] = strval(data);
            cache_get_field_content(i, "Owned", data);
            CarInfo[id][cOwned] = strval(data);
            cache_get_field_content(i, "Owner", data);
            strmid(CarInfo[id][cOwner], data, 0, strlen(data), 64);
            cache_get_field_content(i, "Model", data);
            CarInfo[id][cModel] = strval(data);
            cache_get_field_content(i, "Location_X", data); CarInfo[id][cLocationx] = floatstr(data);
            cache_get_field_content(i, "Location_Y", data); CarInfo[id][cLocationy] = floatstr(data);
            cache_get_field_content(i, "Location_Z", data); CarInfo[id][cLocationz] = floatstr(data);

            cache_get_field_content(i, "Angle", data);
            CarInfo[id][cAngle] = floatstr(data);
            cache_get_field_content(i, "Color_1", data);
            CarInfo[id][cColorOne] = strval(data);
            cache_get_field_content(i, "Color_2", data);
            CarInfo[id][cColorTwo] = strval(data);
            cache_get_field_content(i, "VirtualWorld", data);
            CarInfo[id][cVirWorld] = strval(data);

            if(CarInfo[id][cOwned] == 0 || CarInfo[id][cModel] == 0)
            {
                CarInfo[id][cCarID] = NBC_AddStaticVehicleEx(510, -804.5384, 3791.8506, 39.4313+j, CarInfo[id][cAngle], CarInfo[id][cColorOne], CarInfo[id][cColorTwo], 60000, 0);
            }
            else
            {
                CarInfo[id][cCarID] = NBC_AddStaticVehicleEx(CarInfo[id][cModel], CarInfo[id][cLocationx], CarInfo[id][cLocationy], CarInfo[id][cLocationz]+1.0, CarInfo[id][cAngle], CarInfo[id][cColorOne], CarInfo[id][cColorTwo], 60000, 0);
            }
            count++;
    }
    return 1;
}

Try this.


Again same..
Vehicle ID is 503 not ID 1.
In my Table on MySQL vehicle ID is 1, but on server it's not.
OsmanMalagic is offline   Reply With Quote
Old 31/01/2020, 08:34 PM   #4
xRadical3
Gangsta
 
xRadical3's Avatar
 
Join Date: May 2017
Location: Iran
Posts: 544
Reputation: 19
Default Re: MySQL load vehicles issue

So,
pawn Code:
for(new j = 1; j < sizeof(CarInfo); j++)
i think this must be
pawn Code:
foreach(new j : Vehicle)
//or
for(new j = 1; j < GetVehiclePoolSize(); j++)

CarInfo new like this?:
pawn Code:
new CarInfo[MAX_VEHICLES][CarEnum];
Right?

Your second mistake is use break;
This break the loop and not continue and car id in database right but in server diffrent ids...
xRadical3 is offline   Reply With Quote
Old 31/01/2020, 09:15 PM   #5
OsmanMalagic
Little Clucker
 
Join Date: Jul 2016
Location: EX-YU
Posts: 40
Reputation: 51
Default Re: MySQL load vehicles issue

Quote:
Originally Posted by Vizi10 View Post
So,
pawn Code:
for(new j = 1; j < sizeof(CarInfo); j++)
i think this must be
pawn Code:
foreach(new j : Vehicle)
//or
for(new j = 1; j < GetVehiclePoolSize(); j++)

CarInfo new like this?:
pawn Code:
new CarInfo[MAX_VEHICLES][CarEnum];
Right?

Your second mistake is use break;
This break the loop and not continue and car id in database right but in server diffrent ids...
If i delete break; Server spawn me 1000 same vehicles in my area, which cause massive lag.
Of course i use
PHP Code:
new CarInfo[600][cInfo]; 
My old loading sistem on y_ini going like this

PHP Code:
for(new 1sizeof(CarInfo); h++)
    {
        new 
vstr[40];
           
format(vstrsizeof(vstr), "NBCRP/Vehicles/%d.ini"h);
        if(
fexist(vstr))
        {
            
INI_ParseFile(vstr"LoadVehicles", .bExtra true, .extra h);
            if(
CarInfo[h][cOwned] == || CarInfo[h][cModel] == 0)
            {
                
CarInfo[h][cID] = NBC_CreateVehicle(510, -804.53843791.850639.4313+hCarInfo[h][cAngle], CarInfo[h][cColorOne], CarInfo[h][cColorTwo], 60000);
            }
            else
            {
                
CarInfo[h][cID] = NBC_CreateVehicle(CarInfo[h][cModel], CarInfo[h][cLocationx], CarInfo[h][cLocationy], CarInfo[h][cLocationz]+1.0CarInfo[h][cAngle], CarInfo[h][cColorOne], CarInfo[h][cColorTwo], 60000);
            }
        }
    } 
OsmanMalagic is offline   Reply With Quote
Old 02/02/2020, 06:00 AM   #6
Filip21
Little Clucker
 
Join Date: Nov 2017
Posts: 8
Reputation: 0
Default Re: MySQL load vehicles issue

Quote:
Originally Posted by OsmanMalagic View Post
Hi guys, i have one issue with my Vehicles.
I created saving system using MySQL but my loading system not working properly.
Vehicle ID must be 1 because the car is private, and ID must go from 1 to 1000.
System loading different ID (last Car ID created on server).
I using enum CarInfo for vehicles..

PHP Code:
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `vehicles`");
mysql_pquery(mysqlquery"LoadVehicles""");

forward LoadVehicles();
public 
LoadVehicles()
{
    new 
rowsfieldscountdata[24];
    
cache_get_data(rowsfields);
    for(new 
0rowsi++)
    {
        for(new 
1sizeof(CarInfo); j++)
        {
            
cache_get_field_content(i"ID"data); CarInfo[j][cID] = strval(data);
            
cache_get_field_content(i"CarID"data); CarInfo[j][cCarID] = strval(data);
            
cache_get_field_content(i"Owned"data); CarInfo[j][cOwned] = strval(data);
            
cache_get_field_content(i"Owner"data); strmid(CarInfo[j][cOwner], data0strlen(data), 64);
            
cache_get_field_content(i"Model"data); CarInfo[j][cModel] = strval(data);
            
cache_get_field_content(i"Location_X"data); CarInfo[j][cLocationx] = floatstr(data);
            
cache_get_field_content(i"Location_Y"data); CarInfo[j][cLocationy] = floatstr(data);
            
cache_get_field_content(i"Location_Z"data); CarInfo[j][cLocationz] = floatstr(data);
            
cache_get_field_content(i"Angle"data); CarInfo[j][cAngle] = floatstr(data);
            
cache_get_field_content(i"Color_1"data); CarInfo[j][cColorOne] = strval(data);
            
cache_get_field_content(i"Color_2"data); CarInfo[j][cColorTwo] = strval(data);
            
cache_get_field_content(i"VirtualWorld"data); CarInfo[j][cVirWorld] = strval(data);

            if(
CarInfo[j][cOwned] == || CarInfo[j][cModel] == 0)
            {
                
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(510, -804.53843791.850639.4313+jCarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
            }
            else
            {
                
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(CarInfo[j][cModel], CarInfo[j][cLocationx], CarInfo[j][cLocationy], CarInfo[j][cLocationz]+1.0CarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
            }
            
count++;
            break;
        }
    }
    return 
1;

What i do wrong?
PHP Code:
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `vehicles`");
mysql_tquery(mysqlquery"LoadVehicles""");

forward LoadVehicles();
public 
LoadVehicles()
{
    new 
rowsfieldscountdata[24];
    
cache_get_data(rowsfields);
    
    for(new 
1sizeof(CarInfo); j++)
    {
        
cache_get_field_content(j-1"ID"data); CarInfo[j][cID] = strval(data);
        
cache_get_field_content(j-1"CarID"data); CarInfo[j][cCarID] = strval(data);
        
cache_get_field_content(j-1"Owned"data); CarInfo[j][cOwned] = strval(data);
        
cache_get_field_content(j-1"Owner"data); strmid(CarInfo[j][cOwner], data0strlen(data), 64);
        
cache_get_field_content(j-1"Model"data); CarInfo[j][cModel] = strval(data);
        
cache_get_field_content(j-1"Location_X"data); CarInfo[j][cLocationx] = floatstr(data);
        
cache_get_field_content(j-1"Location_Y"data); CarInfo[j][cLocationy] = floatstr(data);
        
cache_get_field_content(j-1"Location_Z"data); CarInfo[j][cLocationz] = floatstr(data);
        
cache_get_field_content(j-1"Angle"data); CarInfo[j][cAngle] = floatstr(data);
        
cache_get_field_content(j-1"Color_1"data); CarInfo[j][cColorOne] = strval(data);
        
cache_get_field_content(j-1"Color_2"data); CarInfo[j][cColorTwo] = strval(data);
        
cache_get_field_content(j-1"VirtualWorld"data); CarInfo[j][cVirWorld] = strval(data);

        if(
CarInfo[j][cOwned] == || CarInfo[j][cModel] == 0)
        {
            
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(510, -804.53843791.850639.4313+jCarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
        }
        else
        {
            
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(CarInfo[j][cModel], CarInfo[j][cLocationx], CarInfo[j][cLocationy], CarInfo[j][cLocationz]+1.0CarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
        }
        
count++; 
    } 
    return 
1;

Filip21 is offline   Reply With Quote
Old 02/02/2020, 05:34 PM   #7
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,702
Reputation: 1664
Default Re: MySQL load vehicles issue

It appears you are referring to 'vehicleid' (The server's vehicle id, created with AddStaticVehicle/CreateVehicle). If you want this to be 1-1000 ingame (like in the MySQL server), make sure to load these vehicles before any other vehicles.

CarInfo[*][cID] should countain the ID from the MySQL database. The CarID is probably the ID that must be used in-game? You should not save such data to the database. Especially since you're re-assigning it afterwards anyway.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#1966
Kwarde is offline   Reply With Quote
Old 03/02/2020, 10:51 AM   #8
OsmanMalagic
Little Clucker
 
Join Date: Jul 2016
Location: EX-YU
Posts: 40
Reputation: 51
Default Re: MySQL load vehicles issue

Quote:
Originally Posted by Filip21 View Post
PHP Code:
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `vehicles`");
mysql_tquery(mysqlquery"LoadVehicles""");

forward LoadVehicles();
public 
LoadVehicles()
{
    new 
rowsfieldscountdata[24];
    
cache_get_data(rowsfields);
    
    for(new 
1sizeof(CarInfo); j++)
    {
        
cache_get_field_content(j-1"ID"data); CarInfo[j][cID] = strval(data);
        
cache_get_field_content(j-1"CarID"data); CarInfo[j][cCarID] = strval(data);
        
cache_get_field_content(j-1"Owned"data); CarInfo[j][cOwned] = strval(data);
        
cache_get_field_content(j-1"Owner"data); strmid(CarInfo[j][cOwner], data0strlen(data), 64);
        
cache_get_field_content(j-1"Model"data); CarInfo[j][cModel] = strval(data);
        
cache_get_field_content(j-1"Location_X"data); CarInfo[j][cLocationx] = floatstr(data);
        
cache_get_field_content(j-1"Location_Y"data); CarInfo[j][cLocationy] = floatstr(data);
        
cache_get_field_content(j-1"Location_Z"data); CarInfo[j][cLocationz] = floatstr(data);
        
cache_get_field_content(j-1"Angle"data); CarInfo[j][cAngle] = floatstr(data);
        
cache_get_field_content(j-1"Color_1"data); CarInfo[j][cColorOne] = strval(data);
        
cache_get_field_content(j-1"Color_2"data); CarInfo[j][cColorTwo] = strval(data);
        
cache_get_field_content(j-1"VirtualWorld"data); CarInfo[j][cVirWorld] = strval(data);

        if(
CarInfo[j][cOwned] == || CarInfo[j][cModel] == 0)
        {
            
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(510, -804.53843791.850639.4313+jCarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
        }
        else
        {
            
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(CarInfo[j][cModel], CarInfo[j][cLocationx], CarInfo[j][cLocationy], CarInfo[j][cLocationz]+1.0CarInfo[j][cAngle], CarInfo[j][cColorOne], CarInfo[j][cColorTwo], 600000);
        }
        
count++; 
    } 
    return 
1;

Again same..
Vehicle ID is 503 not ID 1.


Quote:
Originally Posted by Kwarde View Post
It appears you are referring to 'vehicleid' (The server's vehicle id, created with AddStaticVehicle/CreateVehicle). If you want this to be 1-1000 ingame (like in the MySQL server), make sure to load these vehicles before any other vehicles.

CarInfo[*][cID] should countain the ID from the MySQL database. The CarID is probably the ID that must be used in-game? You should not save such data to the database. Especially since you're re-assigning it afterwards anyway.
Hm, I loading private vehicles first, then all others, that is not a problem.
I store Vehicle Number into my database and then using that Vehicle Number i want to load that car.
Seeing old system on Y_INI all loading values must go trough CarInfo loop then under that values car spawns.
When i do that, server created same vehicle more than 600 times.
OsmanMalagic is offline   Reply With Quote
Old 03/02/2020, 02:58 PM   #9
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,702
Reputation: 1664
Default Re: MySQL load vehicles issue

I still think you're mixing up the vehicle server ID and the vehicle mysql ID (ID and CarID) somewhere.

Quote:
I store Vehicle Number into my database and then using that Vehicle Number i want to load that car.
Do you refer to this line?:
Code:
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(CarInfo[j][cModel], CarInfo[j][cLocationx]...
Because that does not set a vehicle ID. It merely creates a vehicle and sets CarInfo[*][cCarID] to the ID of the newly created vehicle. Storing and loading that data (CarID) is really just a waste of space because you store it, load it, and then overwrite it again.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#1966
Kwarde is offline   Reply With Quote
Old 03/02/2020, 03:16 PM   #10
OsmanMalagic
Little Clucker
 
Join Date: Jul 2016
Location: EX-YU
Posts: 40
Reputation: 51
Default Re: MySQL load vehicles issue

Quote:
Originally Posted by Kwarde View Post
I still think you're mixing up the vehicle server ID and the vehicle mysql ID (ID and CarID) somewhere.


Do you refer to this line?:
Code:
CarInfo[j][cCarID] = NBC_AddStaticVehicleEx(CarInfo[j][cModel], CarInfo[j][cLocationx]...
Because that does not set a vehicle ID. It merely creates a vehicle and sets CarInfo[*][cCarID] to the ID of the newly created vehicle. Storing and loading that data (CarID) is really just a waste of space because you store it, load it, and then overwrite it again.
I have 2 variable for vehicles.

First is:
PHP Code:
new ownedcar[sizeof(CarInfo)]; 
Second is when i buy the car

PHP Code:
new car 1;
for(new 
1sizeof(CarInfo); h++)
{
    if(
CarInfo[h][cOwned] == 0)
    {
        
car h;
        
9999;
    }
}
CarInfo[car][cCarID] = car;
ownedcar[car] = NBC_AddStaticVehicleEx(CarInfo[car][cModel], CarInfo[car][cLocationx], CarInfo[car][cLocationy], CarInfo[car][cLocationz], CarInfo[car][cAngle], 11600000); 
For loading it must be:
PHP Code:
for(new 1sizeof(CarInfo); h++)
{
    if(
CarInfo[h][cOwned] == || CarInfo[h][cModel] == 0)
     {
        
ownedcar[h] = NBC_AddStaticVehicleEx(510,-804.5384,3791.8506,39.4313+h,CarInfo[h][cAngle],CarInfo[h][cColorOne],CarInfo[h][cColorTwo],600000);
    }
     else
    {
        
ownedcar[h] = NBC_AddStaticVehicleEx(CarInfo[h][cModel],CarInfo[h][cLocationx],CarInfo[h][cLocationy],CarInfo[h][cLocationz]+1.0,CarInfo[h][cAngle],CarInfo[h][cColorOne],CarInfo[h][cColorTwo],600000);
    }

Yes i mixing up the vehicle server ID and the vehicle mysql ID (ID and CarID) somewhere, but where.. Only in loading.
I tryed on 1000 ways using CarInfo loop, and sometimes ID of Vehicle is 1000, or less.
OsmanMalagic 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
MYSQL - Load vehicles. DarkLouis Scripting Help 2 09/06/2015 08:27 AM
MySQL Load Issue RedCounty Scripting Help 4 14/01/2015 09:03 PM
How to load and save vehicles from MySQL R38? TheNerka Scripting Help 21 12/09/2014 02:32 PM
Load Vehicles + MYSQL Stefand Scripting Help 2 04/06/2013 02:44 PM
MySQL: Vehicles don't load... Tee Help Archive 0 08/08/2011 09:13 AM


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


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