View Single Post
  #1  
Old 09-13-2006, 06:03 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Custom Inventory

Custom Inventory
v1.0


This inventory works pretty much as the default Graal inventory does. It displays NPCs that doesnt start with "-", and by doubleclicking on a weapon you select it. 'Sub-Folders' will be implemented in the next version, if requested.


Theres only ONE thing that doesnt work properly in it, selected a weapon. For some reason, it doesnt always selected the proper weapon.

Example:

Player doubleclicks on the weapon "Staff/Boots" and it gets equipped properly.
Player then tries to doubleclick the weapon "Tailor", and that too works.
Finally, player tries to equip the weapon "Skateboard", but "Tailor" gets equiped instead!

Id be so-so happy if someone would be able to solve that bug, I havent been able too.


But other then that, its all good to go!



Installing

When adding the NPC, it can be named pretty much anything you want BUT it HAVE to start with a "-"! If it doesnt, it wont work properly.

PHP Code:
function onActionServerSide()
{
  if (
params[0] == "playerweaps") {
    for (
0player.weapons.size(); ++) temp.imgs.add(findWeaponNPC(player.weapons[i]).image);
    
triggerClient("gui"name"openinv"player.weaponstemp.imgs);
  }
}

//#CLIENTSIDE
function onCreated()
{
  
enablefeatures(allfeatures 4);
  
this.gName "Inventory_";
  (
this.gName "Window0").destroy();
  
setTimer(.05);
}

function 
onTimeOut()
{
  
this.plWeapon player.weapon.name;
  
showText(2006100"System""b""Selected Weapon:" SPC this.plWeapon SPC "[" selectedweapon "]");
  
changeImgVis(2004);
  
  
setTimer(.05);
}

function 
onKeyPressed(keynrkeyname)
{
  if (
keyname == "q") {
    if ((
this.gName "Window0").visible == falsetriggerServer("gui"name"playerweaps");
    else (
this.gName "Window0").destroy();
  }
}

function 
onActionClientSide("",weaps,imgs)
{
  if (
params[0] == "openinv"OpenInventory(weapsimgs);
}

function 
OpenInventory(invWeaponsinvImages)
{
  if ((
this.gName "Window0").visible == false) {
    new 
GuiWindowCtrl(this.gName "Window0") {
      
width 196height 177;
      
screenwidth/width/2screenheight/height/2;
    
      
canMinimize false;
      
canMaximize false;
      
canResize false;
      
canMove false;
      
destroyOnHide true;
      
      
xmod NULL;
      
ymod NULL;
      
rowcount NULL;
      
      
invItems NULL;
      
// Removes old buttons
      
for (0invItems.size(); ++) (this.gName "Button" i).destroy();
    
      
// Checks for items to display in inventory
      
for (0invWeapons.size(); ++) {
        if (!
invWeapons[i].starts("-")) invItems.add({invWeapons[i], invImages[i]});
      }
      
      
// Displays the items
      
new GuiScrollCtrl(this.gName "Scroll0") {
        
width 187height 150;
        
523;
        
        
hScrollBar "alwaysOff";
        
vScrollBar "dynamic";
      
        for (
0invItems.size(); ++) {
          
temp.var = 5;
          if (
temp.var.length() == && 0) {
            
xmod NULL;
            
ymod += 36;
            
rowcount ++;
          }
        
          new 
GuiBitmapButtonCtrl(this.gName "Button" i) {
            
width 32height 32;
            
xmodymod;
          
            
this.itemname invItems[i][0];
            
this.itemimage invItems[i][1];
          
            
normalbitmap this.itemimage;
            
mouseoverbitmap this.itemimage;
            
pressedbitmap this.itemimage;
          
            
thiso.catchevent(this"onMouseDown""onSlotPressed");
            
thiso.catchevent(this"onMouseEnter""onMouseOverSlot");
            
thiso.catchevent(this"onMouseLeave""onMouseExitSlot");
          }
          
xmod += 32 4;
        }
      }
    }
    (
this.gName "Window0").makefirstresponder("false");
  } else (
this.gName "Window0").destroy();
}

function 
onSlotPressed(objkeymodifiermousescreenxmousescreenyclickcount)
{
  if (
clickcount == 2) {
    
player.chat "Selected Weapon:" SPC obj.itemname;
    
selectedweapon player.weapons.index(findWeapon(obj.itemname));
    (
this.gName "Window0").destroy();
  } else if (
clickcount == 1) (this.gName "Window0").text obj.itemname;
}

function 
onMouseOverSlot(obj) (this.gName "Window0").text obj.itemname;
function 
onMouseExitSlot(obj) (this.gName "Window0").text ""

Enjoy!
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote