Updated money mod with kilbith's fork

- (nothing interesting, just little syntax fix, and new textures)
This commit is contained in:
LeMagnesium 2015-07-02 19:34:54 +02:00
parent 0fa535ac68
commit 8acd6b66b9
17 changed files with 150 additions and 682 deletions

View File

@ -1,13 +1,30 @@
Minetest 0.4 mod: money
=======================
Minetest mod : money
====================
This mod adds commerce in Minetest.
Commands for players (requires "money" privilege) :
/money — gets the balance of your account
/money pay <account> <amount> — transfers <amount> money to <account>
Commands for administrators (requires "money_admin" privilege) :
/money <account> — gets balance of <account>
/money set <account> <amount> — sets balance of <account> in <amount> money
/money inc <account> <amount> — increases <amount> money to balance of <account>
/money dec <account> <amount> — decreases <amount> money from balance of <account>
/money take <account> <amount> — takes off <amount> money from balance of <account>
Also, this mod adds 2 kinds of shops:
- Simple shop
- Admin shop (no recipe)
This can be found in:
https://github.com/kotolegokot/minetest-mod-money
License of source code
----------------------
-----------------------------
Copyright (C) 2012 kotolegokot, Oleg Matveev <gkotolegokot@gmail.com>
See README.txt in each mod directory for information about other authors.
- Modified by kilbith and nerzhul (2015)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -23,11 +40,6 @@ You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
License of media (textures and sounds)
--------------------------------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
http://creativecommons.org/licenses/by-sa/3.0/
Authors of media files
-----------------------
Copyright (C) 2012 kotolegokot, Oleg Matveev <gkotolegokot@gmail.com>
License of textures
--------------------------
WTFPL (kilbith)

View File

@ -1,2 +1,2 @@
default
locked_sign
itemframes?

View File

