MySQL car system
#1

Hello again. Today I tryed to make MySQL car system. Actualy I made that system. There is a code:
Код HTML:
enum cInfo {
Id,
Owner[MAX_PLAYER_NAME],
Model,
Float:X,
Float:Y,
Float:Z,
Float:Angle,
Color,
Color,
VehId
};
new Car[MAX_PLAYERS][cInfo];

stock LoadcInfo(playerid)
{
    	new name[MAX_PLAYER_NAME],query[254];
	GetPlayerName(playerid,name,sizeof(name));
	mysql_real_escape_string(name,name);
	format(query,sizeof(query),"SELECT * FROM cars WHERE Owner = '%s'",name);
	mysql_function_query(dbhandle,query,true,"LoadCars","i",playerid);
	return 1;
}

forward LoadCars(playerid);
public LoadCars(playerid)
{
	new rows,fields;
	cache_get_data(rows,fields); 
	if(rows == 1) 
	{
	    new tmp[64];
		
		cache_get_row(0,0,tmp); Car[playerid][Id] = strval(tmp);
		cache_get_row(0,1, Car[playerid][Owner]);
		cache_get_row(0,2,tmp); Car[playerid][Model] = strval(tmp);
		cache_get_row(0,3,tmp); Car[playerid][X] = floatstr(tmp);
		cache_get_row(0,4,tmp); Car[playerid][Y] = floatstr(tmp);
		cache_get_row(0,5,tmp); Car[playerid][Z] = floatstr(tmp);
		cache_get_row(0,6,tmp); Car[playerid][Angle] = floatstr(tmp);
		cache_get_row(0,7,tmp); Car[playerid][Color] = strval(tmp);
		cache_get_row(0,8,tmp); Car[playerid][Color2] = strval(tmp);
		Car[playerid][VehId] = CreateVehicle(Car[playerid][Model],Car[playerid][X],Car[playerid][Y],Car[playerid][Z],Car[playerid][Angle],Car[playerid][Color],Car[playerid][Color2],-1);

	}
 	else Car[playerid][VehId] = INVALID_VEHICLE_ID;
	mysql_free_result();
	return 1;
}

stock SaveCars(playerid)
{
	new query[128];
	if(Car[playerid][VehId] == INVALID_VEHICLE_ID) return 1;
	new Float:pos[3];
	GetVehicleZAngle(Car[playerid][VehId], Car[playerid][Angle]);
	GetVehiclePos(Car[playerid][VehId],pos[0],pos[1],pos[2]);
	format(query,sizeof(query),"UPDATE cars SET PosX=%f,PosY=%f,PosZ=%f,Angle=%f WHERE Id=%d", pos[0],pos[1],pos[2],Car[playerid][Angle],Car[playerid][Id]);
	mysql_function_query(dbhandle,query,false,"","");
	DestroyVehicle(Car[playerid][VehId]);
	return 1;
}
First of all, what do you think, is it good system?
And I want to make a lock system, but I dont know how to make it. Can someone help me?
Thanks a lot!
Reply


Messages In This Thread
MySQL car system - by Delgad0 - 21.11.2014, 16:16
Re: MySQL car system - by BigGroter - 21.11.2014, 16:30
Re: MySQL car system - by Delgad0 - 21.11.2014, 16:35
Re: MySQL car system - by Delgad0 - 21.11.2014, 19:00
Re: MySQL car system - by zT KiNgKoNg - 21.11.2014, 19:14
Re: MySQL car system - by BigGroter - 21.11.2014, 23:14
Re: MySQL car system - by Delgad0 - 22.11.2014, 07:19

Forum Jump:


Users browsing this thread: 1 Guest(s)