Give item? with c#

Discussion in 'Released Mods' started by Johncab, Dec 21, 2012.

  1. Johncab

    Johncab Green Slime

    not sure if this is the right section, but im trying to give a player an item inside of c# is there any way to do so with a MOD item?
     
  2. Wigglesniff

    Wigglesniff World Feeder

    Could you be more specific?
     
  3. Johncab

    Johncab Green Slime

    Im trying to give the player an item when he clicks a button in an interface, like if button pressed; give item to player script here;
     
  4. Wigglesniff

    Wigglesniff World Feeder

  5. Johncab

    Johncab Green Slime

    Yeah i used that tutorial, it doesnt say how to give new items though, it tells me how to clone an item in a slot, or delete the item in a slot, but not put a new item completely
     
  6. GallantJR

    GallantJR Green Slime

    But you can actually delete the copy of the item in the player inventory , and copy it in the other player ^^ You will need some multiplayer code tough
     
  7. Johncab

    Johncab Green Slime

    i just want to give the player an item that he doesn't already have
     
  8. Empio

    Empio Blazing Wheel

    You could use Item.NewItem, and spawn it at the player's location. You can use Main.player[Main.myPlayer] to get the local player.
     
  9. GallantJR

    GallantJR Green Slime

    You are not clear .. Do you want to create a window trading system , or just want to add a selected item to your character ?
     
  10. Johncab

    Johncab Green Slime

    i want to add an item, that he doesn't already have, and isn't referenced beforehand in the script to a player
     
  11. GallantJR

    GallantJR Green Slime

  12. GallantJR

    GallantJR Green Slime

    And if you want to add directly the item in the inventory :

    Code:
    public static int GetInventoryFreeSlot(Player p)
    {
        for(int i = 0; i < p.inventory.Length; i++)
        {
            if (p.inventory[i].name == "" || p.inventory[i].name == " " || p.inventory[i].name == null)
                return i;
        }
     
        return -1;
    }
     
    public static void addItemToInventory(Player p, Item item)
    {
        int slotID = GetInventoryFreeSlot(p);
        if (slotID >= 0)
            p.inventory[slotID] = item;
    }
     

Share This Page