@ -1,21 +1,20 @@
--[[
Mod by kotolegokot
Version 2012.8.12.0
Mod by Kotolegokot and Xiong (2012-2013)
Rev. kilbith and nerzhul (2015)
]]
dofile(minetest.get_modpath("money") .. "/settings.txt") --Loading settings.
money = {}
dofile(minetest.get_modpath("money") .. "/settings.txt") -- Loading settings.
dofile(minetest.get_modpath("money") .. "/hud.lua") -- Account display in HUD.
--Loading accounts
local accounts = {}
local input = io.open(minetest.get_worldpath() .. "/accounts", "r")
if input then
accounts = minetest.deserialize(input:read("*l"))
io.close(input)
end
--End
--Global functions.
money = {}
function money.save_accounts()
local output = io.open(minetest.get_worldpath() .. "/accounts", "w")
output:write(minetest.serialize(accounts))
@ -23,40 +22,27 @@ function money.save_accounts()
end
function money.set_money(name, amount)
accounts[name].money = amount
if money.hud[name] ~= nil then
money.hud_change(name)
end
money.save_accounts()
end
function money.get_money(name)
return accounts[name].money
end
function money.freeze(name)
accounts[name].frozen = true
money.save_accounts()
end
function money.unfreeze(name)
accounts[name].frozen = false
money.save_accounts()
end
function money.is_frozen(name)
return accounts[name].frozen or false
end
function money.exist(name)
return accounts[name] ~= nil
end
--End.
--Local functions
local save_accounts = money.save_accounts
local set_money = money.set_money
local get_money = money.get_money
local freeze = money.freeze
local unfreeze = money.unfreeze
local is_frozen = money.is_frozen
local exist = money.exist
--End.
--Creates player's account, if the player doesn't have it.
--[[ minetest.register_on_joinplayer(function(player)
name = player:get_player_name()
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
if not exist(name) then
local input = io.open(minetest.get_worldpath() .. "/money_" .. name .. ".txt") --For compatible with old versions.
if input then
@ -69,29 +55,31 @@ local exist = money.exist
accounts[name] = {money = INITIAL_MONEY}
end
end
end) --]]
money.hud_add(name)
end) --]]
--End.
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
money.hud[name] = nil
end)
--Registration privileges.
--[[minetest.register_privilege("money", "Can use /money [pay <account> <amount>] command")
minetest.register_privilege("money_admin", {
description = "Can use /money <account> | freeze/unfreeze <account> | take/set/inc/dec <account> <amount>",
description = "Can use /money <account> | take/set/inc/dec <account> <amount>",
give_to_singleplayer = false,
})--]]
--End.
--Registration "money" command.
--[[Registration "money" command.
--[[ minetest.register_chatcommand("money", {
privs = {money=true},
params = "[<account> | freeze/unfreeze <account> | pay/take/set/inc/dec <account> <amount>]",
params = "[<account> | pay/take/set/inc/dec <account> <amount>]",
description = "Operations with money",
func = function(name, param)
func = function(name, param)
if param == "" then --/money
minetest.chat_send_player(name, "Account " .. name .. ":")
minetest.chat_send_player(name, " money: " .. CURRENCY_PREFIX .. get_money(name) .. CURRENCY_POSTFIX .. ";")
local is_f = "no"
if is_frozen(name) then is_f = "yes" end
minetest.chat_send_player(name, " is frozen: " .. is_f .. ".")
minetest.chat_send_player(name, "My money account : " .. CURRENCY_PREFIX .. get_money(name) .. CURRENCY_POSTFIX)
return true
end
local m = string.split(param, " ")
@ -99,39 +87,15 @@ minetest.register_privilege("money_admin", {
if param1 and not param2 then --/money <account>
if minetest.get_player_privs(name)["money_admin"] then
if exist(param1) then
minetest.chat_send_player(name, "Account " .. param1 .. ":")
minetest.chat_send_player(name, " money: " .. CURRENCY_PREFIX .. get_money(param1) .. CURRENCY_POSTFIX .. ";")
local is_f = "no"
if is_frozen(name) then is_f = "yes" end
minetest.chat_send_player(name, " is frozen: " .. is_f .. ".")
minetest.chat_send_player(name, "Account of player '" .. param1 .. "' : " .. CURRENCY_PREFIX .. get_money(param1) .. CURRENCY_POSTFIX)
else
minetest.chat_send_player(name, "\"" .. param1 .. "\" account don't exist.")
end
else
minetest.chat_send_player(name, "You don't have permission to run this command (missing privileges: money_admin)")
minetest.chat_send_player(name, "You don't have permission to run this command (missing privilege: money_admin)")
end
return true
end
if param1 and param2 and not param3 then --/money freeze/unfreeze <account>
if param1 == "freeze" or param1 == "unfreeze" then
if minetest.get_player_privs(name)["money_admin"] then
if exist(param2) then
if param1 == "freeze" then
freeze(param2)
minetest.chat_send_player(name, "\"" .. param2 .. "\" account is frozen.")
else
unfreeze(param2)
minetest.chat_send_player(name, "\"" .. param2 .. "\" account isn't frozen.")
end
else
minetest.chat_send_player(name, "\"" .. param2 .. "\" account don't exist.")
end
return true
else
minetest.chat_send_player(name, "You don't have permission to run this command (missing privileges: money_admin)")
end
end
end
if param1 and param2 and param3 then --/money pay/take/set/inc/dec <account> <amount>
if param1 == "pay" or param1 == "take" or param1 == "set" or param1 == "inc" or param1 == "dec" then
if exist(param2) then
@ -139,28 +103,17 @@ minetest.register_privilege("money_admin", {
if tonumber(param3) >= 0 then
param3 = tonumber(param3)
if param1 == "pay" then
if not is_frozen(name) then
if not is_frozen(param2) then
if get_money(name) >= param3 then
set_money(param2, get_money(param2) + param3)
set_money(name, get_money(name) - param3)
minetest.chat_send_player(param2, name .. " sent you " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
minetest.chat_send_player(name, param2 .. " took your " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
else
minetest.chat_send_player(name, "You don't have enough " .. CURRENCY_PREFIX .. amount - get_money(name) .. CURRENCY_POSTFIX .. ".")
end
else
minetest.chat_send_player(name, "\"" .. param2 .. "\" account is frozen.")
end
if get_money(name) >= param3 then
set_money(param2, get_money(param2) + param3)
set_money(name, get_money(name) - param3)
minetest.chat_send_player(param2, name .. " sent you " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
minetest.chat_send_player(name, param2 .. " took your " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
else
minetest.chat_send_player(name, "Your account is frozen.")
minetest.chat_send_player(name, "You don't have " .. CURRENCY_PREFIX .. param3 - get_money(name) .. CURRENCY_POSTFIX .. ".")
end
return true
end
if minetest.get_player_privs(name)["money_admin"] then
if is_frozen(param2) then
minetest.chat_send_player(name, "Note: \"" .. param2 .. "\" account is frozen.")
end
if param1 == "take" then
if get_money(param2) >= param3 then
set_money(param2, get_money(param2) - param3)
@ -211,33 +164,34 @@ end
--Shop.
minetest.register_node("money:shop", {
description = "Shop",
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
"default_chest_side.png", "default_chest_side.png", "money_shop_front.png"},
tiles = {"shop.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", "Untuned Shop (owned by " .. placer:get_player_name() .. ")")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[8,6.6]"..
"field[0.256,0.5;8,1;shopname;Name of your shop:;]"..
"field[0.256,1.5;8,1;action;Do you want buy(B) or sell(S) or buy and sell(BS):;]"..
"field[0.256,2.5;8,1;nodename;Name of node, that you want buy or/and sell:;]"..
"field[0.256,3.5;8,1;amount;Amount of these nodes:;]"..
"field[0.256,4.5;8,1;costbuy;Cost of purchase, if you buy nodes:;]"..
"field[0.256,5.5;8,1;costsell;Cost of sales, if you sell nodes:;]"..
"button_exit[3.1,6;2,1;button;Proceed]")
meta:set_string("formspec", "size[6,5]"..default.gui_bg..default.gui_bg_img..
"field[0.256,0.5;6,1;shopname;Name of your shop;]"..
"label[-0.025,1.03;Trade Type]"..
"dropdown[-0.025,1.45;2.5,1;action;Sell,Buy,Buy and Sell;]"..
"field[2.7,1.7;3.55,1;amount;Trade lot quantity (1-99);]"..
"field[0.256,2.85;6,1;nodename;Node name to trade (eg. default:mese);]"..
"field[0.256,4;3,1;costbuy;Buying price (per lot);]"..
"field[3.25,4;3,1;costsell;Selling price (per lot);]"..
"button_exit[2,4.5;2,1;button;Tune]")
meta:set_string("infotext", "Untuned Shop")
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
inv:set_size("main", 32)
meta:set_string("form", "yes")
end,
can_dig = function(pos,player)
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and (meta:get_string("owner") == player:get_player_name() or minetest.get_player_privs(player:get_player_name())["money_admin"])
@ -245,10 +199,9 @@ minetest.register_node("money:shop", {
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if not has_shop_privilege(meta, player) then
minetest.log("action", player:get_player_name()..
" tried to access a shop belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
minetest.log("action", player:get_player_name().." tried to access a shop belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
return 0
end
return count
@ -256,15 +209,14 @@ minetest.register_node("money:shop", {
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not has_shop_privilege(meta, player) then
minetest.log("action", player:get_player_name()..
" tried to access a shop belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
minetest.log("action", player:get_player_name().." tried to access a shop belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not has_shop_privilege(meta, player) then
minetest.log("action", player:get_player_name()..
@ -275,23 +227,20 @@ minetest.register_node("money:shop", {
end
return stack:get_count()
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()..
" moves stuff in shop at "..minetest.pos_to_string(pos))
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name().." moves stuff in shop at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" moves stuff to shop at "..minetest.pos_to_string(pos))
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name().." moves stuff to shop at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, count, player)
minetest.log("action", player:get_player_name()..
" takes stuff from shop at "..minetest.pos_to_string(pos))
on_metadata_inventory_take = function(pos, listname, index, count, player)
minetest.log("action", player:get_player_name().." takes stuff from shop at "..minetest.pos_to_string(pos))
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if meta:get_string("form") == "yes" then
if fields.shopname ~= "" and (fields.action == "B" or fields.action == "S" or fields.action == "BS") and minetest.registered_items[fields.nodename] and tonumber(fields.amount) and tonumber(fields.amount) >= 1 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
if fields.action == "B" then
if fields.shopname ~= "" and minetest.registered_items[fields.nodename] and tonumber(fields.amount) and tonumber(fields.amount) >= 1 and tonumber(fields.amount) <= 99 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
if fields.action == "Sell" then
if not tonumber(fields.costbuy) then
return
end
@ -299,7 +248,7 @@ minetest.register_node("money:shop", {
return
end
end
if fields.action == "S" then
if fields.action == "Buy" then
if not tonumber(fields.costsell) then
return
end
@ -307,7 +256,7 @@ minetest.register_node("money:shop", {
return
end
end
if fields.action == "BS" then
if fields.action == "Buy and Sell" then
if not tonumber(fields.costbuy) then
return
end
@ -322,27 +271,28 @@ minetest.register_node("money:shop", {
end
end
local s, ss
if fields.action == "B" then
if fields.action == "Sell" then
s = " sell "
ss = "button[1,5;2,1;buttonsell;Sell("..fields.costbuy..")]"
elseif fields.action == "S" then
ss = "button[1,4.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
elseif fields.action == "Buy" then
s = " buy "
ss = "button[1,5;2,1;buttonbuy;Buy("..fields.costsell..")]"
ss = "button[1,4.5;2,1;buttonbuy;Buy("..fields.costsell..")]"
else
s = " buy and sell "
ss = "button[1,5;2,1;buttonbuy;Buy("..fields.costsell..")]" .. "button[5,5;2,1;buttonsell;Sell("..fields.costbuy..")]"
ss = "button[1,4.5;2,1;buttonbuy;Buy("..fields.costsell..")]" .. "button[5,4.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
end
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[8,10;]"..
meta:set_string("formspec", "size[8,9.35;]"..default.gui_bg..default.gui_bg_img..
"list[context;main;0,0;8,4;]"..
"label[0.256,4.5;You can"..s..fields.amount.." "..fields.nodename.."]"..
ss..
"list[current_player;main;0,6;8,4;]")
"label[1.5,4;You can"..s..fields.amount.." "..fields.nodename.."]"..
ss..
"list[current_player;main;0,5.5;8,4;]")
meta:set_string("shopname", fields.shopname)
meta:set_string("action", fields.action)
meta:set_string("nodename", fields.nodename)
meta:set_string("amount", fields.amount)
meta:set_string("costbuy", fields.costsell)
meta:set_string("costsell", fields.costbuy)
meta:set_string("costbuy", fields.costbuy)
meta:set_string("costsell", fields.costsell)
meta:set_string("infotext", "Shop \"" .. fields.shopname .. "\" (owned by " .. meta:get_string("owner") .. ")")
meta:set_string("form", "no")
end
@ -351,20 +301,23 @@ minetest.register_node("money:shop", {
local inv = meta:get_inventory()
local sender_inv = sender:get_inventory()
if not inv:contains_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "In the shop is not enough goods.")
minetest.chat_send_player(sender_name, "Not enough goods in the shop.")
return true
elseif not sender_inv:room_for_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "In your inventory is not enough space.")
minetest.chat_send_player(sender_name, "Not enough space in your inventory.")
return true
elseif get_money(sender_name) - tonumber(meta:get_string("costbuy")) < 0 then
minetest.chat_send_player(sender_name, "You do not have enough money.")
elseif get_money(sender_name) - tonumber(meta:get_string("costsell")) < 0 then
minetest.chat_send_player(sender_name, "You don't have enough money.")
return true
elseif not exist(meta:get_string("owner")) then
minetest.chat_send_player(sender_name, "The owner's account does not currently exist; try again later.")
return true
end
set_money(sender_name, get_money(sender_name) - meta:get_string("costbuy"))
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) + meta:get_string("costbuy"))
set_money(sender_name, get_money(sender_name) - meta:get_string("costsell"))
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) + meta:get_string("costsell"))
sender_inv:add_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
inv:remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
minetest.chat_send_player(sender_name, "You bought " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costbuy") .. CURRENCY_POSTFIX .. ".")
minetest.chat_send_player(sender_name, "You bought " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costsell") .. CURRENCY_POSTFIX .. ".")
elseif fields["buttonsell"] then
local sender_name = sender:get_player_name()
local inv = meta:get_inventory()
@ -373,27 +326,30 @@ minetest.register_node("money:shop", {
minetest.chat_send_player(sender_name, "You do not have enough product.")
return true
elseif not inv:room_for_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "In the shop is not enough space.")
minetest.chat_send_player(sender_name, "Not enough space in the shop.")
return true
elseif get_money(meta:get_string("owner")) - meta:get_string("costsell") < 0 then
elseif get_money(meta:get_string("owner")) - meta:get_string("costbuy") < 0 then
minetest.chat_send_player(sender_name, "The buyer is not enough money.")
return true
elseif not exist(meta:get_string("owner")) then
minetest.chat_send_player(sender_name, "The owner's account does not currently exist; try again later.")
return true
end
set_money(sender_name, get_money(sender_name) + meta:get_string("costsell"))
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) - meta:get_string("costsell"))
set_money(sender_name, get_money(sender_name) + meta:get_string("costbuy"))
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) - meta:get_string("costbuy"))
sender_inv:remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
inv:add_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
minetest.chat_send_player(sender_name, "You sold " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costsell") .. CURRENCY_POSTFIX .. ".")
minetest.chat_send_player(sender_name, "You sold " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costbuy") .. CURRENCY_POSTFIX .. ".")
end
end,
})
--End.
})
minetest.register_craft({--Shop recipe.
minetest.register_craft({
output = "money:shop",
recipe = {
{"default:chest_locked"},
{"locked_sign:sign_wall_locked"},
{"default:wood", "default:wood", "default:wood"},
{"default:wood", "default:mese", "default:wood"},
{"default:wood", "default:wood", "default:wood"},
},
})
@ -531,24 +487,26 @@ minetest.register_craft({--Barter shop recipe.
minetest.register_alias("barter_shop", "money:barter_shop")
--Admin shop.
minetest.register_node("money:admin_shop", {
description = "Admin Shop",
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
"default_chest_side.png", "default_chest_side.png", "money_admin_shop_front.png"},
tiles = {"admin_shop.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Untuned Admin Shop")
meta:set_string("formspec", "size[8,5.6]"..
"field[0.256,0.5;8,1;action;Do you want buy(B) or sell(S) or buy and sell(BS):;]"..
"field[0.256,1.5;8,1;nodename;Name of node, that you want buy or/and sell:;]"..
"field[0.256,2.5;8,1;amount;Amount of these nodes:;]"..
"field[0.256,3.5;8,1;costbuy;Cost of purchase, if you buy nodes:;]"..
"field[0.256,4.5;8,1;costsell;Cost of sales, if you sell nodes:;]"..
"button_exit[3.1,5;2,1;button;Proceed]")
meta:set_string("formspec", "size[6,3.75]"..default.gui_bg..default.gui_bg_img..
"label[-0.025,-0.2;Trade Type]"..
"dropdown[-0.025,0.25;2.5,1;action;Sell,Buy,Buy and Sell;]"..
"field[2.7,0.48;3.55,1;amount;Trade lot quantity (1-99);]"..
"field[0.256,1.65;5.2,1;nodename;Node name to trade (eg. default:mese);]"..
"item_image[5,1.25;1,1;default:diamond]" ..
"field[0.256,2.75;3,1;costbuy;Buying price (per lot);]"..
"field[3.25,2.75;3,1;costsell;Selling price (per lot);]"..
"button_exit[2,3.25;2,1;button;Proceed]")
meta:set_string("form", "yes")
end,
can_dig = function(pos,player)
@ -557,8 +515,8 @@ minetest.register_node("money:admin_shop", {
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if meta:get_string("form") == "yes" then
if (fields.action == "B" or fields.action == "S" or fields.action == "BS") and minetest.registered_items[fields.nodename] and tonumber(fields.amount) and tonumber(fields.amount) >= 1 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
if fields.action == "B" then
if minetest.registered_items[fields.nodename] and tonumber(fields.amount) and tonumber(fields.amount) >= 1 and tonumber(fields.amount) <= 99 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
if fields.action == "Sell" then
if not tonumber(fields.costbuy) then
return
end
@ -566,7 +524,7 @@ minetest.register_node("money:admin_shop", {
return
end
end
if fields.action == "S" then
if fields.action == "Buy" then
if not tonumber(fields.costsell) then
return
end
@ -574,7 +532,7 @@ minetest.register_node("money:admin_shop", {
return
end
end
if fields.action == "BS" then
if fields.action == "Buy and Sell" then
if not tonumber(fields.costbuy) then
return
end
@ -589,10 +547,10 @@ minetest.register_node("money:admin_shop", {
end
end
local s, ss
if fields.action == "B" then
if fields.action == "Sell" then
s = " sell "
ss = "button[1,0.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
elseif fields.action == "S" then
elseif fields.action == "Buy" then
s = " buy "
ss = "button[1,0.5;2,1;buttonbuy;Buy("..fields.costsell..")]"
else
@ -600,7 +558,7 @@ minetest.register_node("money:admin_shop", {
ss = "button[1,0.5;2,1;buttonbuy;Buy("..fields.costsell..")]" .. "button[5,0.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
end
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[8,5.5;]"..
meta:set_string("formspec", "size[8,5.5;]"..default.gui_bg..default.gui_bg_img..
"label[0.256,0;You can"..s..fields.amount.." "..fields.nodename.."]"..
ss..
"list[current_player;main;0,1.5;8,4;]")
@ -616,10 +574,10 @@ minetest.register_node("money:admin_shop", {
local sender_inv = sender:get_inventory()
if not sender_inv:room_for_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "In your inventory is not enough space.")
return true
return true
elseif get_money(sender_name) - tonumber(meta:get_string("costbuy")) < 0 then
minetest.chat_send_player(sender_name, "You do not have enough money.")
return true
return true
end
set_money(sender_name, get_money(sender_name) - meta:get_string("costbuy"))
sender_inv:add_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
@ -628,12 +586,11 @@ minetest.register_node("money:admin_shop", {
local sender_name = sender:get_player_name()
local sender_inv = sender:get_inventory()
if not sender_inv:contains_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "You do not have enough product.")
minetest.chat_send_player(sender_name, "You don't have enough product.")
return true
end
set_money(sender_name, get_money(sender_name) + meta:get_string("costsell"))
sender_inv:remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
minetest.chat_send_player(sender_name, "You sold " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costsell") .. CURRENCY_POSTFIX .. ".")
end
end,
})
@ -691,9 +648,11 @@ minetest.register_node("money:admin_barter_shop", {
sender_inv:remove_item("main", meta:get_string("nodename2") .. " " .. meta:get_string("amount2"))
sender_inv:add_item("main", meta:get_string("nodename1") .. " " .. meta:get_string("amount1"))
minetest.chat_send_player(sender_name, "You exchanged " .. meta:get_string("amount2") .. " " .. meta:get_string("nodename2") .. " on " .. meta:get_string("amount1") .. " " .. meta:get_string("nodename1") .. ".")
minetest.chat_send_player(sender_name, "You sold " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costsell") .. CURRENCY_POSTFIX .. ".")
end
end,
})
--End.
minetest.register_alias("admin_barter_shop", "money:admin_barter_shop")

View File

@ -1,45 +0,0 @@
Minetest mod : money
====================
This mod adds commerce in Minetest.
Commands for players (requires "money" privilege) :
/money — gets the balance of your account
/money pay <account> <amount> — transfers <amount> money to <account>
Commands for administrators (requires "money_admin" privilege) :
/money <account> — gets balance of <account>
/money set <account> <amount> — sets balance of <account> in <amount> money
/money inc <account> <amount> — increases <amount> money to balance of <account>
/money dec <account> <amount> — decreases <amount> money from balance of <account>
/money take <account> <amount> — takes off <amount> money from balance of <account>
Also, this mod adds 2 kinds of shops:
- Simple shop
- Admin shop (no recipe)
This can be found in:
https://github.com/kotolegokot/minetest-mod-money
License of source code
-----------------------------
Copyright (C) 2012 kotolegokot, Oleg Matveev <gkotolegokot@gmail.com>
- Modified by kilbith and nerzhul (2015)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
License of textures
--------------------------
WTFPL (kilbith)

View File

@ -1,2 +0,0 @@
default
itemframes?

View File

@ -1,454 +0,0 @@
--[[
Mod by Kotolegokot and Xiong (2012-2013)
Rev. kilbith and nerzhul (2015)
]]
money = {}
dofile(minetest.get_modpath("money") .. "/settings.txt") -- Loading settings.
dofile(minetest.get_modpath("money") .. "/hud.lua") -- Account display in HUD.
local accounts = {}
local input = io.open(minetest.get_worldpath() .. "/accounts", "r")
if input then
accounts = minetest.deserialize(input:read("*l"))
io.close(input)
end
function money.save_accounts()
local output = io.open(minetest.get_worldpath() .. "/accounts", "w")
output:write(minetest.serialize(accounts))
io.close(output)
end
function money.set_money(name, amount)
accounts[name].money = amount
if money.hud[name] ~= nil then
money.hud_change(name)
end
money.save_accounts()
end
function money.get_money(name)
return accounts[name].money
end
function money.exist(name)
return accounts[name] ~= nil
end
local save_accounts = money.save_accounts
local set_money = money.set_money
local get_money = money.get_money
local exist = money.exist
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
if not exist(name) then
local input = io.open(minetest.get_worldpath() .. "/money_" .. name .. ".txt") --For compatible with old versions.
if input then
local n = input:read("*n")
io.close(input)
accounts[name] = {money = n}
os.remove(minetest.get_worldpath() .. "/money_" .. name .. ".txt")
save_accounts()
else
accounts[name] = {money = INITIAL_MONEY}
end
end
money.hud_add(name)
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
money.hud[name] = nil
end)
minetest.register_privilege("money", "Can use /money [pay <account> <amount>] command")
minetest.register_privilege("money_admin", {
description = "Can use /money <account> | take/set/inc/dec <account> <amount>",
give_to_singleplayer = false,
})
--[[minetest.register_chatcommand("money", {
privs = {money=true},
params = "[<account> | pay/take/set/inc/dec <account> <amount>]",
description = "Operations with money",
func = function(name, param)
if param == "" then --/money
minetest.chat_send_player(name, "My money account : " .. CURRENCY_PREFIX .. get_money(name) .. CURRENCY_POSTFIX)
return true
end
local m = string.split(param, " ")
local param1, param2, param3 = m[1], m[2], m[3]
if param1 and not param2 then --/money <account>
if minetest.get_player_privs(name)["money_admin"] then
if exist(param1) then
minetest.chat_send_player(name, "Account of player '" .. param1 .. "' : " .. CURRENCY_PREFIX .. get_money(param1) .. CURRENCY_POSTFIX)
else
minetest.chat_send_player(name, "\"" .. param1 .. "\" account don't exist.")
end
else
minetest.chat_send_player(name, "You don't have permission to run this command (missing privilege: money_admin)")
end
return true
end
if param1 and param2 and param3 then --/money pay/take/set/inc/dec <account> <amount>
if param1 == "pay" or param1 == "take" or param1 == "set" or param1 == "inc" or param1 == "dec" then
if exist(param2) then
if tonumber(param3) then
if tonumber(param3) >= 0 then
param3 = tonumber(param3)
if param1 == "pay" then
if get_money(name) >= param3 then
set_money(param2, get_money(param2) + param3)
set_money(name, get_money(name) - param3)
minetest.chat_send_player(param2, name .. " sent you " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
minetest.chat_send_player(name, param2 .. " took your " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
else
minetest.chat_send_player(name, "You don't have " .. CURRENCY_PREFIX .. param3 - get_money(name) .. CURRENCY_POSTFIX .. ".")
end
return true
end
if minetest.get_player_privs(name)["money_admin"] then
if param1 == "take" then
if get_money(param2) >= param3 then
set_money(param2, get_money(param2) - param3)
set_money(name, get_money(name) + param3)
minetest.chat_send_player(param2, name .. " took your " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
minetest.chat_send_player(name, "You took " .. param2 .. "'s " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX .. ".")
else
minetest.chat_send_player(name, "Player named \""..param2.."\" do not have enough " .. CURRENCY_PREFIX .. param3 - get_money(player) .. CURRENCY_POSTFIX .. ".")
end
elseif param1 == "set" then
set_money(param2, param3)
minetest.chat_send_player(name, param2 .. " " .. CURRENCY_PREFIX .. param3 .. CURRENCY_POSTFIX)
elseif param1 == "inc" then
set_money(param2, get_money(param2) + param3)
minetest.chat_send_player(name, param2 .. " " .. CURRENCY_PREFIX .. get_money(param2) .. CURRENCY_POSTFIX)
elseif param1 == "dec" then
if get_money(param2) >= param3 then
set_money(param2, get_money(param2) - param3)
minetest.chat_send_player(name, param2 .. " " .. CURRENCY_PREFIX .. get_money(param2) .. CURRENCY_POSTFIX)
else
minetest.chat_send_player(name, "Player named \""..param2.."\" don't have enough " .. CURRENCY_PREFIX .. param3 - get_money(player) .. CURRENCY_POSTFIX .. ".")
end
end
else
minetest.chat_send_player(name, "You don't have permission to run this command (missing privilege: money_admin)")
end
else
minetest.chat_send_player(name, "You must specify a positive amount.")
end
else
minetest.chat_send_player(name, "The amount must be a number.")
end
else
minetest.chat_send_player(name, "\"" .. param2 .. "\" account don't exist.")
end
return true
end
end
minetest.chat_send_player(name, "Invalid parameters (see /help money)")
end,
})]]
local function has_shop_privilege(meta, player)
return player:get_player_name() == meta:get_string("owner") or minetest.get_player_privs(player:get_player_name())["money_admin"]
end
minetest.register_node("money:shop", {
description = "Shop",
tiles = {"shop.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", "Untuned Shop (owned by " .. placer:get_player_name() .. ")")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[6,5]"..default.gui_bg..default.gui_bg_img..
"field[0.256,0.5;6,1;shopname;Name of your shop;]"..
"label[-0.025,1.03;Trade Type]"..
"dropdown[-0.025,1.45;2.5,1;action;Sell,Buy,Buy and Sell;]"..
"field[2.7,1.7;3.55,1;amount;Trade lot quantity (1-99);]"..
"field[0.256,2.85;6,1;nodename;Node name to trade (eg. default:mese);]"..
"field[0.256,4;3,1;costbuy;Buying price (per lot);]"..
"field[3.25,4;3,1;costsell;Selling price (per lot);]"..
"button_exit[2,4.5;2,1;button;Tune]")
meta:set_string("infotext", "Untuned Shop")
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("main", 32)
meta:set_string("form", "yes")
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and (meta:get_string("owner") == player:get_player_name() or minetest.get_player_privs(player:get_player_name())["money_admin"])
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if not has_shop_privilege(meta, player) then
minetest.log("action", player:get_player_name().." tried to access a shop belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
return 0
end
return count
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not has_shop_privilege(meta, player) then
minetest.log("action", player:get_player_name().." tried to access a shop belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not has_shop_privilege(meta, player) then
minetest.log("action", player:get_player_name()..
" tried to access a shop belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
return 0
end
return stack:get_count()
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name().." moves stuff in shop at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name().." moves stuff to shop at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, count, player)
minetest.log("action", player:get_player_name().." takes stuff from shop at "..minetest.pos_to_string(pos))
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if meta:get_string("form") == "yes" then
if fields.shopname ~= "" and minetest.registered_items[fields.nodename] and tonumber(fields.amount) and tonumber(fields.amount) >= 1 and tonumber(fields.amount) <= 99 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
if fields.action == "Sell" then
if not tonumber(fields.costbuy) then
return
end
if not (tonumber(fields.costbuy) >= 0) then
return
end
end
if fields.action == "Buy" then
if not tonumber(fields.costsell) then
return
end
if not (tonumber(fields.costsell) >= 0) then
return
end
end
if fields.action == "Buy and Sell" then
if not tonumber(fields.costbuy) then
return
end
if not (tonumber(fields.costbuy) >= 0) then
return
end
if not tonumber(fields.costsell) then
return
end
if not (tonumber(fields.costsell) >= 0) then
return
end
end
local s, ss
if fields.action == "Sell" then
s = " sell "
ss = "button[1,4.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
elseif fields.action == "Buy" then
s = " buy "
ss = "button[1,4.5;2,1;buttonbuy;Buy("..fields.costsell..")]"
else
s = " buy and sell "
ss = "button[1,4.5;2,1;buttonbuy;Buy("..fields.costsell..")]" .. "button[5,4.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
end
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[8,9.35;]"..default.gui_bg..default.gui_bg_img..
"list[context;main;0,0;8,4;]"..
"label[1.5,4;You can"..s..fields.amount.." "..fields.nodename.."]"..
ss..
"list[current_player;main;0,5.5;8,4;]")
meta:set_string("shopname", fields.shopname)
meta:set_string("action", fields.action)
meta:set_string("nodename", fields.nodename)
meta:set_string("amount", fields.amount)
meta:set_string("costbuy", fields.costbuy)
meta:set_string("costsell", fields.costsell)
meta:set_string("infotext", "Shop \"" .. fields.shopname .. "\" (owned by " .. meta:get_string("owner") .. ")")
meta:set_string("form", "no")
end
elseif fields["buttonbuy"] then
local sender_name = sender:get_player_name()
local inv = meta:get_inventory()
local sender_inv = sender:get_inventory()
if not inv:contains_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "Not enough goods in the shop.")
return true
elseif not sender_inv:room_for_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "Not enough space in your inventory.")
return true
elseif get_money(sender_name) - tonumber(meta:get_string("costsell")) < 0 then
minetest.chat_send_player(sender_name, "You don't have enough money.")
return true
elseif not exist(meta:get_string("owner")) then
minetest.chat_send_player(sender_name, "The owner's account does not currently exist; try again later.")
return true
end
set_money(sender_name, get_money(sender_name) - meta:get_string("costsell"))
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) + meta:get_string("costsell"))
sender_inv:add_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
inv:remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
minetest.chat_send_player(sender_name, "You bought " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costsell") .. CURRENCY_POSTFIX .. ".")
elseif fields["buttonsell"] then
local sender_name = sender:get_player_name()
local inv = meta:get_inventory()
local sender_inv = sender:get_inventory()
if not sender_inv:contains_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "You do not have enough product.")
return true
elseif not inv:room_for_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "Not enough space in the shop.")
return true
elseif get_money(meta:get_string("owner")) - meta:get_string("costbuy") < 0 then
minetest.chat_send_player(sender_name, "The buyer is not enough money.")
return true
elseif not exist(meta:get_string("owner")) then
minetest.chat_send_player(sender_name, "The owner's account does not currently exist; try again later.")
return true
end
set_money(sender_name, get_money(sender_name) + meta:get_string("costbuy"))
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) - meta:get_string("costbuy"))
sender_inv:remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
inv:add_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
minetest.chat_send_player(sender_name, "You sold " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costbuy") .. CURRENCY_POSTFIX .. ".")
end
end,
})
minetest.register_craft({
output = "money:shop",
recipe = {
{"default:wood", "default:wood", "default:wood"},
{"default:wood", "default:mese", "default:wood"},
{"default:wood", "default:wood", "default:wood"},
},
})
--Admin shop.
minetest.register_node("money:admin_shop", {
description = "Admin Shop",
tiles = {"admin_shop.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Untuned Admin Shop")
meta:set_string("formspec", "size[6,3.75]"..default.gui_bg..default.gui_bg_img..
"label[-0.025,-0.2;Trade Type]"..
"dropdown[-0.025,0.25;2.5,1;action;Sell,Buy,Buy and Sell;]"..
"field[2.7,0.48;3.55,1;amount;Trade lot quantity (1-99);]"..
"field[0.256,1.65;5.2,1;nodename;Node name to trade (eg. default:mese);]"..
"item_image[5,1.25;1,1;default:diamond]" ..
"field[0.256,2.75;3,1;costbuy;Buying price (per lot);]"..
"field[3.25,2.75;3,1;costsell;Selling price (per lot);]"..
"button_exit[2,3.25;2,1;button;Proceed]")
meta:set_string("form", "yes")
end,
can_dig = function(pos,player)
return minetest.get_player_privs(player:get_player_name())["money_admin"]
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if meta:get_string("form") == "yes" then
if minetest.registered_items[fields.nodename] and tonumber(fields.amount) and tonumber(fields.amount) >= 1 and tonumber(fields.amount) <= 99 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
if fields.action == "Sell" then
if not tonumber(fields.costbuy) then
return
end
if not (tonumber(fields.costbuy) >= 0) then
return
end
end
if fields.action == "Buy" then
if not tonumber(fields.costsell) then
return
end
if not (tonumber(fields.costsell) >= 0) then
return
end
end
if fields.action == "Buy and Sell" then
if not tonumber(fields.costbuy) then
return
end
if not (tonumber(fields.costbuy) >= 0) then
return
end
if not tonumber(fields.costsell) then
return
end
if not (tonumber(fields.costsell) >= 0) then
return
end
end
local s, ss
if fields.action == "Sell" then
s = " sell "
ss = "button[1,0.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
elseif fields.action == "Buy" then
s = " buy "
ss = "button[1,0.5;2,1;buttonbuy;Buy("..fields.costsell..")]"
else
s = " buy and sell "
ss = "button[1,0.5;2,1;buttonbuy;Buy("..fields.costsell..")]" .. "button[5,0.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
end
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[8,5.5;]"..default.gui_bg..default.gui_bg_img..
"label[0.256,0;You can"..s..fields.amount.." "..fields.nodename.."]"..
ss..
"list[current_player;main;0,1.5;8,4;]")
meta:set_string("nodename", fields.nodename)
meta:set_string("amount", fields.amount)
meta:set_string("costbuy", fields.costsell)
meta:set_string("costsell", fields.costbuy)
meta:set_string("infotext", "Admin Shop")
meta:set_string("form", "no")
end
elseif fields["buttonbuy"] then
local sender_name = sender:get_player_name()
local sender_inv = sender:get_inventory()
if not sender_inv:room_for_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "In your inventory is not enough space.")
return true
elseif get_money(sender_name) - tonumber(meta:get_string("costbuy")) < 0 then
minetest.chat_send_player(sender_name, "You do not have enough money.")
return true
end
set_money(sender_name, get_money(sender_name) - meta:get_string("costbuy"))
sender_inv:add_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
minetest.chat_send_player(sender_name, "You bought " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costbuy") .. CURRENCY_POSTFIX .. ".")
elseif fields["buttonsell"] then
local sender_name = sender:get_player_name()
local sender_inv = sender:get_inventory()
if not sender_inv:contains_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount")) then
minetest.chat_send_player(sender_name, "You don't have enough product.")
return true
end
set_money(sender_name, get_money(sender_name) + meta:get_string("costsell"))
sender_inv:remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
minetest.chat_send_player(sender_name, "You sold " .. meta:get_string("amount") .. " " .. meta:get_string("nodename") .. " at a price of " .. CURRENCY_PREFIX .. meta:get_string("costsell") .. CURRENCY_POSTFIX .. ".")
end
end,
})

View File

@ -1,3 +0,0 @@
INITIAL_MONEY = 1000
CURRENCY_PREFIX = "$"
CURRENCY_POSTFIX = " dollars"

View File

@ -1,3 +1,3 @@
INITIAL_MONEY = 2000
CURRENCY_PREFIX = ""
CURRENCY_POSTFIX = " money"
INITIAL_MONEY = 1000
CURRENCY_PREFIX = "$"
CURRENCY_POSTFIX = " dollars"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 273 B

View File

Before

Width:  |  Height:  |  Size: 288 B

After

Width:  |  Height:  |  Size: 288 B

View File

@ -6,6 +6,7 @@ News de FR - MinetestForFun (Survival - PVP - Hardcore)
/!\ Ajout des classes "Hunter" et "Warrior" qui ne vont plus tarder /!\
---xx/07/2015--- (Remerciements : LeMagnesium/Mg, Obani, mgl512/Le_Docteur, Gael-de-Sailly, crabman77/crabman)
MAJ de "money" (utilisation d'une version plus récente et optimisée, nouvelles textures)
MAJ de "3d_armor" (nombreux bugfixs, ajout d'un paramètre de "poids" augmentant la faim en fonction de l'armure portée, les valeurs seront disponibles sur le site bientôt)
MAJ de "nether" (crashfix de la nourriture du nether)
MAJ de "MFF_game" (ajout en avant-première de la "Dungeon Master's Blood Sword", l'épée la plus puissante du jeu- inflige 10 de dégats et plus résistante que celle en Mithril -, elle sera dans un futur proche accessible uniquement aux joueurs de la classe guerrier)