Load ID Car from MySQL
#1

OnPlayerEnterVehicle:
Код:
for(new c=0;c<=c_h;c++)
{
PlayerInfo[playerid][pCarID] = c;
}
When i enter in car,the server give me id 2,but car have id 1 (Mysql)

Example System house:
Код:
OnPlayerPickupPickup:
for(new h = 0; h <= m_h; h++)
{
IsPlayerInRangeOfPoint(playerid,HomeInfo[h][Entryx],HomeInfo[h][Entryy]
,HomeInfo[h][Entryz],2.0);
{
PlayerInfo[playerid][HID] = h;
}
}
System house:Server give me correctly id of house.

System personal vehicle:
The system is working good,
but i can't get car id from mysql in game

System is based on Mysql (ORM)
Sorry for my bad english)
Reply
#2

Cars never have ID 0, they start at 1. Just make sure when loading the cars from your database that id 0 won't be spawned.
Reply
#3

Quote:
Originally Posted by PizzaPuntjes
Посмотреть сообщение
Cars never have ID 0, they start at 1. Just make sure when loading the cars from your database that id 0 won't be spawned.
Код:
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("autosalons");
		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 Loaded Cars with %d ms",c_h,GetTickCount() - time);
	return 1;
}
if i delete c_h++;
the server give me id 1
I think,when i enter in vehicle
there are no check which is id

I create 2 cars
1)With id 1
2)With id 3

How i check the car id?
Код:
CMD:carid(playerid, params[])
{
	SendMes(playerid, 0x131313, "{FFFFFF}%d",PlayerInfo[playerid][pCarID]);
	return 1;
}
Reply
#4

UP !
Reply
#5

Quote:
Originally Posted by PizzaPuntjes
Посмотреть сообщение
Cars never have ID 0, they start at 1. Just make sure when loading the cars from your database that id 0 won't be spawned.
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.
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)