Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-18-2010, 04:36 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Bare-bone Inventory system with tabs

I was making a cool inventory with particle effects for use with my item system and someone asked me to make them one that works with just classic weapons and since Ziro's apperently can't be copied and pasted into a WNPC(?) I figured I'd make one with tabs that could. I gave it to them and they had 100000 questions about it so I figured I could just post it here and explain it.

This is how it works:
You must first put your weapon's into categories ex "Weapons/Bow" or "Tools/Hammer". After doing that all you have to do is edit thiso.weapontabs and put the category into the array. Say you wanted to add everything in "Tools/" you would do it like this:
PHP Code:
thiso.weapontabs = {"Tools"}; 
everything in "Tools/" would show up like "Tools/Hammer", "Tools/Axe","Tools/Water Can" or whatever.
Next lets say you want to add a new tab for event items right after that would contain everything in "Events/" you would just do:
PHP Code:
thiso.weapontabs = {"Tools","Events"}; 
Everything in this tab would be things like "Events/Color Changer" or "Events/Ban Hammer".

If you want to change your images just put this into your weapon npcs.
PHP Code:
this.image "imagename.png"
This will not show anything that is just "WeaponName" so everything must be categorized which will help with organization. I would suggest putting all the weapons like 'system weapons' and anything you dont want the player to have access to as just "WeaponName" with no category. I tried to explain this as best I could so there wont be any questions but I guess feel free to ask.
PHP Code:
//#CLIENTSIDE
function onCreated(){
  
thiso.weapontabs = {"Weapons","Events","Tools","Fun","Etc"};
  
enablefeatures(allfeatures 4);
  
onOpenInventoryGui();
  
InventoryGuiControl_Container.hide();
}
function 
onKeyPressed(){
  if (
keydown(9))
  {
    if (
InventoryGuiControl_Container.visible false)
    {
      
InventoryGuiControl_Container.show();
      
onOpenInventoryGui();
    }
    elseif (
InventoryGuiControl_Container.visible true){
      
InventoryGuiControl_Container.hide();
    }
  }
}
function 
onOpenInventoryGui(){
  new 
GuiControl("InventoryGuiControl_Container"){
    
extent "332 270";
    
= (screenwidth/2)-width/2;
    
= (screenheight/2)-height/2;
    new 
GuiTabCtrl("InventoryGuiTabCtrl_TabSelect"){
      
profile "GuiBlueTabProfile";
      
0;
      
0;
      
extent "332 20";
      
tabwidth 326/thiso.weapontabs.size();
      
clearrows();
      for (
temp.0temp.thiso.weapontabs.size(); temp.i++)
      {
        
addrow(temp.ithiso.weapontabs[temp.i]);
        
thiso.catchevent(name,"onSelect","onUpdateInventory");
      }
      
setselectedrow(0);
    }
    new 
GuiScrollCtrl("InventoryGuiScrollCtrl_WeaponList"){
      
profile "GuiBlueScrollProfile";
      
0;
      
20;
      
extent "332 230";
      
hscrollbar "alwaysOff";
    }
    new 
GuiScrollCtrl("InventoryGuiScrollCtrl_WeaponNameContainer"){
      
profile "GuiBlueScrollProfile";
      
0;
      
250;
      
extent "332 26";
      
hscrollbar vscrollbar "alwaysOff";
      new 
GuiMLTextCtrl("InventoryGuiMLTextCtrl_WeaponName"){
        
profile "GuiBlueMLTextProfile";
        
0;
        
0;
        
extent "332 20";
        
text "";
      }
    }
  }
  
onUpdateInventory();
}
function 
onUpdateInventory(){
  for (
temp.0temp.player.weapons.size();temp.i++)
  {
    (@ 
"InventoryGuiBitmapCtrl_Weapon_" temp.i).destroy();
  }
  
temp."-1";
  
temp."0";
  for (
temp.0temp.player.weapons.size();temp.i++)
  {
    
with (InventoryGuiScrollCtrl_WeaponList){
      
temp.weaponsection InventoryGuiTabCtrl_TabSelect.getselectedtext();
      if (
player.weapons[i].name.starts(temp.weaponsection))
      {
        if (!(
player.weapons[i].name.starts("-") || player.weapons[i].name.starts("*")))
        {
          if (
temp.7)
          {
            
temp."0";
            
temp.h++;
          }
          else
            
temp.w++;
          new 
GuiBitmapCtrl("InventoryGuiBitmapCtrl_Weapon_" temp.i){
            
= (temp.w*34)+5;
            
= (temp.h*34)+6;
            
extent "32 32";
            
bitmap player.weapons[i].image;
            
hint player.weapons[i].name;
            
this.wepid temp.i;
            
this.wepname =  player.weapons[i].name;
            
thiso.catchevent(name,"onMouseMove","onSetGuiText");
            
thiso.catchevent(name,"onMouseDown","onSetWeapon");
          }
        }
      }
    }
  }
  
GraalControl.makeFirstResponder(true);
}
function 
onSetWeapon(GuiBitmapCtrl_Weapon){
  
selectedweapon =  GuiBitmapCtrl_Weapon.wepid;
}
function 
onSetGuiText(GuiBitmapCtrl_WeaponName){
  
InventoryGuiMLTextCtrl_WeaponName.text GuiBitmapCtrl_WeaponName.wepname;

Attached Thumbnails
Click image for larger version

Name:	basicinventory.png
Views:	451
Size:	13.1 KB
ID:	50637  
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:28 AM.


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