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
#2

I suppose you add a new variable, "Locked" for example.

When you load the cars, set the locked parameter of the vehicle to 1 or 0 depending on if the car is locked or not.
Reply
#3

Quote:
Originally Posted by BigGroter
Посмотреть сообщение
I suppose you add a new variable, "Locked" for example.

When you load the cars, set the locked parameter of the vehicle to 1 or 0 depending on if the car is locked or not.
Umm. Ok. But where I've to check if someone is trying to enter my car and it is locked?
Reply
#4

Still need help!
I tryed some methods, but its not working.
Quote:

new pName[MAX_PLAYER_NAME];
new id = GetPlayeridMid(pName);
GetPlayerName(id, pName, sizeof(pName));

if(vehicleid == Car[id][VehId])
{
if(Car[id][Locked] >= 1)
{
Stop(playerid);
SendClientMessage(playerid, COLOR_RED, "Car is locked.");
}
}


stock Stop(playerid){
new Float:coo[3];
GetPlayerPos(playerid,coo[0],coo[1],coo[2]);
SetPlayerPos(playerid,coo[0],coo[1],coo[2]);
}

This is my code.
Reply
#5

You could always use a system like this, and when the player locks the vehicle just lock the car (doors are the locks), and when you spawn the vehicle (when you load them) change the variables too.

pawn Код:
forward Encode_Vehicle(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
public Encode_Vehicle(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective)
{
    SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
}
Reply
#6

Quote:
Originally Posted by Delgad0
Посмотреть сообщение
Still need help!
I tryed some methods, but its not working.


This is my code.
When I talk about changing the vehicle params, I mean what the user above posted.

https://sampwiki.blast.hk/wiki/SetVehicleParamsEx

If the locked variable is true, lock the car with the code above.
Reply
#7

Ok, thanks! But what if owner wants to enter the car, and its locked? I've always unlock before entering the car, and when I enter the car I've to lock it. Is it possible to make, that if car wants to enter owner, he dont need to unlock it(if its locked).
Sorry for my little bad English, I hope so you understand me.
Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)