Compare commits

...

6 Commits

3 changed files with 44 additions and 16 deletions

View File

@ -4,7 +4,7 @@ Github: https://github.com/Jean28518/minetest_adminshop
Mod for Minetest, which adds adminshops.
There are no crafting recipe available.
To place and to break adminshops you need the "adminshop" privilege assigned. Only the owner (placer) of the adminshop is able to change the offer.
To place and to break adminshops you need the "adminshop" privilege assigned. Every Player with the "adminshop" privilege is able to configure an adminshop.
## Optional: How to work with licenses and adminshop
The Mod can be found at: https://github.com/Jean28518/minetest_licenses

View File

@ -3,6 +3,9 @@ minetest.register_privilege("adminshop", {
give_to_singleplayer= true,
})
local jeans_economy = false
if minetest.get_modpath("jeans_economy") then jeans_economy = true end
-- Adminshop
-- Globaler Arrayspeicher
default.adminshop_current_shop_position = {}
@ -35,17 +38,17 @@ minetest.register_node("adminshop:adminshop", {
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
-- Schreibe die eigene Position des Blockes in eine öffentliche Variable mit dem Namen des Spielernamens, welcher auf den Block zugegriffen hat
default.adminshop_current_shop_position[player:get_player_name()] = pos
show_spec(player)
adminshop_show_spec(player)
--end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
if not minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then 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 player:get_player_name() ~= meta:get_string("owner") then return 0 end
if not minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then return 0 end
return stack:get_count()
end,
can_dig = function(pos, player)
@ -59,15 +62,17 @@ minetest.register_node("adminshop:adminshop", {
})
show_spec = function (player)
adminshop_show_spec = function (player)
local pos = default.adminshop_current_shop_position[player:get_player_name()]
local meta = minetest.get_meta(pos)
local listname = "nodemeta:"..pos.x..','..pos.y..','..pos.z
if player:get_player_name() == meta:get_string("owner") then
-- if player:get_player_name() == meta:get_string("owner") then
if minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then
--"label[0,0;Welcome back, " .. meta:get_string("owner") ..
-- "list["..listname..";einnahme;0,3.5;8,4;]"
minetest.show_formspec(player:get_player_name(), "adminshop:adminshop", "size[8,7.5]"..
"label[0,0;Welcome back, ".. meta:get_string("owner").."]" ..
"label[0,0;Welcome back, ".. player:get_player_name().."]" ..
"label[3.5,1.15;Counter: "..meta:get_int("adminshop:counter").."]" ..
"label[0,0.5;Paying:]" ..
"list["..listname..";einnahme;0,1;2,2;]"..
@ -171,12 +176,12 @@ if minetest.get_modpath("licenses") ~= nil then
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
if not minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then 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 player:get_player_name() ~= meta:get_string("owner") then return 0 end
if not minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then return 0 end
return stack:get_count()
end,
can_dig = function(pos, player)
@ -209,9 +214,10 @@ if minetest.get_modpath("licenses") ~= nil then
if licenses_required == "" then
licenses_required = "nothing"
end
if player:get_player_name() == meta:get_string("owner") then
-- if player:get_player_name() == meta:get_string("owner") then
if minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then
minetest.show_formspec(player:get_player_name(), "adminshop:adminshop_license", "size[11,7.5]"..
"label[0,0;Welcome back, ".. meta:get_string("owner").."]" ..
"label[0,0;Welcome back, ".. player:get_player_name().."]" ..
"label[3.5,1.15;Counter: "..meta:get_int("adminshop:counter").."]" ..
-- Licenses:
"label[8,0;Licenses:]" ..
@ -385,12 +391,12 @@ if minetest.get_modpath("licenses") ~= nil and minetest.get_modpath("currency")
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
if not minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then 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 player:get_player_name() ~= meta:get_string("owner") then return 0 end
if not minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then return 0 end
return stack:get_count()
end,
can_dig = function(pos, player)
@ -411,6 +417,9 @@ if minetest.get_modpath("licenses") ~= nil and minetest.get_modpath("currency")
local licenses_string = ""
local licenses_required = ""
local ltable = minetest.deserialize(meta:get_string("adminshop:ltable"))
if atm.balance[player:get_player_name()] == nil then
atm.balance[player:get_player_name()] = 0
end
if ltable == nil then
ltable = {}
end
@ -423,9 +432,10 @@ if minetest.get_modpath("licenses") ~= nil and minetest.get_modpath("currency")
if licenses_required == "" then
licenses_required = "nothing"
end
if player:get_player_name() == meta:get_string("owner") then
-- if player:get_player_name() == meta:get_string("owner") then
if minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then
minetest.show_formspec(player:get_player_name(), "adminshop:adminshop_license_atm", "size[11,7.5]"..
"label[0,0;Welcome back, ".. meta:get_string("owner").."]" ..
"label[0,0;Welcome back, ".. player:get_player_name().."]" ..
"label[3.5,1.15;Counter: "..meta:get_int("adminshop:counter").."]" ..
-- Licenses:
"label[8,0;Licenses:]" ..
@ -517,8 +527,17 @@ if minetest.get_modpath("licenses") ~= nil and minetest.get_modpath("currency")
-- BUY:
if meta:get_string("adminshop:bs") == "Buy" then
if enough_space and allowed then
local item_name = "Nothing"
local item_count = 1
for i, item in pairs(items) do
pinv:add_item("main",item)
if item_name == "Nothing" or item_name == "" then
item_name = item:get_name()
item_count = item:get_count()
end
end
if jeans_economy then
jeans_economy_save(customer:get_player_name(), "Server", meta:get_int("adminshop:price"), customer:get_player_name().." buys "..item_count.." "..item_name.." at the adminshop")
end
atm.balance[customer:get_player_name()] = atm.balance[customer:get_player_name()] - meta:get_int("adminshop:price")
show_specl_atm(customer)
@ -531,9 +550,18 @@ if minetest.get_modpath("licenses") ~= nil and minetest.get_modpath("currency")
-- SELL:
else
if allowed and enough_items then
local item_name = "Nothing"
local item_count = 1
for i, item in pairs(items) do
pinv:remove_item("main",item)
if item_name == "Nothing" or item_name == "" then
item_name = item:get_name()
item_count = item:get_count()
end
end
if jeans_economy then
jeans_economy_save("Server", customer:get_player_name(), meta:get_int("adminshop:price"), customer:get_player_name().." sells "..item_count.." "..item_name.." to the adminshop")
end
atm.balance[customer:get_player_name()] = atm.balance[customer:get_player_name()] + meta:get_int("adminshop:price")
show_specl_atm(customer)
meta:set_int("adminshop:counter", meta:get_int("adminshop:counter") + 1)

View File

@ -1,4 +1,4 @@
name = adminshop
description = Adds adminshops. Suitable for Servers.
depends = default
optional_depends = licenses, currency, atm
optional_depends = licenses, currency, atm, jeans_economy