Adding optional functionality with licenses
parent
05c7be2364
commit
e4286d8ab9
|
@ -1,4 +1,6 @@
|
||||||
# minetest_adminshop
|
# Minetest-Mod: adminshop
|
||||||
|
Github: https://github.com/Jean28518/minetest_adminshop
|
||||||
|
|
||||||
Mod for Minetest, which adds adminshops.
|
Mod for Minetest, which adds adminshops.
|
||||||
|
|
||||||
There is no crafting recipe available.
|
There is no crafting recipe available.
|
||||||
|
|
198
init.lua
198
init.lua
|
@ -1,6 +1,6 @@
|
||||||
minetest.register_privilege("adminshop", {
|
minetest.register_privilege("adminshop", {
|
||||||
description = "Player can place and destruct any adminshop",
|
description = "Player can place and destruct any adminshop",
|
||||||
give_to_singleplayer= false,
|
give_to_singleplayer= true,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Adminshop
|
-- Adminshop
|
||||||
|
@ -123,3 +123,199 @@ minetest.register_on_player_receive_fields(function(customer, formname, fields)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
-- Adminshop with licenses
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
if minetest.get_modpath("licenses") ~= nil then
|
||||||
|
default.adminshop_current_license_shop_position = {}
|
||||||
|
minetest.register_node("adminshop:adminshop_license", {
|
||||||
|
|
||||||
|
description = "Adminshop with licenses integrated",
|
||||||
|
tiles = {"dummy.png"},
|
||||||
|
is_ground_content = true,
|
||||||
|
groups = {choppy=2},
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
-- Registriere den Owner beim Platzieren:
|
||||||
|
after_place_node = function(pos, placer, itemstack)
|
||||||
|
if not minetest.check_player_privs(placer:get_player_name(), { adminshop=true }) then
|
||||||
|
-- if minetest.check_player_privs(placer:get_player_name(), { adminshop=false }) then
|
||||||
|
minetest.chat_send_player(placer:get_player_name(),"You don't have the required privilege to place an adminshop!")
|
||||||
|
minetest.remove_node(pos)
|
||||||
|
end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("owner", placer:get_player_name())
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("einnahme", 2*2)
|
||||||
|
inv:set_size("ausgabe", 2*2)
|
||||||
|
end,
|
||||||
|
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_license_shop_position[player:get_player_name()] = pos
|
||||||
|
show_specl(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
|
||||||
|
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
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
can_dig = function(pos, player)
|
||||||
|
if minetest.check_player_privs(player:get_player_name(), { adminshop=true }) then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
show_specl = function (player)
|
||||||
|
local pos = default.adminshop_current_license_shop_position[player:get_player_name()]
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local listname = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||||
|
local licenses_string = ""
|
||||||
|
local ltable = minetest.deserialize(meta:get_string("adminshop:ltable"))
|
||||||
|
if ltable == nil then
|
||||||
|
ltable = {}
|
||||||
|
end
|
||||||
|
for k, v in pairs(ltable) do
|
||||||
|
if v == "defined" then
|
||||||
|
licenses_string = licenses_string .. k ..","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if player:get_player_name() == meta:get_string("owner") then
|
||||||
|
minetest.show_formspec(player:get_player_name(), "adminshop:adminshop_license", "size[11,7.5]"..
|
||||||
|
"label[0,0;Welcome back, ".. meta:get_string("owner").."]" ..
|
||||||
|
-- Licenses:
|
||||||
|
"label[8,0;Licenses:]" ..
|
||||||
|
"textlist[8,0.5;2.8,5;license_list;"..licenses_string.."]" ..
|
||||||
|
"button[8,5.5;1.5,1;add_license;Add]" ..
|
||||||
|
"button[9.5,5.5;1.5,1;remove_license;Remove]" ..
|
||||||
|
"field[8.3,6.7;3,1;license_text;;]" ..
|
||||||
|
--for word in string.gmatch("Hello Lua user", "%a+") do print(word) end
|
||||||
|
-------------
|
||||||
|
"label[0,0.5;Paying:]" ..
|
||||||
|
"list["..listname..";einnahme;0,1;2,2;]"..
|
||||||
|
"label[6,0.5;Getting:]" ..
|
||||||
|
"list["..listname..";ausgabe;6,1;2,2;]" ..
|
||||||
|
"list[current_player;main;0,3.5;8,4;]" ..
|
||||||
|
"button[3,1.5;2,1;exchange;Exchange]"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
minetest.show_formspec(player:get_player_name(), "adminshop:adminshop_license", "size[8,7.5]"..
|
||||||
|
"label[0,0;Welcome, "..player:get_player_name().."]" ..
|
||||||
|
"label[0,0.5;Paying:]" ..
|
||||||
|
"list["..listname..";einnahme;0,1;2,2;]"..
|
||||||
|
"label[6,0.5;Getting:]" ..
|
||||||
|
"list["..listname..";ausgabe;6,1;2,2;]" ..
|
||||||
|
"list[current_player;main;0,3.5;8,4;]" ..
|
||||||
|
"button[3,1.5;2,1;exchange;Exchange]"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Wenn der Spieler auf Exchange gedrückt hat:
|
||||||
|
minetest.register_on_player_receive_fields(function(customer, formname, fields)
|
||||||
|
if formname == "adminshop:adminshop_license" and fields.exchange ~= nil and fields.exchange ~= "" then
|
||||||
|
local pos = default.adminshop_current_license_shop_position[customer:get_player_name()]
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local minv = meta:get_inventory()
|
||||||
|
local pinv = customer:get_inventory()
|
||||||
|
|
||||||
|
local wants = minv:get_list("einnahme")
|
||||||
|
local gives = minv:get_list("ausgabe")
|
||||||
|
if wants == nil or gives == nil then return end -- do not crash the server
|
||||||
|
-- Check if we can exchange
|
||||||
|
local enough_items = true
|
||||||
|
local enough_space = true
|
||||||
|
for i, item in pairs(wants) do
|
||||||
|
if not pinv:contains_item("main",item) then
|
||||||
|
enough_items = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i, item in pairs(gives) do
|
||||||
|
if not pinv:room_for_item("main", item) then
|
||||||
|
enough_space = false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
-- Check Licence
|
||||||
|
local allowed = false
|
||||||
|
local empty = true
|
||||||
|
local ltable = minetest.deserialize(meta:get_string("adminshop:ltable"))
|
||||||
|
if ltable == nil then
|
||||||
|
ltable = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
for k, v in pairs(ltable) do
|
||||||
|
empty = false
|
||||||
|
if v == "defined" then
|
||||||
|
if licenses_check_player_by_licese(customer:get_player_name(), k) then
|
||||||
|
allowed = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if empty then
|
||||||
|
allowed = true
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
if enough_items and enough_space and allowed then
|
||||||
|
for i, item in pairs(wants) do
|
||||||
|
pinv:remove_item("main",item)
|
||||||
|
end
|
||||||
|
for i, item in pairs(gives) do
|
||||||
|
pinv:add_item("main",item)
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(customer:get_player_name(),"Exchanged!")
|
||||||
|
elseif not allowed then
|
||||||
|
minetest.chat_send_player(customer:get_player_name(),"You are not allowd to buy this!" )
|
||||||
|
elseif enough_space then
|
||||||
|
minetest.chat_send_player(customer:get_player_name(),"You don't have the required items in your inventory!")
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(customer:get_player_name(),"You don't have enough space in your inventory!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(customer, formname, fields)
|
||||||
|
if formname == "adminshop:adminshop_license" and fields.add_license ~= nil and fields.add_license ~= "" then
|
||||||
|
local pos = default.adminshop_current_license_shop_position[customer:get_player_name()]
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local ltable = minetest.deserialize(meta:get_string("adminshop:ltable"))
|
||||||
|
if ltable == nil then
|
||||||
|
ltable = {}
|
||||||
|
end
|
||||||
|
-- Checke, ob das wirklich existiert
|
||||||
|
if licenses_exists(fields.license_text) then
|
||||||
|
ltable[fields.license_text] = "defined"
|
||||||
|
meta:set_string("adminshop:ltable", minetest.serialize(ltable))
|
||||||
|
show_specl(customer)
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(customer:get_player_name(),"This license doesnt exist! Add this with /licenses_add " .. fields.license_text )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(customer, formname, fields)
|
||||||
|
if formname == "adminshop:adminshop_license" and fields.remove_license ~= nil and fields.remove_license ~= "" then
|
||||||
|
local pos = default.adminshop_current_license_shop_position[customer:get_player_name()]
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local ltable = minetest.deserialize(meta:get_string("adminshop:ltable"))
|
||||||
|
if ltable == nil then
|
||||||
|
ltable = {}
|
||||||
|
end
|
||||||
|
ltable[fields.license_text] = nil
|
||||||
|
meta:set_string("adminshop:ltable", minetest.serialize(ltable))
|
||||||
|
show_specl(customer)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
Loading…
Reference in New Issue