Give item? with c#

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

  1. Johncab

    Johncab Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    12
    Likes Received:
    0
    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?
     
    #1
  2. Wigglesniff

    Wigglesniff World Feeder

    Joined:
    Jul 27, 2011
    Messages:
    675
    Likes Received:
    213
    Could you be more specific?
     
    #2
  3. Johncab

    Johncab Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    12
    Likes Received:
    0
    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;
     
    #3
  4. Wigglesniff

    Wigglesniff World Feeder

    Joined:
    Jul 27, 2011
    Messages:
    675
    Likes Received:
    213
    #4
  5. Johncab

    Johncab Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    12
    Likes Received:
    0
    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
     
    #5
  6. GallantJR

    GallantJR Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    43
    Likes Received:
    22
    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
     
    #6
  7. Johncab

    Johncab Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    12
    Likes Received:
    0
    i just want to give the player an item that he doesn't already have
     
    #7
  8. Empio

    Empio Blazing Wheel

    Joined:
    Jan 29, 2012
    Messages:
    430
    Likes Received:
    263
    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.
     
    #8
  9. GallantJR

    GallantJR Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    43
    Likes Received:
    22
    You are not clear .. Do you want to create a window trading system , or just want to add a selected item to your character ?
     
    #9
  10. Johncab

    Johncab Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    12
    Likes Received:
    0
    i want to add an item, that he doesn't already have, and isn't referenced beforehand in the script to a player
     
    #10
  11. GallantJR

    GallantJR Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    43
    Likes Received:
    22
    #11
  12. GallantJR

    GallantJR Green Slime

    Joined:
    Dec 19, 2012
    Messages:
    43
    Likes Received:
    22
    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;
    }
     
    #12

Share This Page