SA-MP Forums Archive
MySQL owned vehicle system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL owned vehicle system (/showthread.php?tid=421980)



MySQL owned vehicle system - PaulDinam - 11.03.2013

I've been trying to make a vehicle system for players using mysql (BlueG R

This is my info enums

pawn Код:
enum OWNED_CARS_INFO
{
    carID,
    carModel,
    carColor1,
    carColor2,
    Float:carParkX,
    Float:carParkY,
    Float:carParkZ,
    Float:carParkA,
    carPlate[64],
    carOwner[128],
    carOwned,
    carVehicle,
    carSpawned,
    carOn
}
new OwnedVehicles[MAX_VEHICLES][OWNED_CARS_INFO];
new PlayerVehicle[MAX_PLAYERS][MAX_PLAYER_CARS];
I have the loading function:

pawn Код:
public LoadPlayerVehicles()
{
    new rows, fields, str[128];
    new total = 0;
    cache_get_data(rows, fields);
    if(rows)
    {
        while(total < rows)
        {
            OwnedVehicles[total][carID] = cache_get_row_int(total, 0),
            OwnedVehicles[total][carModel] = cache_get_row_int(total, 1),
            OwnedVehicles[total][carColor1] = cache_get_row_int(total, 2),
            OwnedVehicles[total][carColor2] = cache_get_row_int(total, 3),
            OwnedVehicles[total][carParkX] = cache_get_row_float(total, 4),
            OwnedVehicles[total][carParkY] = cache_get_row_float(total, 5),
            OwnedVehicles[total][carParkZ] = cache_get_row_float(total, 6),
            OwnedVehicles[total][carParkA] = cache_get_row_float(total, 7),
            cache_get_row(total, 8, OwnedVehicles[total][carPlate], dbHandle, 128),
            cache_get_row(total, 9, OwnedVehicles[total][carOwner], dbHandle, 128),
            OwnedVehicles[total][carOwned] = cache_get_row_int(total, 10);
            OwnedVehicles[total][carSpawned] = 0;
            OwnedVehicles[total][carOn] = 1;
            total++;
        }
    }
    format(str,sizeof(str), "Loaded %d player owned vehicles from MySQL.", total);
    printf(str);
    return 1;
}
Now... if I want to check when player connects if he owns a vehicle by the ownername of the vehicle.
But the problem is when I do this:
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
{
  for(new z = 0; z < MAX_PLAYER_CARS; z++)
  {
    if(!strcmp(GetName(playerid), OwnedVehicles[i][carOwner], true))
    {
        PlayerVehicle[playerid][z] = i;
    }
  }
}
It doesn't works..


Re: MySQL owned vehicle system - Misiur - 11.03.2013

I have to admit that your method is quite nice (I'm using references via database ids held in fields).

However the nested loop looks ugly (max vehicles time max player cars might be a lot). Let's start with little debug:
Add this over if statement
pawn Код:
printf("Currently at %d/%d with values %s & %s", i, z, GetName(playerid), OwnedVehicles[i][carOwner]);



Re: MySQL owned vehicle system - Knappen - 11.03.2013

Do you save players to MySQL? If so, it's probably easier to store the vehicle id in their account if they own it, and then load it when they log on.