20.03.2012, 12:38
Supose you have the following array:
You buy a car and save to the array the modelid:
Now you have PlayerCars[playerid][0] = modelof(vehicleid)
You go to the modshop and add a nitro to the car. Then save it's data to a file:
So now you have in "file.txt":
Now you buy two more cars and add some nitros to them, so they occuppy slot1 and slot2. You sell car in slot1 so now only slot0 and slot2 cotain some data.
"file.txt" now looks like this:
Now I try to create a menu to only show the cars i have:
This will show in the menu:
So, what's the problem?
The problem is that Landstalker corresponds to row 0 in the menu ( ok, no problem ), but Super Gt corresponds to slot 1 in the menu and slot 3
in PlayerCars.
If I select "Super Gt", im selecting a car that has no data stored for that slot inside the file, so nothing is loaded.
I need help figuring out how to list only the cars i have inside a menu and when I selected them to correctly load the data stored in the file.
I don't know i explained myself well.
pawn Код:
PlayerCars[MAX_PLAYERS][4] = { 0,0,0,0 };
pawn Код:
for( new i; i<sizeof(PlayerCars[]); i++)
{
if( PlayerCars[playerid][i] < 400 ) // Slot is empty
PlayerCars[playerid][i] = GetVehicleModel( vehicleid );
}
You go to the modshop and add a nitro to the car. Then save it's data to a file:
pawn Код:
for( new i; i<sizeof(PlayerCars[]); i++)
{
if( GetVehicleModel(vehicleid) == PlayerCars[playerid][i] )
{
// Some function, just suppose it works like this
Save( "file.txt", i, "modelid:", PlayerCars[playerid][i] );
Save( "file.txt", i, "nitro:", GetVehicleComponentInSlot( GetPlayerVehicleID(playerid) );
// You are saving the nitro to the corresponding slot of the car in the array
}
}
Код:
slot0: modelid: 506 nitro: 1008 // a 2x nitro for car in slot 0 inside PlayerCars slot1: slot2: slot3:
"file.txt" now looks like this:
Код:
slot0: modelid: 506 nitro: 1008 slot1: slot2: modelid: 400 nitro: 1008 slot3:
pawn Код:
new string[24];
new Menu:mycarsmenu = CreateMenu("Your cars", 2, 2, 150.0, 100.0, 20.0);
for( new i=0; i<sizeof(PlayerCars[]); i++ )
{
if( PlayerCars[playerid][i] >= 400 )
{
format(string,sizeof(string),"%s", GetVehicleNameByModel(PlayerCars[playerid][i]) );
AddMenuItem( mycarsmenu, 0, string);
}
}
Код:
Landstalker Super GT
The problem is that Landstalker corresponds to row 0 in the menu ( ok, no problem ), but Super Gt corresponds to slot 1 in the menu and slot 3
in PlayerCars.
If I select "Super Gt", im selecting a car that has no data stored for that slot inside the file, so nothing is loaded.
I need help figuring out how to list only the cars i have inside a menu and when I selected them to correctly load the data stored in the file.
I don't know i explained myself well.