SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 08/06/2015, 05:46 PM   #1
DarkLouis
Big Clucker
 
DarkLouis's Avatar
 
Join Date: Jan 2014
Location: Italy
Posts: 152
Reputation: 14
Default MYSQL - Load vehicles.

Hi all, I'm newbie at MYSQL.

Today I converted my Y_INI Vehicle System to MYSQL.

The register step work very well.

Load vehicle step don't work.

I did:

PHP Code:

function LoadingVehicle(id)
{
    new 
string[250];
    
    
Veicolo[id][ID] = cache_get_field_content_int(0"ID");
    
Veicolo[id][Creato] = cache_get_field_content_int(0"Creato");
    
Veicolo[id][Modello] = cache_get_field_content_int(0"Modello");
    
Veicolo[id][Costo] = cache_get_field_content_int(0"Costo");
    
Veicolo[id][Creato] = cache_get_field_content_int(0"Creato");
    
Veicolo[id][Colore_uno] = cache_get_field_content_int(0"Colore_uno");
    
Veicolo[id][Colore_due] = cache_get_field_content_int(0"Colore_due");
    
Veicolo[id][Chiuso] = cache_get_field_content_int(0"Chiuso");
    
Veicolo[id][Motore] = cache_get_field_content_int(0"Motore");
    
Veicolo[id][Fari] = cache_get_field_content_int(0"Fari");
    
Veicolo[id][Bagagliaio] = cache_get_field_content_int(0"Bagagliaio");
    
Veicolo[id][Cofano] = cache_get_field_content_int(0"Cofano");
    
Veicolo[id][Carburante] = cache_get_field_content_int(0"Carburante");
    
Veicolo[id][Acquistato] = cache_get_field_content_int(0"Acquistato");
    
Veicolo[id][Distrutto] = cache_get_field_content_int(0"Distrutto");
    
Veicolo[id][DiFazione] = cache_get_field_content_int(0"Fazione");
    
Veicolo[id][Sirena] = cache_get_field_content_int(0"Sirena");
    
Veicolo[id][LimiteCarburante] = cache_get_field_content_int(0"LimiteCarburante");
    
    
Veicolo[id][vX] = cache_get_field_content_float(0"Posizione_X");
    
Veicolo[id][vY] = cache_get_field_content_float(0"Posizione_Y");
    
Veicolo[id][vZ] = cache_get_field_content_float(0"Posizione_Z");
    
Veicolo[id][vA] = cache_get_field_content_float(0"Posizione_A");
    
Veicolo[id][rX] = cache_get_field_content_float(0"Respawn_X");
    
Veicolo[id][rY] = cache_get_field_content_float(0"Respawn_Y");
    
Veicolo[id][rZ] = cache_get_field_content_float(0"Respawn_Z");
    
Veicolo[id][rA] = cache_get_field_content_float(0"Respawn_A");
    
Veicolo[id][vHP] = cache_get_field_content_float(0"HP");
    
    
cache_get_field_content(0"Proprietario"Veicolo[id][Proprietario]);
    
    if(
Veicolo[id][Creato] == 1)
    {
                
Veicolo[id][vO] = CreateVehicle(Veicolo[id][Modello], Veicolo[id][vX], Veicolo[id][vY], Veicolo[id][vZ], Veicolo[id][vA], Veicolo[id][Colore_uno], Veicolo[id][Colore_due], -1Veicolo[id][Sirena]);
       
    }
    
    
printf("Server: %d veicoli sono stati caricati!"id);
}

