MySQL problem
#1

Hey guys,

I'm working on a faction vehicle system that dynamically saves vehicles but the problem is that my system messes up on server start (meaning that when the loading of faction vehicles comes) it takes it time and makes it hard to figure out why it is restricting the server from fully loading.

Here is the code:
pawn Код:
stock LoadFactionVehicles()
{
    new Query[500];
    for(new i = 1;i<MAX_FACTION_VEHICLES;i++)
    {
        format(Query, sizeof(Query), "SELECT * FROM `vehicledata` WHERE `ID` = %d LIMIT 1", i);
        mysql_query(Query);
        mysql_store_result();
        while(mysql_fetch_row(Query))
        {
            mysql_fetch_int("ID", vInfo[i][ID]);
            mysql_fetch_int("ModelID", vInfo[i][ModelID]);
            mysql_fetch_int("posX", vInfo[i][posX]);
            mysql_fetch_int("posY", vInfo[i][posY]);
            mysql_fetch_int("posZ", vInfo[i][posZ]);
            mysql_fetch_int("posA", vInfo[i][posA]);
            mysql_fetch_int("ColorA", vInfo[i][ColorA]);
            mysql_fetch_int("ColorB", vInfo[i][ColorB]);
            mysql_fetch_int("Faction", vInfo[i][Faction]);
            mysql_fetch_int("Plate", vInfo[i][NrPlate]);

            CreateVehicle(vInfo[i][ModelID], vInfo[i][posX], vInfo[i][posY], vInfo[i][posZ], vInfo[i][posA], vInfo[i][ColorA], vInfo[i][ColorB], 10000000000000, 1);
            SetVehicleNumberPlate(i, vInfo[i][NrPlate]);

            SetVehicleParamsForPlayer(i, i, 0, 1);
            SetVehicleToRespawn(i);
        }
        mysql_free_result();
    }
    return 1;
}
I can post the other codes of the system if needed.
Reply
#2

Bump.. Someone please help me as no one likes to respond to any of my bloody posts...
Reply
#3

PHP код:
forward OnLoadFactionVehicles();
stock LoadFactionVehicles()
{
    
mysql_function_query(MySQL"SELECT * FROM `vehicledata`"true"OnLoadFactionVehicles""");
    return 
1;
}
public 
OnLoadFactionVehicles()
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsMySQL);
    if(
rows)
    {
        for(new 
0rowsv++)
        {
            new 
vID cache_get_field_content_int(v"ID");
            
vInfo[vID][ID] = vID;
            
vInfo[vID][ModelID] = cache_get_field_content_int(v"ModelID");
            
vInfo[vID][posX] = cache_get_field_content_float(v"posX");
            
vInfo[vID][posY] = cache_get_field_content_float(v"posY");
            
vInfo[vID][posZ] = cache_get_field_content_float(v"posZ");
            
vInfo[vID][posA] = cache_get_field_content_float(v"posA");
            
vInfo[vID][ColorA] = cache_get_field_content_int(v"ColorA");
            
vInfo[vID][ColorB] = cache_get_field_content_int(v"ColorB");
            
vInfo[vID][Faction] = cache_get_field_content_int(v"Faction");
            
cache_get_field_content(v"Plate"vInfo[vID][NrPlate]);
        }
    }
    return 
1;

This is the way I load from MySQL... works great.

Also you was sending a lot of queries to the database, this will most defiantly slow down the server / make it lag. This sends 1 query.
Reply
#4

Quote:
Originally Posted by d3ll
Посмотреть сообщение
PHP код:
forward OnLoadFactionVehicles();
stock LoadFactionVehicles()
{
    
mysql_function_query(MySQL"SELECT * FROM `vehicledata`"true"OnLoadFactionVehicles""");
    return 
1;
}
public 
OnLoadFactionVehicles()
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsMySQL);
    if(
rows)
    {
        for(new 
0rowsv++)
        {
            new 
vID cache_get_field_content_int(v"ID");
            
vInfo[vID][ID] = vID;
            
vInfo[vID][ModelID] = cache_get_field_content_int(v"ModelID");
            
vInfo[vID][posX] = cache_get_field_content_float(v"posX");
            
vInfo[vID][posY] = cache_get_field_content_float(v"posY");
            
vInfo[vID][posZ] = cache_get_field_content_float(v"posZ");
            
vInfo[vID][posA] = cache_get_field_content_float(v"posA");
            
vInfo[vID][ColorA] = cache_get_field_content_int(v"ColorA");
            
vInfo[vID][ColorB] = cache_get_field_content_int(v"ColorB");
            
vInfo[vID][Faction] = cache_get_field_content_int(v"Faction");
            
cache_get_field_content(v"Plate"vInfo[vID][NrPlate]);
        }
    }
    return 
1;

This is the way I load from MySQL... works great.

Also you was sending a lot of queries to the database, this will most defiantly slow down the server / make it lag. This sends 1 query.
The cache_get_field gives me errors because am using BlueG's plugin
Reply
#5

Yes, am using BlueGs version too. It works fine with me, try replacing the MySQL files with the latest version.
Reply
#6

Quote:
Originally Posted by d3ll
Посмотреть сообщение
Yes, am using BlueGs version too. It works fine with me, try replacing the MySQL files with the latest version.
My bad it is actually StrickenKid's MySQL plugin...
Reply
#7

Not sure if this will work but give it a try.

PHP код:
stock LoadFactionVehicles()
{
    new 
Query[500];
    for(new 
1;i<MAX_FACTION_VEHICLES;i++)
    {
        
format(Querysizeof(Query), "SELECT * FROM `vehicledata` WHERE `ID` = %d LIMIT 1"i);
        
mysql_query(Query);
        
mysql_store_result();
        while(
mysql_fetch_row(Query))
        {
            
mysql_fetch_int("ID"vInfo[i][ID]);
            
mysql_fetch_int("ModelID"vInfo[i][ModelID]);
            
mysql_fetch_float("posX"vInfo[i][posX]);
            
mysql_fetch_float("posY"vInfo[i][posY]);
            
mysql_fetch_float("posZ"vInfo[i][posZ]);
            
mysql_fetch_float("posA"vInfo[i][posA]);
            
mysql_fetch_int("ColorA"vInfo[i][ColorA]);
            
mysql_fetch_int("ColorB"vInfo[i][ColorB]);
            
mysql_fetch_int("Faction"vInfo[i][Faction]);
            
mysql_fetch_int("Plate"vInfo[i][NrPlate]);

            
CreateVehicle(vInfo[i][ModelID], vInfo[i][posX], vInfo[i][posY], vInfo[i][posZ], vInfo[i][posA], vInfo[i][ColorA], vInfo[i][ColorB], 100000000000001);
            
SetVehicleNumberPlate(ivInfo[i][NrPlate]);

            
SetVehicleParamsForPlayer(ii01);
            
SetVehicleToRespawn(i);
        }
        
mysql_free_result();
    }
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)