Saving Vehicle Modifications -
BornHuman - 03.06.2016
So the way I'm saving vehicle modifications is by the player enum. It's set up to have 13 different arrays in the enum and they're multi dimensional arrays so each array supports up to MAX_PLAYER_VEHICLES, which is currently defined as 5.
CarMod0[MAX_PLAYER_VEHICLES],
CarMod1[MAX_PLAYER_VEHICLES]
etc, etc.
So when the player mods their vehicle, instead of grabbing the component and doing if then or even switch statements I've decided just to make a function that will just save all their vehicle modifications at once. I know, not the most efficient thing in the world, but meh.
Here is where that function is used:
PHP код:
public OnVehicleMod(playerid, vehicleid, componentid)
{
if(IsPlayersVehicle(playerid, GetPlayerVehicleID(playerid)))
{
GetPlayerCarMods(playerid);
}
return 1;
}
Here is "GetPlayerCarMods"
PHP код:
GetPlayerCarMods(playerid)
{
for(new i; i < MAX_PLAYER_VEHICLES; i++)
{
Player[playerid][CarMod0][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 0);
Player[playerid][CarMod1][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 1);
Player[playerid][CarMod2][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 2);
Player[playerid][CarMod3][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 3);
Player[playerid][CarMod4][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 4);
Player[playerid][CarMod5][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 5);
Player[playerid][CarMod6][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 6);
Player[playerid][CarMod7][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 7);
Player[playerid][CarMod8][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 8);
Player[playerid][CarMod9][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 9);
Player[playerid][CarMod10][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 10);
Player[playerid][CarMod11][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 11);
Player[playerid][CarMod12][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 12);
Player[playerid][CarMod13][i] = GetVehicleComponentInSlot(Player[playerid][CarID][i], 13);
printf("%d|%d|%d", Player[playerid][CarMod5][i], GetVehicleComponentInSlot(Player[playerid][CarID][i], 5), Player[playerid][CarID][i]);
}
return 1;
}
I started to test this by adding nitro which is slot 5, so I decided to add a print at the bottom for the ID that's stored in CarMod5, and the GetVehicleComponentInSlot for that vehicle in slot 5. Both of these output 0 in the log. Finally, I added a check for the car ID itself and
it is the car ID in game.
Am I doing something wrong?
Re: Saving Vehicle Modifications -
Onfroi - 03.06.2016
Everything looks fine from my eyes. How are you setting the component? Maybe try OnEnterExitModShop instead.
Re: Saving Vehicle Modifications -
Vince - 03.06.2016
Quote:
Originally Posted by BornHuman
they're multi dimensional arrays
|
No, they're not. They're single dimensional arrays. A
true multi-dimensional array would look like this:
PHP код:
CarMod[MAX_PLAYER_VEHICLES][14]
Then all you need to do is loop through all vehicles, and for each vehicle loop through all slots, like so:
PHP код:
for(new i; i < sizeof(CarMod); i++) // loop 5 times for all vehicles
{
for(new j; j < sizeof(CarMod[]); j++) // for each vehicle, loop 14 times to gather each slot
{
CarMod[i][j] = GetVehicleComponentInSlot(Player[playerid][CarID][i], j);
}
}
No unnecessary repeated code.