Transition Problems
#1

Hello..
I'm using code, that does like this: You need house to buy car, if you buy house it creates " House " file under ServerData. And if you buy a vehicle in same house, it add's also car data under the same file.
Now trying to move my server car list to higher prices. I want to create a little code that adds to that " House " file a little line like " carvalue ". And when player wants to sell his car, server take value from that file and sells it.
My English is bad, but I hope some of you understood me..

This is the file called " Housing.inc " and in there is " House_AddVehicle " that should add bought car to house.
Код:
House_AddVehicle(HouseID, cModel, cPaint, cComponents[], Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2)
{
	// Setup local variables
	new vid, CarSlot;

	// Get a free carslot from the house
	CarSlot = House_GetFreeCarSlot(HouseID);

	// Check if there is a free carslot
	if (CarSlot != -1)
	{
		// Create a new vehicle and get the vehicle-id
		vid = CreateVehicle(cModel, cx, cy, cz, crot, Col1, Col2, 600);
		// Store the vehicle-id in the house's free carslot
		AHouseData[HouseID][VehicleIDs][CarSlot] = vid;

		// Save the model of the vehicle
		AVehicleData[vid][Model] = cModel;
		// Save the paintjob of the vehicle and apply it
		AVehicleData[vid][PaintJob] = cPaint;
		if (cPaint != 0)
			ChangeVehiclePaintjob(vid, cPaint - 1);

		mhind = AVehicleData[vid][Price];
		
		// Also update the car-color
		ChangeVehicleColor(vid, Col1, Col2);
		// Save the colors of the vehicle
		AVehicleData[vid][Color1] = Col1;
		AVehicleData[vid][Color2] = Col2;

		// Save the components of the vehicle and apply them
		for (new i; i < 14; i++)
		{
			AVehicleData[vid][Components][i] = cComponents[i];
		    // Check if the componentslot has a valid component-id
			if (AVehicleData[vid][Components][i] != 0)
		        AddVehicleComponent(vid, AVehicleData[vid][Components][i]); // Add the component to the vehicle
		}

		// Save the spawn-data of the vehicle
        AVehicleData[vid][SpawnX] = cx;
        AVehicleData[vid][SpawnY] = cy;
        AVehicleData[vid][SpawnZ] = cz;
        AVehicleData[vid][SpawnRot] = crot;
		// Also set the fuel to maximum
		AVehicleData[vid][Fuel] = MaxFuel;
		// Also set the owner
		AVehicleData[vid][Owned] = true;
		format(AVehicleData[vid][Owner], 24, AHouseData[HouseID][Owner]);
		// Save the HouseID for the vehicle
		AVehicleData[vid][BelongsToHouse] = HouseID;
	}
	else // No free carslot was found, return 0
		return 0;

	// Exit the function and return the vehicle-id
	return vid;
}
I tried to add there line " ABuyableVehicles[vid][Price] = mhind ". So mhind would = vehicle price.

The file it should take the price is called " DefBuyableVehicles.inc " and looks about like that:
Код:
#define VClassBike          1
#define VClassBoat          2
#define VClassConvertible   3
#define VClassHelicopter    4
#define VClassIndustrial    5
#define VClassLowRider      6
#define VClassOffRoad       7
#define VClassPlane         8
#define VClassPublic        9
#define VClassRCVehicle     10
#define VClassSaloons       11
#define VClassSportCar      12
#define VClassStationCar    13
#define VClassTrailer       14
#define VClassUnique        15

enum TBuyableVehicle
{
	CarName[50], // Holds the name of the vehicle
	VehicleClass, // Holds the ID of the vehicleclass
	CarModel, // Holds the model-ID of the vehicle
	Price // Holds the price for the vehicle (renting it will be 10% of this price)
}

new ABuyableVehicles[][TBuyableVehicle] =
{
	{"Admiral", VClassSaloons, 445, 150000},
	{"Alpha", VClassSportCar, 602, 150000},
	{"Ambulance", VClassPublic, 416, 150000},
	{"Andromada", VClassPlane, 592, 150000},

and so on... Finally:

	{"Yosemite", VClassIndustrial, 554, 1150000},
	{"ZR-350", VClassSportCar, 477, 1150000}
};



