Load ID Car from MySQL
#6

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
In that case vehicle ID 1 wont be loaded. Because row index starts from 0. Means you'll have a car missing.


Show me the code how you create the vehicle.
Код:
enum cInfo
{
	ORM:ORM_ID,
	ID,
	Owner[MAX_PLAYER_NAME],
	Locked,
	Float:Vposx,
	Float:Vposy,
	Float:Vposz,
	Float:Vposa,
	Model,
	Color1,
	Color2,
	CarID,
	Fuel
};
new CarInfo[MAX_VEHICLES][cInfo];

new c_h = -1;

OnGameModeInit:
mysql_tquery(g_SQL, "SELECT * FROM `vehicles`", "OnVehiclesLoad", "");

forward OnVehiclesLoad();
public OnVehiclesLoad()
{
    new time = GetTickCount();
	for(new c=0; c < cache_num_rows(); ++c) {
		new ORM:ormid = CarInfo[c][ORM_ID] = orm_create("vehicles");
		orm_addvar_int(ormid, CarInfo[c][ID], "ID");
		orm_setkey(ormid, "ID");
		orm_addvar_string(ormid, CarInfo[c][Owner], MAX_PLAYER_NAME, "Owner");
		orm_addvar_int(ormid, CarInfo[c][Locked], "Locked");
		orm_addvar_float(ormid, CarInfo[c][Vposx], "Vposx");
		orm_addvar_float(ormid, CarInfo[c][Vposy], "Vposy");
		orm_addvar_float(ormid, CarInfo[c][Vposz], "Vposz");
		orm_addvar_float(ormid, CarInfo[c][Vposa], "Vposa");
		orm_addvar_int(ormid, CarInfo[c][Model], "Model");
		orm_addvar_int(ormid, CarInfo[c][Color1], "Color1");
		orm_addvar_int(ormid, CarInfo[c][Color2], "Color2");
		orm_addvar_int(ormid, CarInfo[c][Fuel], "Fuel");
		orm_apply_cache(ormid, c);
		c_h = c;
	        c_h++;
		CarInfo[c][CarID] = CreateVehicle(CarInfo[c][Model], CarInfo[c][Vposx], CarInfo[c][Vposy], CarInfo[c][Vposz], CarInfo[c][Vposa], CarInfo[c][Color1], CarInfo[c][Color2], -1);
		VFuel[c] = CarInfo[c][Fuel];
	}
	printf("%d personal cars loaded with %d ms",c_h,GetTickCount() - time);
	return 1;
}

OnPlayerStateChange:
if(newstate == PLAYER_STATE_DRIVER)
    {
        
	    for(new c=0; c<=c_h; c++)
	    {
	        PlayerInfo[playerid][pCarID] = c;
	    }
    }

CMD:carid(playerid, params[])
{
	SendMes(playerid, 0x131313, "{FFFFFF}%d",PlayerInfo[playerid][pCarID]);
	return 1;
}
if i use command "s",the car is not save
Код:
CMD:s(playerid, params[])
{
    CarInfo[PlayerInfo[playerid][pCarID]][Locked] = 20;
    orm_save(CarInfo[PlayerInfo[playerid][pCarID]][ORM_ID]);
	return 1;
}
Reply


Messages In This Thread
Load ID Car from MySQL - by iulicxd - 28.07.2015, 09:41
Re: Load ID Car from MySQL - by PizzaPuntjes - 28.07.2015, 10:27
Re: Load ID Car from MySQL - by iulicxd - 28.07.2015, 10:39
Re: Load ID Car from MySQL - by iulicxd - 29.07.2015, 09:12
Re: Load ID Car from MySQL - by DaniceMcHarley - 29.07.2015, 09:51
Re: Load ID Car from MySQL - by iulicxd - 29.07.2015, 10:02

Forum Jump:


Users browsing this thread: 1 Guest(s)