tModLoader Vending Machines

JPAN

Steampunker
This mod introduces Vending Machines to the world of Terraria. These vending machines can be custom shops or any Town NPC shop, including both vanilla and modded npc shops.

To create a NPC based shop, you need a Soul Extractor(
SoulExtractor.png
), a deadly weapon that can only hit Town NPCs (and the Skeleton Merchant) and, as of Version 1.2, NPCs that spawn the Town NPCs (bound, sleeping,etc). This weapon is crafted with 12 Gold/Platinum bars, 1 Guide/Clothier Voodo Doll and 5 Diamonds. Killing a Town NPC (or spawning version) with this weapon will cause it to drop a Soul of <NPC> item, essential to craft a Town NPC Shop. To craft a Vending Machine, you need 15 iron/lead bars, 25 glass blocks, 10 wire, one switch and the NPC soul. This will create a "Vending Machine (<NPC>)" Example below:
20170218205046_1.jpg
Note: When creating the Vending Machine, it will display as "Vending Machine (Empty)". This is due to the way the item is programmed, and most likely cannot be fixed. The final item should be called "Vending Machine (Nurse)" or whatever NPC's soul you used.

Whey you finish crafting, place the Vending Machine anywhere and then right click it (from close enough) to open the shop. If the shop doesn't appear to open, try from closer (the range is really small). It works even with most Modded town NPCs (example here the Mutant from Fargo's Mutant Mod):
20170218205235_1.jpg
The Nurse Vending Machine is special: It will heal you at the cost the nurse would with a right click (it had to be implemented like that due to limitations).
The Travelling and Skeleton Merchant's shops change based on the day you are on, or if one of them spawns in your world.

This mod also includes the "Easy Vending Machine", an example vending machine that sells health and mana potions that is coded completely without an equivalent NPC.

As of version 1.1, it also includes the "Guide's Crafting Help Machine", that allows for access to the crafting help interface from the Guide, which requires the "Soul of the Guide" and the remaining regular vending machine crafting items, and a "Reforge Machine" crafted from the "Soul of the Goblin Thinkerer" and vending machine crafting items, which allows for reforging, same as the Goblin Tinkerer. Both these machines can be used as an example for building machines with custom Right-click code.

Version 1.2 adds the ATM, a Tax Collector based Machine that collects taxes, the Dye Ball Machine, a Dye Trader machine that allows for trading Strange Plants for Dyes, and the Hair Dryer, a Stylist based machine that allows you to color and style your hair. All machines are made the same as the others (requiring specific souls) except for the Hair Dryer, which requires Silk instead of Glass. The Hair Dryer also counts as a chair for your house, if you need one.

With this update, the only NPCs with a secondary function remaining require the NPC dialog screen, so I shouldn't be able to implement them.

Also the Right click code interface for VendingMachineItems was changed to include the VendingMachineData of the vending machine being used, and the Invisible NPC spawner was made "public static"

separator.png

Creating your own Vending Machine
This mod is meant as an easy-to-use Framework for anyone wishing to implement their own Vending Machines. To create one, you need to include this mod as a dependency on your mod build.txt. Feel free to use any of the provided graphics and code as reference. To decompile the mod you need the tModReader from the tModLoader thread.


  • Create a new class inheriting the VendingMachineItem class.
  • On that item's SetDefaults, include the following lines:
    hasShop = true;
    npcType = SoulOfNPC.ItemToTag(item);
  • On that same class, create a method
    "public override bool SetupShop(Item[] shop)"
  • fill it with your shop's contents, same as a NPC setupShop method.
You need to create a item image for this item, but feel free to use the one provided in the mod to match with the vending machine tile.

  • Create a new class inheriting the VendingMachineItem class.
  • On that item's SetDefaults, include the following lines:
    item.createTile = mod.TileType<*your vending machine Tile>();
    hasShop = true;
    npcType = SoulOfNPC.ItemToTag(item);
  • On that same class, create a method
    "public override bool SetupShop(Item[] shop)"
  • fill it with your shop's contents, same as a NPC setupShop method.
  • Create a new class inheriting the VendingMachine (Tile) Class
  • write
    public override void SetDefaults()
    {
    base.SetDefaults();
    dropID = mod.ItemType<*Your Vending machine Item Type here*>();
    }

  • (Optional) If you want to change the tile style from 3x4 to something else, write
    "public override void VendingMachineTileStyle()"
    and then fill in the "TileObjectData.newTile" fields. DO NOT USE TileObjectData.newTile.addTile. The base does that for you.
  • (Optional) If you want to change what shows on the map when you hover over the tile, write
    public override void VendingMachineMapEntry()
    {
    base.AddMapEntry(new Microsoft.Xna.Framework.Color(*your r, g, b*), "*your name to show*");
    }

  • (*Really* Optional) Change the Mouse Over/ Mouse Over Far methods to display something entirely different. By default (no change required) the method displays the Item Name of your vending machine item.
Don't forget to create your own tile/Item images if using this method.

To end, here's the mod and source code for those who cannot open the mod with tModReader. I would prefer if you download the mod from the browser, however, as this one might not be always up to date.
EDIT: Find all latest released in the github : JPANv2/VendingMachines
 

Attachments

  • VendingMachines.tmod.zip
    62.3 KB · Views: 1,174
  • VendingMachines.v1.2.zip
    33.4 KB · Views: 688
Last edited:
This mod introduces Vending Machines to the world of Terraria. These vending machines can be custom shops or any Town NPC shop, including both vanilla and modded npc shops.

