29.08.2012, 11:05
Problem
Let's say I want to make a house storage where players can save weapons.
If I want to store 5 weapons (weapon ID and ammo) I would add the 'hStorage' to the house enum like this:
This doesn't work (gives error on compiling), but there is another way.
Solution
This compiles fine and now I can use the 'hStorage' as I intended.
Looping:
This method doesn't actually make 'hStorage' 2-dimensional, but it gives a feeling that it is.
Let's say I want to make a house storage where players can save weapons.
If I want to store 5 weapons (weapon ID and ammo) I would add the 'hStorage' to the house enum like this:
pawn Code:
enum eHouse
{
hCreated,
Float:hEnter[3],
Float:hExit[3],
hInterior,
hOwner[MAX_PLAYER_NAME],
hValue,
hLock,
hStorage[5][2],
hPickup,
Text3D:hLabel
};
new House[50][eHouse];
Solution
pawn Code:
const hStorage_size1 = 5;
const hStorage_size2 = 2;
const sizeof_hStorage = hStorage_size1 * hStorage_size2;
enum eHouse
{
hCreated,
Float:hEnter[3],
Float:hExit[3],
hInterior,
hOwner[MAX_PLAYER_NAME],
hValue,
hLock,
hStorage[sizeof_hStorage],
hPickup,
Text3D:hLabel
};
new House[50][eHouse];
#define hStorage][%1][%2] hStorage][((%1)*hStorage_size2)+(%2)]
pawn Code:
House[houseid][hStorage][2][0] = WEAPON_MP5;
House[houseid][hStorage][2][1] = 500;
pawn Code:
new weapon, ammo;
for(new i=0; i < hStorage_size1; i++)
{
weapon = House[houseid][hStorage][i][0];
ammo = House[houseid][hStorage][i][1];
printf("[%d] weapon: %d ammo: %d", i, weapon, ammo);
}