Help with Car system -
Mystique - 08.08.2010
Allright so I made a car system and everything worked fine until I wanted to modify it so that it's not the name that's saved into the carsystem file on carowner. Instead I wanted to make that it saves the carid into a variable called PlayerInfo[playerid][vKey1] also a vkey2. This is because people should be able to change names. Now I realized that if I buy a vehicle (spawns when clicking on a dialog), then spawn another vehicle with /vcreate that I had before and then spawn another one with the dialog buy buying it. Now if I delete the car that I created with /vcreate and restart the server, then second cars ID is degraded by 1 which means the players doesn't own that vehicle anymore. Now I need suggestions on how I actually can fix this so that it won't bug everytime when people are doing /vscrap or anything. Any suggestions are welcome.
Re: Help with Car system -
Carlton - 08.08.2010
I'm pretty sure you're assigning variables to a returned CreateVehicle, so when it deletes the variables will messup, or am I mistaken?
Re: Help with Car system -
Mystique - 08.08.2010
Yes, I bought vehicle ID 40, spawned vehicle 41 and bought vehicle 42. Then I deleted 41, restarted and then the 42 was suddenly vehicle ID 41. So, do you have any suggestions?
Re: Help with Car system -
Carlton - 08.08.2010
Quote:
Originally Posted by Mystique
Yes, I bought vehicle ID 40, spawned vehicle 41 and bought vehicle 42. Then I deleted 41, restarted and then the 42 was suddenly vehicle ID 41. So, do you have any suggestions?
|
How are you storing your vehicle data, maybe you can use a auto-incremented ID from where you're loading it from and using it as the vehicleID.
Re: Help with Car system -
Mystique - 08.08.2010
I'm storing the vehicle ID into a PlayerInfo[playerid][vKey1] variable and then when you enter it checks if the vehicle ID of that vehicle is the same. Rest of the vehicle info is saved into a .cfg file.
Re: Help with Car system -
Carlton - 08.08.2010
Ehm, i'm not to good with files honestly. I'm sure you're using two dimesion arrays for the vehicle stats. When loading those, use a new variable that's supposed to be the vehicle ID. Ehm, this is an example:
pawn Код:
enum vdata {
vModel,
vPos[3],
etc..
vVehicleID // This is the vehicleID variable i'm talking about.
}
// My vehicle loadscript
VehicleInfo[MyCurrentLoadingVehicleID][vVehicleID] = MyCurrentLoadingVehicleID;
Then later when the account loads.
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++ ) {
if(PlayerInfo[playerid][vKey1] == VehicleInfo[i][vVehicleID]) {
}
}
Or something like the example code above.
Re: Help with Car system -
Mystique - 08.08.2010
Yeah, I was actually thinking about creating something similar to that. I just need to make that when a player buys a vehicle it sets a global variable up by one step so that the vehicles doesn't mess up and become the same ID ,am I right? Also, I'm using this MAX_CARS thing and not MAX_VEHICLES but I'm using GetPlayerVehicleID(playerid) so that's the problem am I right? It counts with the MAX_VEHICLES, not MAX_CARS.
Re: Help with Car system -
Carlton - 08.08.2010
Quote:
Originally Posted by Mystique
Yeah, I was actually thinking about creating something similar to that. I just need to make that when a player buys a vehicle it sets a global variable up by one step so that the vehicles doesn't mess up and become the same ID ,am I right? Also, I'm using this MAX_CARS thing and not MAX_VEHICLES but I'm using GetPlayerVehicleID(playerid) so that's the problem am I right? It counts with the MAX_VEHICLES, not MAX_CARS.
|
GetPlayerVehicleID(playerid) is most likely the problem, you will have to create a function getting the variable stored vehicleID.
Re: Help with Car system -
Mystique - 08.08.2010
I don't really understand at the moment. So you mean that when a player buys a vehicle the MAX_VEHICLES ID is stored into a variable. And then I have to check it with another fuction if the variable ID is the same as the vKey1. Well what happens if I delete several vehicles so that the MAX_VEHICLES is degraded by a few steps. If a player buys a vehicle then it can become the same as any other vehicle's ID. Got any suggestion on fixing that?