Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Inventory Question (https://forums.graalonline.com/forums/showthread.php?t=134266242)

Entrok 04-14-2012 08:52 PM

Inventory Question
 
2 Attachment(s)
Im trying to learn how to make a inventory based on loading .txt/.arc files and sofar so good, but when i want to place out the weapons that are available i dident know how to do it, so i checked forums but dident find so much about it.

I did check in to Stonehenge how they had done theirs but the prob is that they only have 1 row, with 4 items down like i show in attached file 1.

What im trying to do is to list the items like attached file 2.

What i have tryed to use/modify atm is this:

PHP Code:

  if (this.curtab == NIL) this.curtab = "weapons";
  
this.gsk = getstringkeys("clientr." @ this.curtab @ "_");
  

  for (
temp.g = 0; temp.g < min(this.gsk.size(), 5); temp.g++) 
  {  
    
// Draw the icons in the inventory that are currently visible
    
temp.draw = clientr.(@ this.curtab @ "_" @ this.gsk[temp.g + this.menuscroll])[3];
    
    
drawImg(502 + temp.g * 2, temp.draw, 31 + temp.g * 35, 110 + temp.g * 35, 6);
    
temp.writ = clientr.(@ this.curtab @ "_" @ this.gsk[temp.g + this.menuscroll])[1];
    
drawText(502 + temp.g * 2 + 1, 62, 131 + temp.g * 35, temp.font, "r", temp.writ, 7, .5, 1, 1, 1, 1);
    if (
mousescreenx in |31, 63|) 
    {
      if (
mousescreeny in |110 + temp.g * 35, 142 + temp.g * 35|) 
      {  
        
// Hovering over an item in the inventory
        
temp.writ = clientr.(@ this.curtab @ "_" @ this.gsk[temp.g + this.menuscroll])[2];
        
drawText(500, mousescreenx, mousescreeny - 8, temp.font, "bc", temp.writ, 9, .5, 0, 0, 0, 1);
        
drawImg(501, "light4.png", -17, 62 + temp.g * 35, 8, .7, .7, .7, .7, .7);
      }
    }
  } 

How would i make it to list more then 1 row?

fowlplay4 04-14-2012 10:33 PM

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...
} 



All times are GMT +2. The time now is 09:10 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.