added main files

master
Red_King_Cyclops 2019-11-03 13:35:24 +00:00
parent 20fc031e6d
commit df6dd5f322
5 changed files with 99 additions and 0 deletions

84
api.lua Normal file
View File

@ -0,0 +1,84 @@
adventure_vendors = {}
function adventure_vendors.register_vendor(name, desc, giveStackName, giveStackCount, receiveStackName, receiveStackCount)
minetest.register_node("adventure_vendors:" .. name, {
description = "Adventure Vendor\n" .. desc,
tiles = {"adventure_vendor_vending_machine_face.png"},
tiles = {
"adventure_vendor_vending_machine_side.png", -- y+
"adventure_vendor_vending_machine_side.png", -- y-
"adventure_vendor_vending_machine_side.png", -- x+
"adventure_vendor_vending_machine_side.png", -- x-
"adventure_vendor_vending_machine_side.png", -- z+
"adventure_vendor_vending_machine_face.png", -- z-
},
is_ground_content = false,
groups = {cracky=3},
paramtype2 = "facedir",
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
if itemstack:get_name() == giveStackName and itemstack:get_count() >= giveStackCount then
local inv = player:get_inventory()
local taken = itemstack:take_item(giveStackCount)
local added = inv:add_item("main", ItemStack({name = receiveStackName, count = receiveStackCount}))
minetest.chat_send_player(player:get_player_name(), "Your purchase was successful.")
else
if itemstack:get_count() == 0 then
minetest.chat_send_player(player:get_player_name(), desc)
else
minetest.chat_send_player(player:get_player_name(), "You are not holding the required item and/or you are not holding enough for the purchase.")
end
end
end
})
end
--[[
--------------------------------------------------
--local inv = player:get_inventory()
--local stack = ItemStack("default:stone 99")
--local taken = inv:remove_item("main", stack)
--local stack2 = ItemStack("default:diamond 1")
--local added = inv:add_item("main", stack2)
--if itemstack:item_fits({name = "default:stone"}) then
--itemstack:add_item({name = "default:stone"})
--Trash
------------------------------------------------------
if(1==0) --trash
then
local inv = player:get_inventory()
local notenough = false
for i = 0,#givestacks - 1,1
do
local givestack = ItemStack(givestacks[i])
--local added = inv:set_stack("main", 0, givestack) --test
if(not inv.contains_item("main", getstack))
then
notenough = true
end
end
if(notenough == false)
then
for i = 0,#givestacks - 1,1
do
local givestack = ItemStack(givestacks[i])
local taken = inv:take_item("main", givestack)
end
for i = 0,#receivestacks - 1,1
do
local receivestack = ItemStack(receivestacks[i])
local added = inv:add_item("main", receivestack)
end
minetest.chat_send_player(player:get_player_name(), "Your purchase was successful.")
else
minetest.chat_send_player(player:get_player_name(), "You do not have all the required items for the purchase.")
end
end --trash end
]]

2
init.lua Normal file
View File

@ -0,0 +1,2 @@
dofile(minetest.get_modpath("adventure_vendors") .. "/api.lua")
dofile(minetest.get_modpath("adventure_vendors") .. "/vendors.lua")

3
mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = adventure_vendors
description = Adds in simple vending machines for adventure maps instead of servers. To create a vending machine, one must use the API.
optional_depends = default

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

10
vendors.lua Normal file
View File

@ -0,0 +1,10 @@
--params:
--adventure_vendors.register_vendor(TECHNICAL_NAME (string with no spaces), DESCRIPTION (string), ITEM_NAME_YOU_SELL (string with no spaces), NUMBER_OF_ITEM_NAME_YOU_SELL (integer), ITEM_NAME_YOU_BUY (string with no spaces), NUMBER_OF_ITEM_NAME_YOU_BUY (integer))
--Examples
if(minetest.get_modpath("default")) ~= nil then
adventure_vendors.register_vendor("coal_lump_99_for_diamond_1", "Purchase 1 diamond for 99 coal lumps.", "default:coal_lump", 99, "default:diamond", 1)
adventure_vendors.register_vendor("gold_ingot_5_for_diamond_sword_1", "Purchase 1 diamond sword for 5 gold ingots.", "default:gold_ingot", 5, "default:sword_diamond", 1)
adventure_vendors.register_vendor("iron_ingot_2_for_dirt_99", "Purchase 99 blocks of dirt for 2 iron ingots.", "default:steel_ingot", 2, "default:dirt", 99)
end
--Add your own below (the entire point of this mod)