SA-MP Forums Archive
[MYSQL] - Load veh - 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] - Load veh (/showthread.php?tid=610614)



[MYSQL] - Load veh - Maximun - 26.06.2016

Well, I'm trying to load vehicles with the code below but it's not working, it seeming to me all is correct

Код:
public OnGameModeInit()
{
	mysql_function_query(g_iHandle, "SELECT * FROM `srv_cars`", true, "LoadCarSystem", "");
}
Код:
public LoadCarSystem()
{
	static
	    rows,
	    fields,
		str[128];

	cache_get_data(rows, fields, g_iHandle);

	for (new i = 0; i < rows; i ++) if (i < MAX_VEHICLES)
	{
	    CarSystem[i][cCarID] = cache_get_field_int(i, "CarID");
	    CarSystem[i][cModel] = cache_get_field_int(i, "Model");
		CarSystem[i][cEssence] = cache_get_field_int(i, "Essence");
        cache_get_row(i, 1, CarSystem[i][cX], g_iHandle, 128 );
        cache_get_row(i, 1, CarSystem[i][cY], g_iHandle, 128 );
        cache_get_row(i, 1, CarSystem[i][cZ], g_iHandle, 128 );
		cache_get_row(i, 1, CarSystem[i][cAngle], g_iHandle, 128 );
        CarSystem[i][cColor1] = cache_get_field_int(i, "Color1");
       	CarSystem[i][cColor2] = cache_get_field_int(i, "Color2");
       	CarSystem[i][cKM] = cache_get_field_int(i, "KM");
       	CarSystem[i][cObjective] = cache_get_field_int(i, "Objective");
       	CarSystem[i][cDoorsLocked] = cache_get_field_int(i, "DoorsLocked");
       	CarSystem[i][cVehicleType] = cache_get_field_int(i, "VehicleType");
        cache_get_field_content(i, "Plaque", CarSystem[i][cPlaque], g_iHandle, 32);
   	    CarSystem[i][cVehicleMaterials] = cache_get_field_int(i, "VehicleMaterials");
   	    CarSystem[i][cVehicleCrack] = cache_get_field_int(i, "VehicleCrack");
   	    CarSystem[i][cVehiclePot] = cache_get_field_int(i, "VehiclePot");
   	    CarSystem[i][cJantes] = cache_get_field_int(i, "Jantes");
   	    CarSystem[i][cMetre] = cache_get_field_int(i, "Metre");
   	    CarSystem[i][cVehicleHealth] = cache_get_field_int(i, "VehicleHealth");
    	CarSystem[i][cVehicleAlarm] = cache_get_field_int(i, "VehicleAlarm");
	    CarSystem[i][cVehicleOwned] = cache_get_field_int(i, "VehicleOwned");
	    CarSystem[i][cDescription] = cache_get_field_int(i, "Description");
	    cache_get_field_content(i, "Owner", CarSystem[i][cOwner], g_iHandle, 32);
     	CarSystem[i][cNitro] = cache_get_field_int(i, "Nitro");
	    CarSystem[i][cPaintJob] = cache_get_field_int(i, "PaintJob");
	    CarSystem[i][cLoad] = cache_get_field_int(i, "Load");
	    CarSystem[i][cVehINT] = cache_get_field_int(i, "VehINT");
	    CarSystem[i][cVehWorld] = cache_get_field_int(i, "VehWorld");
	    CarSystem[i][cHydro] = cache_get_field_int(i, "Hydro");
	    CarSystem[i][cPimped] = cache_get_field_int(i, "Pimped");
	    CarSystem[i][cPerma] = cache_get_field_int(i, "Perma");
	    CarSystem[i][cRank] = cache_get_field_int(i, "Rank");
	    CarSystem[i][cPrice] = cache_get_field_int(i, "Price");
	    CarSystem[i][cSpoiler] = cache_get_field_int(i, "Spoiler");
	    CarSystem[i][cFbumper] = cache_get_field_int(i, "Fbumper");
	    CarSystem[i][cRbumper] = cache_get_field_int(i, "Rbumper");
	    SetVehicleHealth(i,CarSystem[i][cVehicleHealth]);
	    ChangeVehicleColor(i,CarSystem[i][cColor1], CarSystem[i][cColor2]);
	    ChangeVehiclePaintjob(i,CarSystem[i][cPaintJob]);
	    SetVehicleNumberPlate(i,CarSystem[i][cPlaque]);
	    AddVehicleComponent(i,CarSystem[i][cJantes]);
     	CreateVehicle(CarSystem[i][cModel],CarSystem[i][cX],CarSystem[i][cY],CarSystem[i][cZ],CarSystem[i][cAngle],CarSystem[i][cColor1],CarSystem[i][cColor2], -1);

	}
        printf("Loading Vehicles");
	return 1;
}



Re: [MYSQL] - Load veh - SaltySandy - 26.06.2016

Any error codes? Please provide us with your log-file .


Re: [MYSQL] - Load veh - Maximun - 26.06.2016

