One way to do it is to keep track of your current position in the Inventory, then use a dual for loop to draw the amount of rows and columns you're after. I.e.
PHP Code:
//#CLIENTSIDE
function drawInventory() {
temp.rows = 4; // Rows
temp.cols = 5; // Columns
temp.spacing = 2; // Pixels between squares
temp.i = 0;
temp.tx = 100; // Top-left X
temp.ty = 100; // Top-left Y
temp.icon_width = 32;
temp.icon_height = 32;
for (temp.x = 0; temp.x < temp.cols; temp.x++) {
for (temp.y = 0; temp.y < temp.rows; temp.y++) {
temp.item = getInventoryItemIcon(temp.i);
showimg(200 + temp.i, temp.item, temp.tx + (temp.x * temp.icon_width) + temp.spacing, temp.ty + (temp.y * temp.icon_height) + temp.spacing);
changeimgvis(200 + temp.i, 4); // Draws is on screen-level instead of player.
temp.i++; // You could do math to determine the item by x and y but a simple counter is easier
}
}
}
function getInventoryItemIcon(item_pos) {
return this.items[item_pos].icon; // Placeholder...
}