// This function searches the ABuyableVehicles array to search for the model and returns the index in the array
VehicleBuyable_GetIndex(vModel)
{
	// Loop through all vehicles in the ABuyableVehicles array
	for (new i; i < sizeof(ABuyableVehicles); i++)
	{
	    // Check if the model of the current vehicle is the same as the given model
		if (ABuyableVehicles[i][CarModel] == vModel)
		    return i; // Return the index of the array where the carmodel was found
	}

	return -1;
}
Then there is a file " FileOperations.inc " which like I understand Saves the data about cars and things into the file:
Код:
HouseFile_Save(HouseID)
{
	new file[100], File:HFile, LineForFile[100], vid;

    // Construct the complete filename for this house
	format(file, sizeof(file), HouseFile, HouseID);

	HFile = fopen(file, io_write); // Open the playerfile for writing

	format(LineForFile, 100, "HouseName %s\r\n", AHouseData[HouseID][HouseName]); // Construct the line: "HouseName <HouseName>"
	fwrite(HFile, LineForFile); // And save it to the file
	// Save the vehicle-data for every vehicle added to the house
	for (new CarSlot; CarSlot < 10; CarSlot++)
	{
	    // If a valid vehicle-id has been found
		if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
		{
			// Get the vehicle id
			vid = AHouseData[HouseID][VehicleIDs][CarSlot];

		    format(LineForFile, 100, "[Vehicle]\r\n"); // Construct the line: "[Vehicle]"
			fwrite(HFile, LineForFile); // And save it to the file

		    format(LineForFile, 100, "VehicleModel %i\r\n", AVehicleData[vid][Model]); // Construct the line: "VehicleModel <VehicleModel>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "Fuel %i\r\n", AVehicleData[vid][Fuel]); // Construct the line: "Fuel <Fuel>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehiclePaintJob %i\r\n", AVehicleData[vid][PaintJob]); // Construct the line: "VehiclePaintJob <VehiclePaintJob>"
			fwrite(HFile, LineForFile); // And save it to the file

		    format(LineForFile, 100, "VehicleSpoiler %i\r\n", AVehicleData[vid][Components][0]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleHood %i\r\n", AVehicleData[vid][Components][1]); // Construct the line: "VehicleHood <VehicleHood>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleRoof %i\r\n", AVehicleData[vid][Components][2]); // Construct the line: "VehicleRoof <VehicleRoof>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleSideSkirt %i\r\n", AVehicleData[vid][Components][3]); // Construct the line: "VehicleSideSkirt <VehicleSideSkirt>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleLamps %i\r\n", AVehicleData[vid][Components][4]); // Construct the line: "VehicleLamps <VehicleLamps>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleNitro %i\r\n", AVehicleData[vid][Components][5]); // Construct the line: "VehicleNitro <VehicleNitro>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleExhaust %i\r\n", AVehicleData[vid][Components][6]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleWheels %i\r\n", AVehicleData[vid][Components][7]); // Construct the line: "VehicleWheels <VehicleWheels>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleStereo %i\r\n", AVehicleData[vid][Components][8]); // Construct the line: "VehicleStereo <VehicleStereo>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleHydraulics %i\r\n", AVehicleData[vid][Components][9]); // Construct the line: "VehicleHydraulics <VehicleHydraulics>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleFrontBumper %i\r\n", AVehicleData[vid][Components][10]); // Construct the line: "VehicleFrontBumper <VehicleFrontBumper>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleRearBumper %i\r\n", AVehicleData[vid][Components][11]); // Construct the line: "VehicleRearBumper <VehicleRearBumper>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleVentRight %i\r\n", AVehicleData[vid][Components][12]); // Construct the line: "VehicleVentRight <VehicleVentRight>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleVentLeft %i\r\n", AVehicleData[vid][Components][13]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
			fwrite(HFile, LineForFile); // And save it to the file

		    format(LineForFile, 100, "Color1 %i\r\n", AVehicleData[vid][Color1]); // Construct the line: "Color1 <Color1>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "Color2 %i\r\n", AVehicleData[vid][Color2]); // Construct the line: "Color2 <Color2>"
			fwrite(HFile, LineForFile); // And save it to the file

		    format(LineForFile, 100, "VehicleX %f\r\n", AVehicleData[vid][SpawnX]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleY %f\r\n", AVehicleData[vid][SpawnY]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleZ %f\r\n", AVehicleData[vid][SpawnZ]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
			fwrite(HFile, LineForFile); // And save it to the file
		    format(LineForFile, 100, "VehicleAngle %f\r\n", AVehicleData[vid][SpawnRot]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
			fwrite(HFile, LineForFile); // And save it to the file

			if (AVehicleData[vid][Clamped] == true)
			    format(LineForFile, 100, "Clamped Yes\r\n"); // Construct the line: "Clamped <Yes>"
			else
			    format(LineForFile, 100, "Clamped No\r\n"); // Construct the line: "Clamped <No>"

			fwrite(HFile, LineForFile); // And save it to the file

		    format(LineForFile, 100, "[/Vehicle]\r\n"); // Construct the line: "[/Vehicle]"
			fwrite(HFile, LineForFile); // And save it to the file
		}
	}

	fclose(HFile); // Close the file

	return 1;
}
If anyone could help or give tip.. I would be very glad.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)