Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add give_initial_items API
- Loading branch information
1 parent
12c763a
commit acafe5ca86532aeefad44370b3f63bde5e805290
Showing
3 changed files
with
100 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,44 @@ | ||
minetest.register_on_newplayer(function(player) | ||
--print("on_newplayer") | ||
if minetest.setting_getbool("give_initial_stuff") then | ||
minetest.log("action", "Giving initial stuff to player "..player:get_player_name()) | ||
player:get_inventory():add_item('main', 'default:pick_steel') | ||
player:get_inventory():add_item('main', 'default:torch 99') | ||
player:get_inventory():add_item('main', 'default:axe_steel') | ||
player:get_inventory():add_item('main', 'default:shovel_steel') | ||
player:get_inventory():add_item('main', 'default:cobble 99') | ||
local stuff_string = minetest.setting_get("initial_stuff") or | ||
"default:pick_steel,default:axe_steel,default:shovel_steel," .. | ||
"default:torch 99,default:cobble 99" | ||
|
||
give_initial_stuff = { | ||
items = {} | ||
} | ||
|
||
function give_initial_stuff.give(player) | ||
minetest.log("action", | ||
"Giving initial stuff to player " .. player:get_player_name()) | ||
local inv = player:get_inventory() | ||
for _, stack in ipairs(give_initial_stuff.items) do | ||
inv:add_item("main", stack) | ||
end | ||
end | ||
|
||
function give_initial_stuff.add(stack) | ||
give_initial_stuff.items[#give_initial_stuff.items + 1] = ItemStack(stack) | ||
end | ||
|
||
function give_initial_stuff.clear() | ||
give_initial_stuff.items = {} | ||
end | ||
|
||
function give_initial_stuff.add_from_csv(str) | ||
local items = str:split(",") | ||
for _, itemname in ipairs(items) do | ||
give_initial_stuff.add(itemname) | ||
end | ||
end) | ||
end | ||
|
||
function give_initial_stuff.set_list(list) | ||
give_initial_stuff.items = list | ||
end | ||
|
||
function give_initial_stuff.get_list() | ||
return give_initial_stuff.items | ||
end | ||
|
||
give_initial_stuff.add_from_csv(stuff_string) | ||
if minetest.setting_getbool("give_initial_stuff") then | ||
minetest.register_on_newplayer(give_initial_stuff.give) | ||
end |