Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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:	406
Size:	13.1 KB
ID:	50637  
Reply With Quote
  #2  
Old 07-24-2010, 07:24 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Have you tested row usage?

I haven't, but from what it looks like, it will not add another row. I'd recommend replacing that with something like...

PHP Code:
temp.= -1;
temp.0;
// Code here
  
if ( temp.== replace this with ONE LESS than the number you want in each row ) {
    
temp.0;
    
temp.++;
  } else {
    
temp.++;
  }
// More code here 
Correct me if I'm wrong, but I'm pretty sure that would work a bit better :P
Reply With Quote
  #3  
Old 07-24-2010, 03:11 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by devilsknite1 View Post
Have you tested row usage?

I haven't, but from what it looks like, it will not add another row. I'd recommend replacing that with something like...

PHP Code:
temp.= -1;
temp.0;
// Code here
  
if ( temp.== replace this with ONE LESS than the number you want in each row ) {
    
temp.0;
    
temp.++;
  } else {
    
temp.++;
  }
// More code here 
Correct me if I'm wrong, but I'm pretty sure that would work a bit better :P
hmm
HTML Code:
  temp.i_pos = {5 + (35 * (temp.i_ind % 9)), 3 + (35 * int(temp.i_ind / 9))};
__________________
Reply With Quote
  #4  
Old 09-01-2010, 03:41 AM
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
I haven't messed with it except for the like 10 minutes that it took for me to make. It worked fine for whoever I made it for.
Reply With Quote
Reply


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 07:57 AM.


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