No, there's no error
log-file :
[12:42:58] Number of vehicle models: 0
[12:42:58] Loading Vehicles (I don't know why it show after the number of vehicle ....)


Re: [MYSQL] - Load veh - Maximun - 26.06.2016

Please I need help ..


Re: [MYSQL] - Load veh - SyS - 26.06.2016

what is problem the values are not saving?


Re: [MYSQL] - Load veh - Maximun - 26.06.2016

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
what is problem the values are not saving?
Saving is working good, I have problem with loading, I have already vehicles in DataBase, but It doesn't load, If you want you can see the picture above

Number of vehicle models: 0

No loading ...


Re: [MYSQL] - Load veh - Konstantinos - 26.06.2016

Please be more detailed.

Is there any vehicle (from those in db) in-game?
Does the message "Loading Vehicles" appear in the console?
Is it because the number of vehicle models is 0? That's nothing to concern because you have to keep in mind that there's delay while selecting the data, retrieving the data using cache functions and creating the vehicles.


Re: [MYSQL] - Load veh - Maximun - 26.06.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Please be more detailed.

Is there any vehicle (from those in db) in-game?
Does the message "Loading Vehicles" appear in the console?
Is it because the number of vehicle models is 0? That's nothing to concern because you have to keep in mind that there's delay while selecting the data, retrieving the data using cache functions and creating the vehicles.
Q1 : Yes, please see the picture
Q2: Yes it appears
Q3: Yes this is one of the problem + vehicles spawn with incorrect position (please see the picture)

The problem is the vehicles spawn with incorrect position and the number of vehicle models is 0, so that's means is not correctly spawned


Re: [MYSQL] - Load veh - Konstantinos - 26.06.2016

pawn Код:
cache_get_row(i, 1, CarSystem[i][cX], g_iHandle, 128 );
cache_get_row(i, 1, CarSystem[i][cY], g_iHandle, 128 );
cache_get_row(i, 1, CarSystem[i][cZ], g_iHandle, 128 );
cache_get_row(i, 1, CarSystem[i][cAngle], g_iHandle, 128 );
Coordinates are floats but you stored them like they're strings and you don't use floatstr either. Use cache_get_field_float instead for those 4.


Re: [MYSQL] - Load veh - Maximun - 26.06.2016

Position is solved, but others values still not working ...

Код:
public LoadCarSystem()
{
	static
	    rows,
	    fields,
		str[128];
	cache_get_data(rows, fields, g_iHandle);

	for (new i = 0; i < rows; i ++) if (i < MAX_VEHICLES)
	{
	    CarSystem[i][cCarID] = cache_get_field_int(i, "CarID");
	    CarSystem[i][cModel] = cache_get_field_int(i, "Model");
		CarSystem[i][cEssence] = cache_get_field_int(i, "Essence");
        CarSystem[i][cX] = cache_get_field_float(i, "PosX");
        CarSystem[i][cY] = cache_get_field_float(i, "PosY");
        CarSystem[i][cZ] = cache_get_field_float(i, "PosZ");
        CarSystem[i][cAngle] = cache_get_field_float(i, "Angle");
        CarSystem[i][cColor1] = cache_get_field_int(i, "Color1");
       	CarSystem[i][cColor2] = cache_get_field_int(i, "Color2");
       	CarSystem[i][cKM] = cache_get_field_int(i, "KM");
       	CarSystem[i][cObjective] = cache_get_field_int(i, "Objective");
       	CarSystem[i][cDoorsLocked] = cache_get_field_int(i, "DoorsLocked");
       	CarSystem[i][cVehicleType] = cache_get_field_int(i, "VehicleType");
        cache_get_field_content(i, "Plaque", CarSystem[i][cPlaque], g_iHandle, 32);
   	    CarSystem[i][cVehicleMaterials] = cache_get_field_int(i, "VehicleMaterials");
   	    CarSystem[i][cVehicleCrack] = cache_get_field_int(i, "VehicleCrack");
   	    CarSystem[i][cVehiclePot] = cache_get_field_int(i, "VehiclePot");
   	    CarSystem[i][cJantes] = cache_get_field_int(i, "Jantes");
   	    CarSystem[i][cMetre] = cache_get_field_int(i, "Metre");
   	    CarSystem[i][cVehicleHealth] = cache_get_field_int(i, "VehicleHealth");
    	CarSystem[i][cVehicleAlarm] = cache_get_field_int(i, "VehicleAlarm");
	    CarSystem[i][cVehicleOwned] = cache_get_field_int(i, "VehicleOwned");
	    cache_get_field_content(i, "Description", CarSystem[i][cDescription], g_iHandle, 64);
	    cache_get_field_content(i, "Owner", CarSystem[i][cOwner], g_iHandle, 255);
     	CarSystem[i][cNitro] = cache_get_field_int(i, "Nitro");
	    CarSystem[i][cPaintJob] = cache_get_field_int(i, "PaintJob");
	    CarSystem[i][cLoad] = cache_get_field_int(i, "Load");
	    CarSystem[i][cVehINT] = cache_get_field_int(i, "VehINT");
	    CarSystem[i][cVehWorld] = cache_get_field_int(i, "VehWorld");
	    CarSystem[i][cHydro] = cache_get_field_int(i, "Hydro");
	    CarSystem[i][cPimped] = cache_get_field_int(i, "Pimped");
	    CarSystem[i][cPerma] = cache_get_field_int(i, "Perma");
	    CarSystem[i][cRank] = cache_get_field_int(i, "Rank");
	    CarSystem[i][cPrice] = cache_get_field_int(i, "Price");
	    CarSystem[i][cSpoiler] = cache_get_field_int(i, "Spoiler");
	    CarSystem[i][cFbumper] = cache_get_field_int(i, "Fbumper");
	    CarSystem[i][cRbumper] = cache_get_field_int(i, "Rbumper");
	    SetVehicleHealth(i,CarSystem[i][cVehicleHealth]);
	    ChangeVehicleColor(i,CarSystem[i][cColor1], CarSystem[i][cColor2]);
	    ChangeVehiclePaintjob(i,CarSystem[i][cPaintJob]);
	    SetVehicleNumberPlate(i,CarSystem[i][cPlaque]);
	    AddVehicleComponent(i,CarSystem[i][cJantes]);
     	CreateVehicle(CarSystem[i][cModel],CarSystem[i][cX],CarSystem[i][cY],CarSystem[i][cZ],CarSystem[i][cAngle],CarSystem[i][cColor1],CarSystem[i][cColor2], -1);
	}
	return 1;
}