new Menu:Vehicles;
forward CreateVehicleMenu();
CreateVehicleMenu();
if(Current == Vehicles)// Vehicle Ownership System { switch(row) { case 0: // Comet { if(PlayerInfo[playerid][pCash] < 10000) { SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: You don't have enough cash to buy a Comet."); return 1; } if(PlayerInfo[playerid][pVeh] > 0 && PlayerInfo[playerid][pVeh2] > 0) { SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: You already own two vehicles, please sell one first."); return 1; } new Float:X,Float:Y,Float:Z; GetPlayerPos(playerid, X,Y,Z); new carid = CreateVehicle(480, X,Y,Z, 0.0, 0, 0, 360000); new sendername[MAX_PLAYER_NAME]; GetPlayerName(playerid, sendername, sizeof(sendername)); CreatedCars[CreatedCar] = carid; CreatedCar ++; SafeGivePlayerMoney(playerid, -10000); DateProp(playerid); OnPropUpdate(); OnPlayerUpdate(playerid); SaveVehicle(); SendClientMessage(playerid, COLOR_YELLOW, "You have bought a Comet for Ј10000."); SendClientMessage(playerid, COLOR_GREEN, "HINT: Use /vehiclehelp. You will have to /park it somewhere, otherwise you'll lose it."); HideMenuForPlayer(Vehicles, playerid); TogglePlayerControllable(playerid,1); CarInfo[carid][cOwned] = 1; CarInfo[carid][cModel] = 480; strmid(CarInfo[carid][cOwner], sendername, 0, strlen(sendername), 999); if(PlayerInfo[playerid][pVeh] > 0) { PlayerInfo[playerid][pVeh2] = carid; } if(PlayerInfo[playerid][pVeh2] > 0) { PlayerInfo[playerid][pVeh] = carid; } if(PlayerInfo[playerid][pVeh] == 0 && PlayerInfo[playerid][pVeh2] == 0) { PlayerInfo[playerid][pVeh] = carid; } } case 1: { HideMenuForPlayer(Vehicles, playerid); TogglePlayerControllable(playerid,1); } case 2: { HideMenuForPlayer(Vehicles, playerid); TogglePlayerControllable(playerid,1); } case 3: { HideMenuForPlayer(Vehicles, playerid); TogglePlayerControllable(playerid,1); } case 4: { HideMenuForPlayer(Vehicles, playerid); TogglePlayerControllable(playerid,1); } case 5: { HideMenuForPlayer(Guide, playerid); TogglePlayerControllable(playerid,1); } } }
public CreateVehicleMenu() // Vehicle Ownership System { Vehicles = CreateMenu("Vehicles", 1, 50.0, 180.0, 200.0, 200.0); AddMenuItem(Vehicles, 0, "Comet $10000"); AddMenuItem(Vehicles, 0, ".."); AddMenuItem(Vehicles, 0, ".."); AddMenuItem(Vehicles, 0, ".."); AddMenuItem(Vehicles, 0, ".."); AddMenuItem(Vehicles, 0, "- Exit -"); }
forward LoadVehicle(); forward SaveVehicle();
public LoadVehicle() { new arrCoords[9][64]; new strFromFile2[256]; new File: file = fopen("cfg/vehicles.cfg", io_read); if (file) { new idx = 1; while (idx < sizeof(CarInfo)) { fread(file, strFromFile2); split(strFromFile2, arrCoords, ','); CarInfo[idx][cModel] = strval(arrCoords[0]); CarInfo[idx][cLocationx] = floatstr(arrCoords[1]); CarInfo[idx][cLocationy] = floatstr(arrCoords[2]); CarInfo[idx][cLocationz] = floatstr(arrCoords[3]); CarInfo[idx][cAngle] = floatstr(arrCoords[4]); CarInfo[idx][cColorOne] = strval(arrCoords[5]); CarInfo[idx][cColorTwo] = strval(arrCoords[6]); CarInfo[idx][cOwned] = strval(arrCoords[7]); CarInfo[idx][cOwner] = strval(arrCoords[8]); idx++; } } return 1; } public SaveVehicle() { new idx; new File: file2; while (idx < sizeof(CarInfo)) { new coordsstring[256]; format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d\n", CarInfo[idx][cModel], CarInfo[idx][cLocationx], CarInfo[idx][cLocationy], CarInfo[idx][cLocationz], CarInfo[idx][cAngle], CarInfo[idx][cColorOne], CarInfo[idx][cColorTwo], CarInfo[idx][cOwned], CarInfo[idx][cOwner]); if(idx == 0) { file2 = fopen("cfg/vehicles.cfg", io_write); } else { file2 = fopen("cfg/vehicles.cfg", io_append); } fwrite(file2, coordsstring); idx++; fclose(file2); } return 1; }
enum cInfo { cModel, Float:cLocationx, Float:cLocationy, Float:cLocationz, Float:cAngle, cColorOne, cColorTwo, cOwner[MAX_PLAYER_NAME], cOwned, };
new CarInfo[9][cInfo];
if(strcmp(cmd, "/park", true) == 0) { new Float:x,Float:y,Float:z; new Float:a; new carid; new getcarid; if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh]) { carid = PlayerInfo[playerid][pVeh]; } else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh2]) { carid = PlayerInfo[playerid][pVeh2]; } else { return 1; } getcarid = GetPlayerVehicleID(playerid); GetPlayerName(playerid, playername, sizeof(playername)); GetVehiclePos(carid, x, y, z); //GetPlayerFacingAngle(playerid, a); GetVehicleZAngle(carid, a); if(IsPlayerInVehicle(playerid,carid) && CarInfo[carid][cOwned] == 1) { if(PlayerInfo[playerid][pVeh] == 0 && PlayerInfo[playerid][pVeh2] == 0) { SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: You don't own a vehicle."); return 1; } if(getcarid == carid) { CarInfo[carid][cLocationx] = x; CarInfo[carid][cLocationy] = y; CarInfo[carid][cLocationz] = z; CarInfo[carid][cAngle] = a; SendClientMessage(playerid, COLOR_YELLOW, "You have parked your vehicle in this position, it will now respawn here."); OnPlayerUpdate(playerid); DestroyVehicle(carid); CreateVehicle(CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz]+0.5,CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo],180000); SaveVehicle(); OnPropUpdate(); TogglePlayerControllable(playerid, 1); return 1; } } }
for(new h = 1; h < sizeof(CarInfo); h++) { AddStaticVehicleEx(CarInfo[h][cModel],CarInfo[h][cLocationx],CarInfo[h][cLocationy],CarInfo[h][cLocationz]+0.5,CarInfo[h][cAngle],CarInfo[h][cColorOne],CarInfo[h][cColorTwo],180000); }
idx = 1; while (idx < sizeof(CarInfo)) { new coordsstring[256]; format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%d,\n", CarInfo[idx][cModel],// CarInfo[idx][cLocationx],// CarInfo[idx][cLocationy],// CarInfo[idx][cLocationz],// CarInfo[idx][cAngle],// CarInfo[idx][cColorOne],// CarInfo[idx][cColorTwo],// CarInfo[idx][cOwner],// CarInfo[idx][cOwned]); if(idx == 184) { file2 = fopen("cfg/vehicles.cfg", io_write); } else { file2 = fopen("cfg/vehicles.cfg", io_append); } fwrite(file2, coordsstring); idx++; fclose(file2); }
OnPropUpdate()
Originally Posted by tour15
Yeah i using GF car ownership... But vehicles spawned with /veh wont save
|