update money mod
|
@ -1,4 +1,7 @@
|
|||
--Mod by kotolegokot
|
||||
--[[
|
||||
Mod by kotolegokot
|
||||
Version 2012.8.13.0
|
||||
]]
|
||||
function table.contains(table, value)
|
||||
for i = 1, #table do
|
||||
if table[i] == value then
|
||||
|
@ -58,15 +61,6 @@ minetest.register_privilege("tell", {
|
|||
description = "Can use /tell command",
|
||||
give_to_singleplayer = false,
|
||||
})
|
||||
--[[minetest.register_privilege("kick", { TODO
|
||||
description = "Can use /kick command",
|
||||
give_to_singleplayer = false,
|
||||
})
|
||||
minetest.register_privilege("kill", "Can use /kill command")
|
||||
minetest.register_privilege("kill_other", {
|
||||
description = "Can use /kill <player> command",
|
||||
give_to_singleplayer = false,
|
||||
})]]
|
||||
--Commands
|
||||
minetest.register_chatcommand("list", {
|
||||
privs = {list=true},
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
Minetest 0.4 mod: locked_furnace
|
||||
=============================
|
||||
|
||||
This can be found in:
|
||||
https://github.com/kotolegokot/minetest-mods/locked_furnace
|
||||
|
||||
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.
|
||||
|
||||
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 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>
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,267 @@
|
|||
--[[
|
||||
Mod by kotolegokot
|
||||
Version 2012.8.6.0
|
||||
]]
|
||||
local function has_locked_furnace_privilege(meta, player)
|
||||
return player:get_player_name() == meta:get_string("owner") or player:get_player_name() == minetest.setting_get("name")
|
||||
end
|
||||
|
||||
minetest.register_node("locked_furnace:furnace_locked", {
|
||||
description = "Locked Furnace",
|
||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||
"default_furnace_side.png", "default_furnace_side.png", "locked_furnace_furnace_lock_front.png"},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
meta:set_string("infotext", "Locked Furnace (owned by " .. placer:get_player_name() .. ")")
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
||||
meta:set_string("infotext", "Locked Furnace")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return minetest.setting_get("name") == player:get_player_name() or (inv:is_empty("fuel") and inv:is_empty("dst") and inv:is_empty("src"))
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if not has_locked_furnace_privilege(meta, player) then
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" tried to access a locked furnace 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.env:get_meta(pos)
|
||||
if not has_locked_furnace_privilege(meta, player) then
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" tried to access a locked furnace 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.env:get_meta(pos)
|
||||
if not has_locked_furnace_privilege(meta, player) then
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" tried to access a locked furnace 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 locked furnace 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 locked furnace at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from locked furnace at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("locked_furnace:furnace_locked_active", {
|
||||
description = "Locked Furnace",
|
||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||
"default_furnace_side.png", "default_furnace_side.png", "locked_furnace_furnace_lock_front_active.png"},
|
||||
paramtype2 = "facedir",
|
||||
light_source = 8,
|
||||
drop = "locked_furnace:furnace_locked",
|
||||
groups = {cracky=2, not_in_creative_inventory=1},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
meta:set_string("owner", "Locked Furnace (owned by " .. player:get_player_name() .. ")")
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
||||
meta:set_string("infotext", "Locked Furnace");
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return minetest.setting_get("name") == player:get_player_name() or (inv:is_empty("fuel") and inv:is_empty("dst") and inv:is_empty("src"))
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if not has_locked_furnace_privilege(meta, player) then
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" tried to access a locked furnace 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.env:get_meta(pos)
|
||||
if not has_locked_furnace_privilege(meta, player) then
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" tried to access a locked furnace 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.env:get_meta(pos)
|
||||
if not has_locked_furnace_privilege(meta, player) then
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" tried to access a locked furnace 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 locked furnace 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 locked furnace at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from locked furnace at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"locked_furnace:furnace_locked","locked_furnace:furnace_locked_active"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
for i, name in ipairs({
|
||||
"fuel_totaltime",
|
||||
"fuel_time",
|
||||
"src_totaltime",
|
||||
"src_time"
|
||||
}) do
|
||||
if meta:get_string(name) == "" then
|
||||
meta:set_float(name, 0.0)
|
||||
end
|
||||
end
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local srclist = inv:get_list("src")
|
||||
local cooked = nil
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
|
||||
local was_active = false
|
||||
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
was_active = true
|
||||
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
||||
-- check if there's room for output in "dst" list
|
||||
if inv:room_for_item("dst",cooked.item) then
|
||||
-- Put result in "dst" list
|
||||
inv:add_item("dst", cooked.item)
|
||||
-- take stuff from "src" list
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
else
|
||||
print("Could not insert '"..cooked.item.."'")
|
||||
end
|
||||
meta:set_string("src_time", 0)
|
||||
end
|
||||
end
|
||||
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
local percent = math.floor(meta:get_float("fuel_time") /
|
||||
meta:get_float("fuel_totaltime") * 100)
|
||||
meta:set_string("infotext","Furnace active: "..percent.."% (owned by "..meta:get_string("owner")..")")
|
||||
hacky_swap_node(pos,"locked_furnace:furnace_locked_active")
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||
(100-percent)..":default_furnace_fire_fg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
return
|
||||
end
|
||||
|
||||
local fuel = nil
|
||||
local cooked = nil
|
||||
local fuellist = inv:get_list("fuel")
|
||||
local srclist = inv:get_list("src")
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
if fuellist then
|
||||
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||
end
|
||||
|
||||
if fuel.time <= 0 then
|
||||
meta:set_string("infotext","Locked Furnace out of fuel (owned by "..meta:get_string("owner")..")")
|
||||
hacky_swap_node(pos,"locked_furnace:furnace_locked")
|
||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
||||
return
|
||||
end
|
||||
|
||||
if cooked.item:is_empty() then
|
||||
if was_active then
|
||||
meta:set_string("infotext","Locked Furnace is empty (owned by "..meta:get_string("owner")..")")
|
||||
hacky_swap_node(pos,"locked_furnace:furnace_locked")
|
||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
meta:set_string("fuel_totaltime", fuel.time)
|
||||
meta:set_string("fuel_time", 0)
|
||||
|
||||
local stack = inv:get_stack("fuel", 1)
|
||||
stack:take_item()
|
||||
inv:set_stack("fuel", 1, stack)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "locked_furnace:furnace_locked",
|
||||
recipe = {
|
||||
{"default:cobble", "default:cobble", "default:cobble"},
|
||||
{"default:cobble", "default:steel_ingot", "default:cobble"},
|
||||
{"default:cobble", "default:cobble", "default:cobble"},
|
||||
},
|
||||
})
|
After Width: | Height: | Size: 703 B |
After Width: | Height: | Size: 823 B |
|
@ -30,4 +30,4 @@ http://creativecommons.org/licenses/by-sa/3.0/
|
|||
|
||||
Authors of media files
|
||||
-----------------------
|
||||
Copyright (C) 2012 kotolegokot, Oleg Matveev <gkotolegokot@gmail.com>
|
||||
Copyright (C) 2012 kotolegokot, Oleg Matveev <gkotolegokot@gmail.com>
|
|
@ -1,5 +1,7 @@
|
|||
--Mod by kotolegokot
|
||||
|
||||
--[[
|
||||
Mod by kotolegokot
|
||||
Version 2012.8.13.0
|
||||
]]
|
||||
minetest.register_node("locked_sign:sign_wall_locked", {
|
||||
description = "Locked Sign",
|
||||
drawtype = "signlike",
|
||||
|
|
After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 645 B |
|
@ -22,22 +22,12 @@ 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 media (textures and sounds)
|
||||
--------------------------------------
|
||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
|
||||
|
||||
Homepage: http://minetest.net/forum/viewtopic.php?id=2263
|
||||
|
||||
Commands for players (requires "money" privilege):
|
||||
/money — prints the balance of <player>;
|
||||
/money pay <player> <amount> — it transfers <amount> money to <player>.
|
||||
|
||||
Commands for administrators (requires "money_admin" privilege):
|
||||
/money <player> — prints the balance of <player>;
|
||||
/money set <player> <amount> — sets the balance of <player> in <amount> money;
|
||||
/money add <player> <amount> — adds <amount> money to the balance of <player>;
|
||||
/money dec <player> <amount> — takes off <amount> money from the balance of <player>.
|
||||
|
||||
Also, this mod adds shops. To create shop, you should place a locked sign and a locked chest like on the image.
|
||||
Text, that must be on the locked sign: shopname B/S modname:nodename quantity price. For example: MyShop B default:mese 1 150. The player who punch the sign, buy one mese at a price of 150 money. In the chest must be appropriate items.
|
||||
Authors of media files
|
||||
-----------------------
|
||||
Copyright (C) 2012 kotolegokot, Oleg Matveev <gkotolegokot@gmail.com>
|
||||
|
|
|
@ -1,109 +1,213 @@
|
|||
--Mod by kotolegokot
|
||||
dofile(minetest.get_modpath("money") .. "/settings.txt")
|
||||
--[[
|
||||
Mod by kotolegokot
|
||||
Version 2012.8.12.0
|
||||
]]
|
||||
|
||||
local function set_money(name, value)
|
||||
local output = io.open(minetest.get_worldpath() .. "/money_" .. name .. ".txt", "w")
|
||||
output:write(value)
|
||||
dofile(minetest.get_modpath("money") .. "/settings.txt") --Loading settings.
|
||||
|
||||
--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))
|
||||
io.close(output)
|
||||
end
|
||||
|
||||
local function get_money(name)
|
||||
local input = io.open(minetest.get_worldpath() .. "/money_" .. name .. ".txt", "r")
|
||||
if not input then
|
||||
return nil
|
||||
end
|
||||
money = input:read("*n")
|
||||
io.close(input)
|
||||
return money
|
||||
function money.set_money(name, amount)
|
||||
accounts[name].money = amount
|
||||
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()
|
||||
if not get_money(name) then
|
||||
set_money(name, tostring(INITIAL_MONEY))
|
||||
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
|
||||
end)
|
||||
|
||||
minetest.register_privilege("money", "Can use /money [pay <player> <amount>] command")
|
||||
--End.
|
||||
|
||||
--Registration privileges.
|
||||
minetest.register_privilege("money", "Can use /money [pay <account> <amount>] command")
|
||||
minetest.register_privilege("money_admin", {
|
||||
description = "Can use /money [<player> | pay/set/add/dec <player> <amount>] command",
|
||||
description = "Can use /money <account> | freeze/unfreeze <account> | take/set/inc/dec <account> <amount>",
|
||||
give_to_singleplayer = false,
|
||||
})
|
||||
--End.
|
||||
|
||||
--Registration "money" command.
|
||||
minetest.register_chatcommand("money", {
|
||||
privs = {money=true},
|
||||
params = "[<player> | pay/set/add/dec <player> <amount>]",
|
||||
params = "[<account> | freeze/unfreeze <account> | pay/take/set/inc/dec <account> <amount>]",
|
||||
description = "Operations with money",
|
||||
func = function(name, param)
|
||||
if param == "" then
|
||||
minetest.chat_send_player(name, get_money(name) .. MONEY_NAME)
|
||||
else
|
||||
local param1, reciever, amount = string.match(param, "([^ ]+) ([^ ]+) (.+)")
|
||||
if not reciever and not amount then
|
||||
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 .. ".")
|
||||
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 " .. 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 .. ".")
|
||||
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)")
|
||||
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 not get_money(param) then
|
||||
minetest.chat_send_player(name, "Player named \"" .. param .. "\" do not exist or not have an account.")
|
||||
return true
|
||||
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
|
||||
minetest.chat_send_player(name, get_money(param) .. MONEY_NAME)
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(name, "You don't have permission to run this command (missing privileges: money_admin)")
|
||||
end
|
||||
end
|
||||
if (param1 ~= "pay") and (param1 ~= "set") and (param1 ~= "add") and (param1 ~= "dec") or not reciever or not amount then
|
||||
minetest.chat_send_player(name, "Invalid parameters (see /help money)")
|
||||
return true
|
||||
elseif not get_money(reciever) then
|
||||
minetest.chat_send_player(name, "Player named \"" .. reciever .. "\" does not exist or not have account.")
|
||||
return true
|
||||
elseif not tonumber(amount) then
|
||||
minetest.chat_send_player(name, amount .. " is not a number.")
|
||||
return true
|
||||
elseif tonumber(amount) < 0 then
|
||||
minetest.chat_send_player(name, "The amount must be greater than 0.")
|
||||
return true
|
||||
end
|
||||
amount = tonumber(amount)
|
||||
if param1 == "pay" then
|
||||
if get_money(name) < amount then
|
||||
minetest.chat_send_player(name, "You do not have enough " .. amount - get_money(name) .. MONEY_NAME .. ".")
|
||||
return true
|
||||
end
|
||||
set_money(name, get_money(name) - amount)
|
||||
set_money(reciever, get_money(reciever) + amount)
|
||||
minetest.chat_send_player(name, reciever .. " took your " .. amount .. MONEY_NAME)
|
||||
minetest.chat_send_player(reciever, name .. " sent you " .. amount .. MONEY_NAME)
|
||||
elseif minetest.get_player_privs(name)["money_admin"] then
|
||||
if param1 == "add" then
|
||||
newmoney = get_money(reciever) + amount
|
||||
set_money(reciever, newmoney)
|
||||
elseif param1 == "dec" then
|
||||
if amount <= get_money(reciever) then
|
||||
newmoney = get_money(reciever) - amount
|
||||
set_money(reciever, newmoney)
|
||||
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 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
|
||||
else
|
||||
minetest.chat_send_player(name, "Your account is frozen.")
|
||||
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)
|
||||
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 .. param3 .. CURRENCY_POSTFIX)
|
||||
elseif param1 == "dec" then
|
||||
if get_money(param2) >= param3 then
|
||||
set_money(param2, get_money(param2) - param3)
|
||||
else
|
||||
minetest.chat_send_player(name, "Player named \""..param2.."\" do not 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 privileges: money_admin)")
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name, "Amount must be greater than -1.")
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name, reciever .. " has too little money.")
|
||||
minetest.chat_send_player(name, "Amount must be a number.")
|
||||
end
|
||||
elseif param1 == "set" then
|
||||
newmoney = amount
|
||||
set_money(reciever, amount)
|
||||
else
|
||||
minetest.chat_send_player(name, "\"" .. param2 .. "\" account don't exist.")
|
||||
end
|
||||
minetest.chat_send_player(name, reciever .. " " .. newmoney .. MONEY_NAME)
|
||||
else
|
||||
minetest.chat_send_player(name, "You don't have permission to run this command (missing privileges: money_admin)")
|
||||
return true
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(name, "Invalid parameters (see /help money)")
|
||||
end,
|
||||
})
|
||||
--End.
|
||||
|
||||
local function has_shop_privilege(meta, player)
|
||||
if player:get_player_name() == meta:get_string("owner") or minetest.get_player_privs(player:get_player_name())["money_admin"] then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
local function has_shop_privilege(meta, player)--Does player have permissions for this shop?
|
||||
return player:get_player_name() == meta:get_string("owner") or minetest.get_player_privs(player:get_player_name())["money_admin"]
|
||||
end
|
||||
|
||||
--Shop.
|
||||
minetest.register_node("money:shop", {
|
||||
description = "Shop",
|
||||
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
||||
|
@ -118,14 +222,14 @@ minetest.register_node("money:shop", {
|
|||
end,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", "size[8,7]"..
|
||||
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.3,6.5;2,1;button;Proceed]")
|
||||
"button_exit[3.1,6;2,1;button;Proceed]")
|
||||
meta:set_string("infotext", "Untuned Shop")
|
||||
meta:set_string("owner", "")
|
||||
meta:set_string("form", "yes")
|
||||
|
@ -202,19 +306,15 @@ minetest.register_node("money:shop", {
|
|||
end
|
||||
if fields.action == "BS" then
|
||||
if not tonumber(fields.costbuy) then
|
||||
minetest.chat_send_all("2")
|
||||
return
|
||||
end
|
||||
if not (tonumber(fields.costbuy) >= 0) then
|
||||
minetest.chat_send_all("3")
|
||||
return
|
||||
end
|
||||
if not tonumber(fields.costsell) then
|
||||
minetest.chat_send_all("4")
|
||||
return
|
||||
end
|
||||
if not (tonumber(fields.costsell) >= 0) then
|
||||
minetest.chat_send_all("5")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -263,7 +363,7 @@ minetest.register_node("money:shop", {
|
|||
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) + meta:get_string("costbuy"))
|
||||
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 " .. meta:get_string("costbuy") .. MONEY_NAME .. ".")
|
||||
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 inv = meta:get_inventory()
|
||||
|
@ -282,12 +382,13 @@ minetest.register_node("money:shop", {
|
|||
set_money(meta:get_string("owner"), get_money(meta:get_string("owner")) - meta:get_string("costsell"))
|
||||
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 " .. meta:get_string("costsell") .. MONEY_NAME .. ".")
|
||||
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_craft({
|
||||
minetest.register_craft({--Shop recipe.
|
||||
output = "money:shop",
|
||||
recipe = {
|
||||
{"default:chest_locked"},
|
||||
|
@ -297,10 +398,11 @@ minetest.register_craft({
|
|||
|
||||
minetest.register_alias("shop", "money:shop")
|
||||
|
||||
--Barter shop.
|
||||
minetest.register_node("money:barter_shop", {
|
||||
description = "Barter 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"},
|
||||
"default_chest_side.png", "default_chest_side.png", "money_barter_shop_front.png"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
paramtype2 = "facedir",
|
||||
|
@ -311,14 +413,14 @@ minetest.register_node("money:barter_shop", {
|
|||
end,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", "size[8,6]"..
|
||||
meta:set_string("formspec", "size[8,5.6]"..
|
||||
"field[0.256,0.5;8,1;bartershopname;Name of your barter shop:;]"..
|
||||
"field[0.256,1.5;8,1;nodename1;What kind of a node you want to exchange:;]"..
|
||||
"field[0.256,1.5;8,1;nodename1;What kind of a node do you want to exchange:;]"..
|
||||
"field[0.256,2.5;8,1;nodename2;for:;]"..
|
||||
"field[0.256,3.5;8,1;amount1;Amount of first kind of node:;]"..
|
||||
"field[0.256,4.5;8,1;amount2;Amount of second kind of node:;]"..
|
||||
"button_exit[3.3,5.5;2,1;button;Proceed]")
|
||||
meta:set_string("infotext", "Untuned Shop")
|
||||
"button_exit[3.1,5;2,1;button;Proceed]")
|
||||
meta:set_string("infotext", "Untuned Barter Shop")
|
||||
meta:set_string("owner", "")
|
||||
meta:set_string("form", "yes")
|
||||
end,
|
||||
|
@ -376,11 +478,10 @@ minetest.register_node("money:barter_shop", {
|
|||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("form") == "yes" then
|
||||
if fields.bartershopname ~= "" and minetest.registered_items[fields.nodename1] and minetest.registered_items[fields.nodename2] and tonumber(fields.amount1) and tonumber(fields.amount1) >= 1 and tonumber(fields.amount2) and tonumber(fields.amount2) >= 1 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", "size[8,10;]"..
|
||||
"list[context;main;0,0;8,4;]"..
|
||||
"label[0.256,4.5;"..fields.amount2.." "..fields.nodename2.." --> "..fields.amount1.." "..fields.nodename1.."]"..
|
||||
"button[3.3,5;2,1;button;Exchange]"..
|
||||
"button[3.1,5;2,1;button;Exchange]"..
|
||||
"list[current_player;main;0,6;8,4;]")
|
||||
meta:set_string("bartershopname", fields.bartershopname)
|
||||
meta:set_string("nodename1", fields.nodename1)
|
||||
|
@ -417,8 +518,9 @@ minetest.register_node("money:barter_shop", {
|
|||
end
|
||||
end,
|
||||
})
|
||||
--End.
|
||||
|
||||
minetest.register_craft({
|
||||
minetest.register_craft({--Barter shop recipe.
|
||||
output = "money:barter_shop",
|
||||
recipe = {
|
||||
{"locked_sign:sign_wall_locked"},
|
||||
|
@ -426,4 +528,171 @@ minetest.register_craft({
|
|||
},
|
||||
})
|
||||
|
||||
minetest.register_alias("barter_shop", "money:barter_shop")
|
||||
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"},
|
||||
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.env: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("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.env: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 not tonumber(fields.costbuy) then
|
||||
return
|
||||
end
|
||||
if not (tonumber(fields.costbuy) >= 0) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if fields.action == "S" then
|
||||
if not tonumber(fields.costsell) then
|
||||
return
|
||||
end
|
||||
if not (tonumber(fields.costsell) >= 0) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if fields.action == "BS" 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 == "B" then
|
||||
s = " sell "
|
||||
ss = "button[1,0.5;2,1;buttonsell;Sell("..fields.costbuy..")]"
|
||||
elseif fields.action == "S" 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.env:get_meta(pos)
|
||||
meta:set_string("formspec", "size[8,5.5;]"..
|
||||
"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 do not 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,
|
||||
})
|
||||
--End.
|
||||
|
||||
minetest.register_alias("admin_shop", "money:admin_shop")
|
||||
|
||||
--Admin barter shop.
|
||||
minetest.register_node("money:admin_barter_shop", {
|
||||
description = "Admin Barter Shop",
|
||||
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
||||
"default_chest_side.png", "default_chest_side.png", "money_admin_barter_shop_front.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.env:get_meta(pos)
|
||||
meta:set_string("formspec", "size[8,4.6]"..
|
||||
"field[0.256,0.5;8,1;nodename1;What kind of a node do you want to exchange:;]"..
|
||||
"field[0.256,1.5;8,1;nodename2;for:;]"..
|
||||
"field[0.256,2.5;8,1;amount1;Amount of first kind of node:;]"..
|
||||
"field[0.256,3.5;8,1;amount2;Amount of second kind of node:;]"..
|
||||
"button_exit[3.1,4;2,1;button;Proceed]")
|
||||
meta:set_string("infotext", "Untuned Admin Barter Shop")
|
||||
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.env:get_meta(pos)
|
||||
if meta:get_string("form") == "yes" then
|
||||
if minetest.registered_items[fields.nodename1] and minetest.registered_items[fields.nodename2] and tonumber(fields.amount1) and tonumber(fields.amount1) >= 1 and tonumber(fields.amount2) and tonumber(fields.amount2) >= 1 and (meta:get_string("owner") == sender:get_player_name() or minetest.get_player_privs(sender:get_player_name())["money_admin"]) then
|
||||
meta:set_string("formspec", "size[8,6;]"..
|
||||
"label[0.256,0.0;"..fields.amount2.." "..fields.nodename2.." --> "..fields.amount1.." "..fields.nodename1.."]"..
|
||||
"button[3.1,0.5;2,1;button;Exchange]"..
|
||||
"list[current_player;main;0,1.5;8,4;]")
|
||||
meta:set_string("nodename1", fields.nodename1)
|
||||
meta:set_string("nodename2", fields.nodename2)
|
||||
meta:set_string("amount1", fields.amount1)
|
||||
meta:set_string("amount2", fields.amount2)
|
||||
meta:set_string("infotext", "Admin Barter Shop")
|
||||
meta:set_string("form", "no")
|
||||
end
|
||||
elseif fields["button"] then
|
||||
local sender_name = sender:get_player_name()
|
||||
local sender_inv = sender:get_inventory()
|
||||
if not sender_inv:contains_item("main", meta:get_string("nodename2") .. " " .. meta:get_string("amount2")) then
|
||||
minetest.chat_send_player(sender_name, "In your inventory is not enough goods.")
|
||||
return
|
||||
elseif not sender_inv:room_for_item("main", meta:get_string("nodename1") .. " " .. meta:get_string("amount1")) then
|
||||
minetest.chat_send_player(sender_name, "In your inventory is not enough space.")
|
||||
return
|
||||
end
|
||||
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") .. ".")
|
||||
end
|
||||
end,
|
||||
})
|
||||
--End.
|
||||
|
||||
minetest.register_alias("admin_barter_shop", "money:admin_barter_shop")
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
INITIAL_MONEY = 2000
|
||||
MONEY_NAME = " money"
|
||||
CURRENCY_PREFIX = ""
|
||||
CURRENCY_POSTFIX = " money"
|
||||
|
|
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 930 B |
After Width: | Height: | Size: 930 B |
After Width: | Height: | Size: 946 B |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 946 B |