Search Unity

RPG Inventory Source

Discussion in 'Made With Unity' started by unitrix, May 6, 2010.

  1. unitrix

    unitrix

    Joined:
    Mar 19, 2010
    Posts:
    279
    No your mesh prefab, needs to have this script on it:
    Code (csharp):
    1.  
    2. Code:
    3.  
    4. var script : Inventory;
    5.  
    6. function Update(){
    7. if(script.UpdateNeeded == false)
    8.    {
    9.       if(script.EquipedItem[16] == null)
    10.       {
    11.             Destroy (gameObject);
    12.             script.UpdateNeeded = true;
    13.       }
    14.    }
    15. }
    16.  
    17.  
    Then in the inspector click on the mesh prefab and then it will say Script None(Inventory)
    You need to drag the object that has the Inventory script on it into this spot.

    Your mesh prefab is like your model for you sword or staff what ever is just showing on the character for equiping.
     
  2. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    Works! I hope this helpes everyone who uses this project. Just remebered to mention that for separate inventory slots I used separate t/f statements and just about separate everything. Thanks Unitrix! :D :D :D
     
  3. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    By the way. Id love to help improve(more) on the whole inventory. I plan to try and create a working vendor. :mrgreen:
     
  4. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    My version of "Advanced"
    Code (csharp):
    1.  
    2. var merchant : Array;
    3. var shoping = false;
    4.  
    5. function OnMouseDown()
    6. {
    7. shoping = true;
    8. }
    9. function Awake()
    10. {
    11.     merchant = new Array(14);
    12.     shoping = true; //for testing only
    13. }
    14. function OnGUI()
    15. {
    16.     GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 1024.0, Screen.height / 768.0, 1));
    17.     if (shoping)
    18.     {
    19.         GUI.Box (Rect (345,100,220,220),GUIContent ("Merchant", "this box has a tooltip"));
    20.         mSlot(merchant,0,350,120);
    21.         mSlot(merchant,1,392,120);
    22.         mSlot(merchant,2,435,120);
    23.         mSlot(merchant,3,350,162);
    24.         mSlot(merchant,4,392,162);
    25.         mSlot(merchant,5,435,162);
    26.         mSlot(merchant,6,350,204);
    27.         mSlot(merchant,7,392,204);
    28.         mSlot(merchant,8,435,204);
    29.         mSlot(merchant,9,350,246);
    30.         mSlot(merchant,10,392,246);
    31.         mSlot(merchant,11,435,246);
    32.         mSlot(merchant,12,477,246);
    33.         mSlot(merchant,13,519,246);
    34.         if (GUI.Button(Rect (545,100,20,20),"X")){
    35.             shoping = false;
    36.         }
    37.     }
    38. }
    39. function mSlot(arraypassed,slot,X,Y)
    40. {
    41. (GUI.Button (Rect (X,Y, 40, 40),""));
    42. }
    43.  
    Its an addition to your merchant.
    I just got the idea of using something like the corpse script. Exept it take money from you...
     
  5. crasyboy42

    crasyboy42

    Joined:
    Jun 29, 2010
    Posts:
    28
    about the potions
    can you use them to heal or gaint mana or something like that??

    maybe is that a new function :)
     
  6. poboczny

    poboczny

    Joined:
    Sep 25, 2010
    Posts:
    553
    The inventory is great and I was searching for that one for over 4 moths. Focused on everything else over the way but I still dont understand one thing.

    When I equip lets say the weapon into the Primary Slot I want to instantieta a prefab in spawn point which is lets say SpawnPoint1 and make it dissapear after unequipping it.

    Any scripts for this ? or halw way scripts ?

    As far as I understand it would be good to attach to a inventory item a var that has no prefab and than when equipping a weapon it should instantiate the prefab that the icon (inventoryitem) has at the specific spown point.

    How to do it ?

    Ofc Id like to do with all of the armor slots.
     
  7. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    (bookmarked)
     
  8. poboczny

    poboczny

    Joined:
    Sep 25, 2010
    Posts:
    553
    OK. I figured it out in a different way.

    My Player has a many meshes including the meshes of armor or weapons.

    I did put a script that disables and enebles a game object when e.g. weapon is equipped.

    The script is currently in that mesh - it'll do for now but later it is going to be hard to rebuild a player each time with the meshes. We will see that.

    Cheers.
     
  9. Voideo

    Voideo

    Joined:
    Sep 28, 2010
    Posts:
    6
    This is best inventory system I've seen for Unity!
    This post is great and the forum should give it more visibility.

    Thank you very much unitrix!
     
  10. markis

    markis

    Joined:
    Oct 11, 2010
    Posts:
    51
    wow nice dude. did some one have full script with equiping into charakter (visible) armor?
     
  11. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    Okay, this is a merchant system. It doesn't work yet. But it is probably just missing one thing.
    Basicly ive tried to add a price to the item, and if you dont have the money, you don't get the item.
    --------------------------------------------------------------------------------------------------------------------------------------------------------
    var looting = false;
    var Item1 : Transform;
    var Item2 : Transform;
    var moneyItem : Transform;
    var inv: Inventory;
    var cinventory : Array;
    var Price1 = 0;
    var GOLD = inv.inventorymoney[2].itemstacksize;
    function OnMouseDown()
    {
    looting = true;
    }
    function Awake(){
    cinventory = new Array(8);
    scriptA = Item1.GetComponent("ItemScript");
    var item = new InventoryItem();
    item.itemname = scriptA.itemname;
    item.itemtex = scriptA.itemtex;
    item.itemtype = scriptA.itemtype;
    item.equipmenttype = scriptA.equipmenttype;
    item.usable = scriptA.usable;
    item.itemweight = scriptA.itemweight;
    item.droppable = scriptA.droppable;
    item.itemmodel = scriptA.itemmodel;
    item.itemmesh = scriptA.itemmesh;

    item.itemstacksize = scriptA.itemstacksize;
    item.itemstacklimit = scriptA.itemstacklimit;
    item.showStack = scriptA.showStack;

    item.bagsize = scriptA.bagsize;
    item.showBag = scriptA.showBag;
    item.BagItem = scriptA.BagItem;
    cinventory[0] = item;

    scriptB = Item2.GetComponent("ItemScript");
    var item2 = new InventoryItem();
    item2.itemname = scriptB.itemname;
    item2.itemtex = scriptB.itemtex;
    item2.itemtype = scriptB.itemtype;
    item2.equipmenttype = scriptB.equipmenttype;
    item2.usable = scriptB.usable;
    item2.itemweight = scriptB.itemweight;
    item2.droppable = scriptB.droppable;
    item2.itemmodel = scriptB.itemmodel;

    item2.itemstacksize = 15;
    item2.itemstacklimit = scriptB.itemstacklimit;
    item2.showStack = scriptB.showStack;

    item2.bagsize = scriptB.bagsize;
    item2.showBag = scriptB.showBag;
    item2.BagItem = scriptB.BagItem;
    cinventory[1] = item2;

    scriptC = moneyItem.GetComponent("ItemScript");
    var item3 = new InventoryItem();
    item3.itemname = scriptC.itemname;
    item3.itemtex = scriptC.itemtex;
    item3.itemtype = scriptC.itemtype;
    item3.equipmenttype = scriptC.equipmenttype;
    item3.usable = scriptC.usable;
    item3.itemweight = scriptC.itemweight;
    item3.droppable = scriptC.droppable;
    item3.itemmodel = scriptC.itemmodel;

    item3.itemstacksize = scriptC.itemstacksize;
    item3.itemstacklimit = scriptC.itemstacklimit;
    item3.showStack = scriptC.showStack;

    item3.bagsize = scriptC.bagsize;
    item3.showBag = scriptC.showBag;
    item3.BagItem = scriptC.BagItem;
    cinventory[2] = item3;
    }

    function OnGUI()
    {
    GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 1024.0, Screen.height / 768.0, 1));
    if (looting){
    if (cinventory[2] != null){
    Inventory.statInventory.AddItem(cinventory[2]);
    cinventory[2] = null;
    }
    GUI.Box (Rect (345,100,167,220),GUIContent ("Corpse", "this box has a tooltip"));
    if (GUI.Button(Rect (492,100,20,20),"X")){
    looting = false;
    }
    /*
    scriptA = Item1.GetComponent("ItemScript");
    if (GUI.Button(Rect (385,120,32,32),"")){
    if (cinventory[0] != null){
    Inventory.statInventory.AddItem(cinventory[0]);
    Price1 += inv.inventorymoney[0].itemstacksize;
    //cinventory[0] = null;
    }
    }
    */
    scriptA = Item1.GetComponent("ItemScript");
    if (GUI.Button(Rect (385,120,32,32),""))
    {

    if (cinventory[0] != null){
    Inventory.statInventory.AddItem(cinventory[0]);
    inv.inventorymoney[2].itemstacksize -= Price1;
    //cinventory[0] = null;
    }

    if(inv.inventorymoney[2].itemstacksize < Price1)
    {

    }
    }
    scriptB = Item2.GetComponent("ItemScript");
    if (GUI.Button(Rect (420,120,32,32),"")){
    if (cinventory[1] != null){
    Inventory.statInventory.AddItem(cinventory[1]);
    //cinventory[1] = null;
    }
    }
    if (cinventory[0]!= null){
    GUI.DrawTexture (Rect(400,120,32,32),cinventory[0].itemtex);
    }
    }
    }
    -------------------------------------------------------------------------------------------------------------------------------------------------------
     
  12. RoyS

    RoyS

    Joined:
    Jan 12, 2009
    Posts:
    664
    Nice addition to the "Advanced" version, Zu01. The advanced version is pretty good and we needed a barter type system. Keep it going.
     
  13. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    Well, I will. But I just need someone to tell me how I can "contact the Copper" because inv.inventorymoney[2].itemstacksize doesn't work
     
  14. unitrix

    unitrix

    Joined:
    Mar 19, 2010
    Posts:
    279
    I checked in my script and from what I see the copper is stored in the array slot 0 so try:
    inv.inventorymoney[0].itemstacksize
     
  15. markis

    markis

    Joined:
    Oct 11, 2010
    Posts:
    51
    OMG you all so good at it. I'm N00B but still... Can you teach me all about it and what need to know for join with you?
     
  16. MrRudak

    MrRudak

    Joined:
    Oct 17, 2010
    Posts:
    159
    Hey men if you wanna work in a sci-fi game
    contact me at rudasvicen8@hotmail.com
    it wont be paid at the moment but you
    will get money of the earnings
    what do yo say? wanna team up?
     
  17. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Perhaps it would be nice if you stopped spamming every other thread with this message.
     
  18. markis

    markis

    Joined:
    Oct 11, 2010
    Posts:
    51
    if spam this message, you will be stupid log

    (sorry, bad english)
     
  19. Leathel

    Leathel

    Joined:
    Nov 3, 2010
    Posts:
    26
    When it says " Finished, not in current web version" does that mean the demo just doesn't have it implemented, or that it won't work for a web app?
     
  20. Sundose

    Sundose

    Joined:
    Nov 6, 2010
    Posts:
    1
    Thanks! Good job :)
     
  21. unitrix

    unitrix

    Joined:
    Mar 19, 2010
    Posts:
    279
    It means its just not in the current demo, it works if you put on web app
     
  22. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    Tada! I finally made a working inventory script!
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    var looting = false;
    var Item1 : Transform;
    var Item2 : Transform;
    var Item3 : Transform;
    var moneyItem : Transform;
    var inv: Inventory;
    var cinventory : Array;
    var Price = 0;
    var PriceI = 0;
    var PriceII = 0;
    var PriceIII = 0;
    var PriceENT : int;
    var PriceENTI : int;
    var PriceENTII : int;
    var PriceENTIII : int;
    var Nameone;
    var Nametwo;
    var Namethree;
    var NrdItemLoot = true;
    private var Blank = "";
    private var PriceD;
    private var PriceDII;
    private var PriceDIII;
    function Update()
    {
    PriceD = Blank + PriceENT;
    PriceDII = Blank + PriceENTI;
    PriceDIII = Blank + PriceENTII;
    }
    function OnMouseDown()
    {
    looting = true;
    }
    function Awake(){
    cinventory = new Array(8);
    scriptA = Item1.GetComponent("ItemScript");
    var item = new InventoryItem();
    Nameone = scriptA.itemname;
    item.itemname = scriptA.itemname;
    item.itemtex = scriptA.itemtex;
    item.itemtype = scriptA.itemtype;
    item.equipmenttype = scriptA.equipmenttype;
    item.usable = scriptA.usable;
    item.itemweight = scriptA.itemweight;
    item.droppable = scriptA.droppable;
    item.itemmodel = scriptA.itemmodel;
    item.itemmesh = scriptA.itemmesh;

    item.itemstacksize = scriptA.itemstacksize;
    item.itemstacklimit = scriptA.itemstacklimit;
    item.showStack = scriptA.showStack;

    item.bagsize = scriptA.bagsize;
    item.showBag = scriptA.showBag;
    item.BagItem = scriptA.BagItem;
    cinventory[0] = item;

    scriptB = Item2.GetComponent("ItemScript");
    var item2 = new InventoryItem();
    Nametwo = scriptB.itemname;
    item2.itemname = scriptB.itemname;
    item2.itemtex = scriptB.itemtex;
    item2.itemtype = scriptB.itemtype;
    item2.equipmenttype = scriptB.equipmenttype;
    item2.usable = scriptB.usable;
    item2.itemweight = scriptB.itemweight;
    item2.droppable = scriptB.droppable;
    item2.itemmodel = scriptB.itemmodel;
    item2.itemmesh = scriptB.itemmesh;

    item2.itemstacksize = scriptB.itemstacksize;
    item2.itemstacklimit = scriptB.itemstacklimit;
    item2.showStack = scriptB.showStack;

    item2.bagsize = scriptB.bagsize;
    item2.showBag = scriptB.showBag;
    item2.BagItem = scriptB.BagItem;
    cinventory[1] = item2;

    if(NrdItemLoot)
    {
    scriptC = moneyItem.GetComponent("ItemScript");
    var item3 = new InventoryItem();
    item3.itemname = scriptC.itemname;
    item3.itemtex = scriptC.itemtex;
    item3.itemtype = scriptC.itemtype;
    item3.equipmenttype = scriptC.equipmenttype;
    item3.usable = scriptC.usable;
    item3.itemweight = scriptC.itemweight;
    item3.droppable = scriptC.droppable;
    item3.itemmodel = scriptC.itemmodel;
    item3.itemmesh = scriptC.itemmesh;

    item3.itemstacksize = scriptC.itemstacksize;
    item3.itemstacklimit = scriptC.itemstacklimit;
    item3.showStack = scriptC.showStack;

    item3.bagsize = scriptC.bagsize;
    item3.showBag = scriptC.showBag;
    item3.BagItem = scriptC.BagItem;
    cinventory[2] = item3;
    }

    scriptD = Item3.GetComponent("ItemScript");
    var item4 = new InventoryItem();
    Namethree = scriptD.itemname;
    item4.itemname = scriptD.itemname;
    item4.itemtex = scriptD.itemtex;
    item4.itemtype = scriptD.itemtype;
    item4.equipmenttype = scriptD.equipmenttype;
    item4.usable = scriptD.usable;
    item4.itemweight = scriptD.itemweight;
    item4.droppable = scriptD.droppable;
    item4.itemmodel = scriptD.itemmodel;
    item4.itemmesh = scriptD.itemmesh;

    item4.itemstacksize = scriptD.itemstacksize;
    item4.itemstacklimit = scriptD.itemstacklimit;
    item4.showStack = scriptD.showStack;

    item4.bagsize = scriptD.bagsize;
    item4.showBag = scriptD.showBag;
    item4.BagItem = scriptD.BagItem;
    cinventory[3] = item4;
    }

    function OnGUI()
    {
    PriceENT = Price - Price - Price - 1;
    PriceENTI = PriceI - PriceI - PriceI - 1;
    PriceENTII = PriceII - PriceII - PriceII - 1;
    PriceENTIII = PriceIII - PriceIII - PriceIII - 1;
    GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 1024.0, Screen.height / 768.0, 1));
    if (looting){
    if (cinventory[2] != null){
    Inventory.statInventory.AddItem(cinventory[2]);
    cinventory[2] = null;
    }
    GUI.Box (Rect (345,100,167,220),GUIContent ("Merchant", "this box has a tooltip"));
    if (GUI.Button(Rect (492,100,20,20),"X")){
    looting = false;
    }
    scriptA = Item1.GetComponent("ItemScript");
    if (GUI.Button(Rect (385,120,32,32),""))
    {
    if(PriceENT < inv.inventorymoney[2].itemstacksize)
    {
    if(inv.inventorymoney[2].itemstacksize > Price)
    {
    if (cinventory[0] != null){
    Inventory.statInventory.AddItem(cinventory[0]);
    inv.inventorymoney[2].itemstacksize += Price;
    //cinventory[0] = null;
    }
    }
    }
    }
    scriptB = Item2.GetComponent("ItemScript");
    if (GUI.Button(Rect (385,155,32,32),"")){
    if(PriceENTI < inv.inventorymoney[2].itemstacksize)
    {
    if(inv.inventorymoney[2].itemstacksize > PriceI)
    {
    if (cinventory[0] != null){
    Inventory.statInventory.AddItem(cinventory[1]);
    inv.inventorymoney[2].itemstacksize += PriceI;
    //cinventory[0] = null;
    }
    }
    }
    }
    if(NrdItemLoot)
    {
    scriptD = Item3.GetComponent("ItemScript");
    if (GUI.Button(Rect (385,190,32,32),"")){
    if(PriceENTII < inv.inventorymoney[2].itemstacksize)
    {
    if(inv.inventorymoney[2].itemstacksize > PriceII)
    {
    if (cinventory[3] != null){
    Inventory.statInventory.AddItem(cinventory[3]);
    inv.inventorymoney[2].itemstacksize += PriceII;
    //cinventory[0] = null;
    }
    }
    }
    }
    }
    if (cinventory[0]!= null){
    GUI.DrawTexture (Rect(385,120,32,32),cinventory[0].itemtex);
    }
    if (cinventory[1]!= null){
    GUI.DrawTexture (Rect(385,155,32,32),cinventory[1].itemtex);
    }
    if(NrdItemLoot)
    {
    if (cinventory[3]!= null){
    GUI.DrawTexture (Rect(385,190,32,32),cinventory[3].itemtex);
    }
    }
    GUI.Label (Rect (420, 120, 100, 30), Nameone);
    GUI.Label (Rect (420, 155, 100, 30), Nametwo);
    GUI.Label (Rect (420, 190, 100, 30), Namethree);
    GUI.Label (Rect (370, 120, 100, 30), PriceD);
    GUI.Label (Rect (370, 155, 100, 30), PriceDII);
    GUI.Label (Rect (370, 190, 100, 30), PriceDIII);
    }
    }

    This merchant script is complety based of your corpse script. Yes, it has taken me a month.
    I attached a picture with corrosponing numbers below:
    P)Pictue is an attachment
    1) That is the merchant
    2) The same inventory, but I did put it in a draggable window
    3) A character stat window (draggable) which I will post when in a more complete state
     

    Attached Files:

  23. markis

    markis

    Joined:
    Oct 11, 2010
    Posts:
    51
    can you compres all script to rar and add here?
     
  24. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    yes would be verry nice if u would ;)

    awesome man keep up great work :D
     
  25. Demonith

    Demonith

    Joined:
    Mar 14, 2010
    Posts:
    200
    OMG its like in WoW :) Keep it up sir.
     
  26. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    so i put this in merchant script.
    but the problem is that there is no "itemmesh" in Itemscript.js that the script wants to acces.
    So what did you fill in ItemScript for "itemmesh".
     
  27. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    i fixed it i didn't looked on the previous pages
     
  28. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    sorry for the posts but i got a problem.
    So i have 999 gold in my inv and when i interact with the merchant it becomes 1998.
    I don't know why? maybe someone can help.
     

    Attached Files:

  29. dannyjax

    dannyjax

    Joined:
    Jan 26, 2010
    Posts:
    6
    falin; If you tell me how you use the script, I will put it in an instance and have my son look at it. What I mean is: Do I attach it to the player character? Do I attach it to an empty game object? Also it looks like .js so I will see if I can get him to convert it to C# too. I am not much of a programmer, I do 3D modeling, Writing and Texturing.
    Daniel
     
  30. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    hi, im back after a long time. Falin, the itemmesh was added to the script to make items appear. I have added the scripts with destructors, and working models(script functions only) But I have just 1 question for unitrix. I am trying to make a quest. How can I check on the item names in ALL the inventory slots> I tried Inventory.inventoryItemSlot.itemname = "hat"; But that failed
     

    Attached Files:

  31. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    I placed the inventory script on the player. the merchant script on a cube with the actionsHUD(http://forum.unity3d.com/threads/67103-ActionsHUD-available-for-free-download?highlight=actionsHUD) and changed the OnMouseDown function to Interact, Filled the 3 items and moneyitem by the merchant and price,priceI,priceII set to -11, price III =0.
    and in the scene i placed the money with itemstacksize 999.
    Is this enough information

    EDIT:
    Zu01 the destructors can put in 1 script right? because a script for every slot isn't needed right?
     
    Last edited: Jan 5, 2011
  32. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    Each destructor corrisponds to the item type. Weapons are A and I think shirts are B and so on... You have to look at the in the update funtion in the inventory (end) to find how they corrispond.

    By the way, did anyone figure out how to check all the inventory array names?
     
  33. Deleted User

    Deleted User

    Guest

    The link is broken :s
     
  34. jin76

    jin76

    Joined:
    Mar 4, 2010
    Posts:
    364
    yes the link to view the online is dead and the v2 gives error when bringing unity can someone confirm or upload a working edition of this

    this is just what i was looking for so i would love it if someone could post working version
     
  35. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    what is the error you get when bringing it in unity?
     
  36. jin76

    jin76

    Joined:
    Mar 4, 2010
    Posts:
    364
    for now i am getting
    "Assets/Scripts/Inventory.js(115,9): BCE0018: The name 'HP' does not denote a valid type ('not found'). "
    if some one can help i will be able to finally run the project
     
  37. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    Sorry about the HP stuff. You might want to remove that. It was intergrated to fit with all my scripts. What do you mean by the link is broken? Do you meen that it won't let you download it? Or that when you try to use the scripts it doesn't work cause they were for unity2.6? If so, I just got 3.1
     
  38. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    sry for the bump .

    i have fixed this problem.
    For someone with the same problem:
    in the merchant script there is this line of code:
    just delete that and it's fixed
     
  39. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    So are people getting into the link at all. From what it sounds, most people got it right?
     
  40. afalk

    afalk

    Joined:
    Jun 21, 2010
    Posts:
    164
    Glad to hear you got V3.1 :) I started experimenting with this code a while back -- very cool code base, and some very nice additions. Looking forward to working w/it in more depth w/3.1
     
  41. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    ok i have a problem:
    I added this to my ItemScript:
    now when i buy something like a bow for archer i can't equip it even when my class is archer.
    But when i drop the bow in the scene i pick it up and only works for archer,and the one from the shop isn't working.
     
  42. harsha

    harsha

    Joined:
    Nov 29, 2010
    Posts:
    64
    Hi guys,
    I am very new to unity.. This is first time doing an inventory for an iphone. I manage to use the source on the forum to create partial of the inventory.

    I will explain what I am doing first before I ask question:
    I have my player able to pick-up items from the ground. When the items are pick it need to be stored in an inventory table. I am able to pass the item name that is picked via the debug console.

    My question is how do I insert the item into the inventory table.

    I also always get this error NullReferenceException: Object reference not set to an instance of an object
    ItemScript.Update () (at Assets/MyScript/ItemScript.js:57)
    The line of the error is Invent2.statInventory.AddItem(item);

    Can someone guide me. Thank you.
     
  43. whyroph

    whyroph

    Joined:
    Nov 2, 2010
    Posts:
    58
    it's posible when you drop a intem to add it on character armor??
     
  44. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    *bump* can someone help me?
    I'm stuck with this problem.
    For bow example i do this:

    but when i have my class to archer it won't equip. the one from the shop and the one i pick up from the ground
     
  45. cemC

    cemC

    Joined:
    Dec 23, 2010
    Posts:
    214
    nice work...
     
  46. unitrix

    unitrix

    Joined:
    Mar 19, 2010
    Posts:
    279
    Sounds like when you buy it from the shop you are not instantiating the item so it doesnt awake thus it doesnt use what is in your awake function?

    That isnt getting called I think.
     
  47. whyroph

    whyroph

    Joined:
    Nov 2, 2010
    Posts:
    58
    @unitrix it's posible to equip armour on character with this inventory??
     
  48. unitrix

    unitrix

    Joined:
    Mar 19, 2010
    Posts:
    279
    Yes it is possible you just have to write it.
     
  49. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    so were do i need to put it because when i put it in update it doesn't work or collect.
    and in the merchant script i already added something like this:
    Code (csharp):
    1. var item5 = new InventoryItem();
    2.     Namefour = scriptE.itemname;
    3.     item5.itemname = scriptE.itemname;
    4.     item5.itemtex = scriptE.itemtex;
    5.     item5.itemtype = scriptE.itemtype;
    6.     item5.equipmenttype = scriptE.equipmenttype;
    7. [B] item5.ClassItem = scriptE.ClassItem;
    8.     item5.ClassEquiptype = scriptE.ClassEquiptype;[/B]
    9.     item5.usable = scriptE.usable;
    10.     item5.itemweight = scriptE.itemweight;
    11.     item5.droppable = scriptE.droppable;
    12.     item5.itemmodel = scriptE.itemmodel;
    13.     item5.itemmesh = scriptE.itemmesh;
    14.                    
    15.     item5.itemstacksize = scriptE.itemstacksize;
    16.     item5.itemstacklimit = scriptE.itemstacklimit;
    17.     item5.showStack = scriptE.showStack;
    18.                    
    19.     item5.bagsize = scriptE.bagsize;
    20.     item5.showBag = scriptE.showBag;
    21.     item5.BagItem = scriptE.BagItem;
    22.     cinventory[4] = item5;
     
  50. Zu01

    Zu01

    Joined:
    Aug 17, 2010
    Posts:
    95
    Ok, this is kinda off topic from what has been written in the last couple weeks, but is there a way to have a script check through the inventory array and find a specific item???

    EX :
    After finishing a quest, I want the finished quest scrip-t to be able to find a log in your inventory. Unitrix, do you have a solution.