MYSQL - Associate vehicle IDs
#1

Hi all. I use this function to load vehicles.

PHP код:

function LoadingVehicles()
{
    new 
rows cache_get_row_count(), string[250];
    
printf("Server: %d veicoli sono stati caricati!"rows);
    for (new 
id 1id != 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], mysql128);
        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;

The problem is that vehicle's ID isn't vehicle's in game. I have my custom vehicle's id.

PHP код:

new id sizeof(Veicolo) + 1;
    
    for(new 
1sizeof(Veicolo); h++)
    {
        if(
Veicolo[h][Creato] == 0)
        {
            
id h;
            break;
        }
    } 
I want that loadingvehicles use Veicolo ID.
Reply
#2

I don't know why that would be necessary since you already save its SQL id. The primary keys ONLY function is to uniquely identify a row in the table. It has no intrinsique value. If you need to update a vehicle, use your "Veicolo[id][ID]" variable.

Also table rows start at 0 so you're skipping over the first one.
Reply
#3

Vince! Thank you so much! It's this the problem, I think. How to skip the first one?

It's only:
PHP код:

if(rows == 0) continue; 
?
Reply
#4

I think Vince meant that you are starting at ID 1, whilst IDs should start at 0:

pawn Код:
for (new id = 1; id != rows; ++id)
At the above line
Reply
#5

No. In my code, it start by 1.

(for(new h = 1; h < sizeof(Veicolo); h++) )
Reply
#6

++id increments the value before the loop starts. So the 'id' variable (not the h variable) starts at id 2, not at 1.
Reply
#7

Veicolo[id][ID] holds the unique SQL ID for each vehicle. It's only used for the queries.
For the real vehicle ID in-game, it's in Veicolo[id][vO].

By the way, what both Vince and mamorunl say is that when loading from mysql the first valid row is 0 and you start from 1 which you skip a vehicle (not what you want).

Quote:
Originally Posted by mamorunl
Посмотреть сообщение
++id increments the value before the loop starts. So the 'id' variable (not the h variable) starts at id 2, not at 1.
It doesn't matters in loops as it still returns the old value.
Reply
#8

My problem is the still... with Y_INI the command /vmenu worked well, now it don't work anymore.
Reply
#9

I created a cmd (/id) that say me the Veicolo's ID.

The first vehicle is -1, second it's 1. Why?
Reply
#10

I created a vehicle without an owner that don't spawn and now all work LOL
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)