Browse Source

give players initial_stuff

main
Hendrik Langer 5 years ago
parent
commit
b902541479
  1. 26
      init.lua

26
init.lua

@ -142,6 +142,18 @@ function switch_creative:get_area_size(astore_area)
return x*z return x*z
end end
function switch_creative:initial_stuff()
local stuff_string = minetest.settings:get("initial_stuff") or
"default:pick_steel,default:axe_steel,default:shovel_steel," ..
"default:torch 99,default:cobble 99"
local itemtable = {}
local items = stuff_string:split(",")
for _, stack in ipairs(items) do
table.insert(itemtable, ItemStack(stack))
end
return itemtable
end
function switch_creative:save_player_privs(player) function switch_creative:save_player_privs(player)
local name = player:get_player_name() local name = player:get_player_name()
local pmeta = player:get_meta() local pmeta = player:get_meta()
@ -171,8 +183,20 @@ function switch_creative:restore_player_inventory(player, listname)
local name = player:get_player_name() local name = player:get_player_name()
local pmeta = player:get_meta() local pmeta = player:get_meta()
local inv = player:get_inventory() local inv = player:get_inventory()
local player_items = inv:get_list(listname) or {} local player_items = inv:get_list(listname)
local give_initial = false
if not player_items then
player_items = {}
give_initial = true
end
inv:set_list("main", player_items) inv:set_list("main", player_items)
if give_initial then
local initial_items = switch_creative:initial_stuff()
for _, stack in ipairs(initial_items) do
inv:add_item("main", stack)
end
end
end end
function switch_creative:player_enter_area(player, privstring) function switch_creative:player_enter_area(player, privstring)

Loading…
Cancel
Save