13.04.2010, 06:40
Hello, I have designed my own car ownership where you can select a car from the menu, then it spawns the car you select. Trouble is, it doesn't write to the file when a car is bought or /parked. Here is what I have:
^ Under OnGameModeInit
This is the menu when someone uses /buyveh, at the moment I only added the Comet. It all works fine, the car spawns and that, it just doesn't write it to the vehicles.cfg file.
All these are in the right place on the gamemode.
Right, when I use /park it doesn't write to vehicles.cfg, just like it doesn't when I use /buyveh and buy a car from the menu.
This is the /park command I have.
I also added this under the AddStaticVehicleEx list I already have.
And this is under an
I have in the script, I know the brackets don't seem enough but that's because it's added with the houses and business scripts.
Like I said, I want it to save to the vehicles.cfg file when I use /buycar and I want it to save the vehicle when I restart the gamemode after using /park but it doesn't.
If anyone could help, thank you so much.
Код:
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()
Like I said, I want it to save to the vehicles.cfg file when I use /buycar and I want it to save the vehicle when I restart the gamemode after using /park but it doesn't.
If anyone could help, thank you so much.