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; }
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. |
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]); } |
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);
}
Still need help!
I tryed some methods, but its not working. This is my code. |