To create a NPC based shop, you need a Soul Extractor(View attachment 160592 ), a deadly weapon that can only hit Town NPCs (and the Skeleton Merchant). This weapon is crafted with 12 Gold/Platinum bars, 1 Guide/Clothier Voodo Doll and 5 Diamonds. Killing a Town NPC with this weapon will cause it to drop a Soul of <NPC> item, essential to craft a Town NPC Shop. To craft a Vending Machine, you need 15 iron/lead bars, 25 glass blocks, 10 wire, one switch and the NPC soul. This will create a "Vending Machine (<NPC>)" Example below:
Note: When creating the Vending Machine, it will display as "Vending Machine (Empty)". This is due to the way the item is programmed, and most likely cannot be fixed. The final item should be called "Vending Machine (Nurse)" or whatever NPC's soul you used.

Whey you finish crafting, place the Vending Machine anywhere and then right click it (from close enough) to open the shop. If the shop doesn't appear to open, try from closer (the range is really small). It works even with most Modded town NPCs (example here the Mutant from Fargo's Mutant Mod):
The Nurse Vending Machine is special: It will heal you at the cost the nurse would with a right click (it had to be implemented like that due to limitations).
The Travelling and Skeleton Merchant's shops change based on the day you are on, or if one of them spawns in your world.

This mod also includes the "Easy Vending Machine", an example vending machine that sells health and mana potions that is coded completely without an equivalent NPC.


Creating your own Vending Machine
This mod is meant as an easy-to-use Framework for anyone wishing to implement their own Vending Machines. To create one, you need to include this mod as a dependency on your mod build.txt. Feel free to use any of the provided graphics and code as reference. To decompile the mod you need the tModReader from the tModLoader thread.


  • Create a new class inheriting the VendingMachineItem class.
  • On that item's SetDefaults, include the following lines:
    hasShop = true;
    npcType = SoulOfNPC.ItemToTag(item);
  • On that same class, create a method
    "public override bool SetupShop(Item[] shop)"
  • fill it with your shop's contents, same as a NPC setupShop method.
You need to create a item image for this item, but feel free to use the one provided in the mod to match with the vending machine tile.

  • Create a new class inheriting the VendingMachineItem class.
  • On that item's SetDefaults, include the following lines:
    item.createTile = mod.TileType<*your vending machine Tile>();
    hasShop = true;
    npcType = SoulOfNPC.ItemToTag(item);
  • On that same class, create a method
    "public override bool SetupShop(Item[] shop)"
  • fill it with your shop's contents, same as a NPC setupShop method.
  • Create a new class inheriting the VendingMachine (Tile) Class
  • write
    public override void SetDefaults()
    {
    base.SetDefaults();
    dropID = mod.ItemType<*Your Vending machine Item Type here*>();
    }

  • (Optional) If you want to change the tile style from 3x4 to something else, write
    "public override void VendingMachineTileStyle()"
    and then fill in the "TileObjectData.newTile" fields. DO NOT USE TileObjectData.newTile.addTile. The base does that for you.
  • (Optional) If you want to change what shows on the map when you hover over the tile, write
    public override void VendingMachineMapEntry()
    {
    base.AddMapEntry(new Microsoft.Xna.Framework.Color(*your r, g, b*), "*your name to show*");
    }

  • (*Really* Optional) Change the Mouse Over/ Mouse Over Far methods to display something entirely different. By default (no change required) the method displays the Item Name of your vending machine item.
Don't forget to create your own tile/Item images if using this method.

To end, here's the mod and source code for those who cannot open the mod with tModReader. I would prefer if you download the mod from the browser, however, as this one might not be always up to date.
nice job dude , you keep getting better
 
Dang! You and me have the same idea. Don't be mad if I happen to implement this, I've been discussing it among friends for a week plus now. Even our implementations are similar, ehe. Good job!
 
Updated mod to 1.2. Here's the Changelog:
- Soul extractor can now kill Vanilla Bound NPCs (and Tortured Soul Tax collector) and extract their Town NPC soul (exception being the Old Man/Clothier, for Reasons).
- Added ATM (tax collector machine), Hair Dryer (Stylist hair styling machine) and Dye Ball Machine (Dye Trader Strange Plant trading).
 
So how does this work with the guide vending machine when you summon the wall of flesh? Does it just say the guide died and the vending machine continues to exist?

Edit: nvm found out that new npcs keep spawning regardless if they have a vending machine equivalent already
 
Last edited:
@Zauber Paracelsus there is a skeleton merchant vending machine. im using one right now in my server.

@JPAN Now sure how much support this mod has with fargos mutant mod but the vending machine for his boss summon item selling npc only shows prehardmode or hard mode summon items based on which one you looked at last from the actual npc. he has 2 different options to click on when you talk to him to open 2 different purchase windows
 
Ok, preliminary update to tmod 0.10 up on browser. I will re-update this mod later if the update broke mod compatibility. I will not update the thread version so people on 0.9+ can still download it here. When 0.10 is older, I will update the main post with it.
 
Ok, preliminary update to tmod 0.10 up on browser. I will re-update this mod later if the update broke mod compatibility. I will not update the thread version so people on 0.9+ can still download it here. When 0.10 is older, I will update the main post with it.

Could you include on your mod the traveling merchant and skeleton merchant vending machines?
 
@Roxxz as far as i know they are already in there. I played this before 1.3.5 and all you had to do was kill them with the sword and use their souls in the crafting recipe to make their respective vending machines
 
@Roxxz as far as i know they are already in there. I played this before 1.3.5 and all you had to do was kill them with the sword and use their souls in the crafting recipe to make their respective vending machines

Using the cheatsheet I was able to see all the available vending machines those did not include merchant and skeleton.
 
Using the cheatsheet I was able to see all the available vending machines those did not include merchant and skeleton.

i get that, i have a crafting recipe mod that shows me all available crafting recipes in the game, modded included, and it wasn't on there either. I just followed the mod authors original post instructions on how to make the vending machines and it does work. Just try it
 
Back
Top Bottom