function 
LoadVehicle()
{
    for(new 
id 1id sizeof(Veicolo); id++)
    {
        new 
query[2000];
        
mysql_format(mysqlquerysizeof(query), "SELECT * FROM Veicolo");
        
mysql_tquery(mysqlquery"LoadingVehicle""i"id);
    }
    return 
1;

It don't work. How can I fix this?
DarkLouis is offline   Reply With Quote
Old 08/06/2015, 06:09 PM   #2
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,831
Reputation: 1401
Default Re: MYSQL - Load vehicles.

Send one query and retrieve the data with a loop. Also in cache_get_field_content, you need to specify the length of the enum-array.

PHP Code:
LoadVehicles()
{
    
mysql_tquery(mysql"SELECT * FROM Veicolo""LoadingVehicles""");
    return 
1;
}

forward LoadingVehicles();
public 
LoadingVehicles()
{
    new 
rows cache_get_row_count();
    
    
printf("Server: %d veicoli sono stati caricati!"rows);
    
    for (new 
idid != rows; ++id)
    {
        if (
id >= sizeof (Veicolo)) break;
        
        
Veicolo[id][ID] = cache_get_field_content_int(id"ID");
        
Veicolo[id][Creato] = cache_get_field_content_int(id"Creato");
        
Veicolo[id][Modello] = cache_get_field_content_int(id"Modello");
        
Veicolo[id][Costo] = cache_get_field_content_int(id"Costo");
        
Veicolo[id][Creato] = cache_get_field_content_int(id"Creato");
        
Veicolo[id][Colore_uno] = cache_get_field_content_int(id"Colore_uno");
        
Veicolo[id][Colore_due] = cache_get_field_content_int(id"Colore_due");
        
Veicolo[id][Chiuso] = cache_get_field_content_int(id"Chiuso");
        
Veicolo[id][Motore] = cache_get_field_content_int(id"Motore");
        
Veicolo[id][Fari] = cache_get_field_content_int(id"Fari");
        
Veicolo[id][Bagagliaio] = cache_get_field_content_int(id"Bagagliaio");
        
Veicolo[id][Cofano] = cache_get_field_content_int(id"Cofano");
        
Veicolo[id][Carburante] = cache_get_field_content_int(id"Carburante");
        
Veicolo[id][Acquistato] = cache_get_field_content_int(id"Acquistato");
        
Veicolo[id][Distrutto] = cache_get_field_content_int(id"Distrutto");
        
Veicolo[id][DiFazione] = cache_get_field_content_int(id"Fazione");
        
Veicolo[id][Sirena] = cache_get_field_content_int(id"Sirena");
        
Veicolo[id][LimiteCarburante] = cache_get_field_content_int(id"LimiteCarburante");
        
        
Veicolo[id][vX] = cache_get_field_content_float(id"Posizione_X");
        
Veicolo[id][vY] = cache_get_field_content_float(id"Posizione_Y");
        
Veicolo[id][vZ] = cache_get_field_content_float(id"Posizione_Z");
        
Veicolo[id][vA] = cache_get_field_content_float(id"Posizione_A");
        
Veicolo[id][rX] = cache_get_field_content_float(id"Respawn_X");
        
Veicolo[id][rY] = cache_get_field_content_float(id"Respawn_Y");
        
Veicolo[id][rZ] = cache_get_field_content_float(id"Respawn_Z");
        
Veicolo[id][rA] = cache_get_field_content_float(id"Respawn_A");
        
Veicolo[id][vHP] = cache_get_field_content_float(id"HP");
        
        
cache_get_field_content(id"Proprietario"Veicolo[id][Proprietario], mysql/* SIZE OF Proprietario HERE */);
        
        if(
Veicolo[id][Creato] == 1)
        {
            
Veicolo[id][vO] = CreateVehicle(Veicolo[id][Modello], Veicolo[id][vX], Veicolo[id][vY], Veicolo[id][vZ], Veicolo[id][vA], Veicolo[id][Colore_uno], Veicolo[id][Colore_due], -1Veicolo[id][Sirena]);
        }
    }
    return 
1;

__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 09/06/2015, 08:27 AM   #3
DarkLouis
Big Clucker
 
DarkLouis's Avatar
 
Join Date: Jan 2014
Location: Italy
Posts: 152
Reputation: 14
Default Re: MYSQL - Load vehicles.

Thank you very much Konstantinos! Now I understand.

Can you give me your SKYPE? Maybe if I need another help or you want to ask me anything..

Mine it's: xdarklouis
DarkLouis 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 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 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
Load Faction Vehicles problem (mysql) oliverrud Help Archive 2 24/06/2010 10:17 PM


All times are GMT. The time now is 04:34 PM.


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