diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-07-23 17:43:08 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-07-23 17:43:08 +0300 |
commit | 2c027b03db1446e13ee8a0791e37ec4eb6672a9d (patch) | |
tree | 2b6b7c79de078699d129ac3e838b2d29f75295d4 /games/minimal/mods/default/init.lua | |
parent | aef1332e4293d873ce5b827785daa3097209c5e6 (diff) | |
download | minetest-2c027b03db1446e13ee8a0791e37ec4eb6672a9d.tar.gz minetest-2c027b03db1446e13ee8a0791e37ec4eb6672a9d.tar.bz2 minetest-2c027b03db1446e13ee8a0791e37ec4eb6672a9d.zip |
Move /give, /giveme, /spawnentity and /pulverize to builtin/chatcommands.lua
Diffstat (limited to 'games/minimal/mods/default/init.lua')
-rw-r--r-- | games/minimal/mods/default/init.lua | 133 |
1 files changed, 12 insertions, 121 deletions
diff --git a/games/minimal/mods/default/init.lua b/games/minimal/mods/default/init.lua index b3bbc5fe8..428dfd9f4 100644 --- a/games/minimal/mods/default/init.lua +++ b/games/minimal/mods/default/init.lua @@ -1722,133 +1722,24 @@ function on_punchnode(p, node) end minetest.register_on_punchnode(on_punchnode) -local function handle_give_command(cmd, giver, receiver, stackstring) - if not minetest.get_player_privs(giver)["give"] then - minetest.chat_send_player(giver, "error: you don't have permission to give") - return - end - minetest.debug("DEBUG: "..cmd..' invoked, stackstring="'..stackstring..'"') - minetest.log(cmd..' invoked, stackstring="'..stackstring..'"') - local itemstack = ItemStack(stackstring) - if itemstack:is_empty() then - minetest.chat_send_player(giver, 'error: cannot give an empty item') - return - elseif not itemstack:is_known() then - minetest.chat_send_player(giver, 'error: cannot give an unknown item') - return - end - local receiverref = minetest.env:get_player_by_name(receiver) - if receiverref == nil then - minetest.chat_send_player(giver, receiver..' is not a known player') - return - end - local leftover = receiverref:get_inventory():add_item("main", itemstack) - if leftover:is_empty() then - partiality = "" - elseif leftover:get_count() == itemstack:get_count() then - partiality = "could not be " - else - partiality = "partially " - end - -- The actual item stack string may be different from what the "giver" - -- entered (e.g. big numbers are always interpreted as 2^16-1). - stackstring = itemstack:to_string() - if giver == receiver then - minetest.chat_send_player(giver, '"'..stackstring - ..'" '..partiality..'added to inventory.'); - else - minetest.chat_send_player(giver, '"'..stackstring - ..'" '..partiality..'added to '..receiver..'\'s inventory.'); - minetest.chat_send_player(receiver, '"'..stackstring - ..'" '..partiality..'added to inventory.'); - end -end - -minetest.register_on_chat_message(function(name, message) - --print("default on_chat_message: name="..dump(name).." message="..dump(message)) - local cmd = "/giveme" - if message:sub(0, #cmd) == cmd then - local stackstring = string.match(message, cmd.." (.*)") - if stackstring == nil then - minetest.chat_send_player(name, 'usage: '..cmd..' stackstring') - return true -- Handled chat message - end - handle_give_command(cmd, name, name, stackstring) - return true - end - local cmd = "/give" - if message:sub(0, #cmd) == cmd then - local receiver, stackstring = string.match(message, cmd.." ([%a%d_-]+) (.*)") - if receiver == nil or stackstring == nil then - minetest.chat_send_player(name, 'usage: '..cmd..' name stackstring') - return true -- Handled chat message - end - handle_give_command(cmd, name, receiver, stackstring) - return true - end - local cmd = "/spawnentity" - if message:sub(0, #cmd) == cmd then - if not minetest.get_player_privs(name)["give"] then - minetest.chat_send_player(name, "you don't have permission to spawn (give)") - return true -- Handled chat message - end - if not minetest.get_player_privs(name)["interact"] then - minetest.chat_send_player(name, "you don't have permission to interact") - return true -- Handled chat message - end - local entityname = string.match(message, cmd.." (.*)") - if entityname == nil then - minetest.chat_send_player(name, 'usage: '..cmd..' entityname') - return true -- Handled chat message - end - print(cmd..' invoked, entityname="'..entityname..'"') - local player = minetest.env:get_player_by_name(name) - if player == nil then - print("Unable to spawn entity, player is nil") - return true -- Handled chat message - end - local p = player:getpos() - p.y = p.y + 1 - minetest.env:add_entity(p, entityname) - minetest.chat_send_player(name, '"'..entityname - ..'" spawned.'); - return true -- Handled chat message - end - local cmd = "/pulverize" - if message:sub(0, #cmd) == cmd then - local player = minetest.env:get_player_by_name(name) - if player == nil then - print("Unable to pulverize, player is nil") - return true -- Handled chat message - end - if player:get_wielded_item():is_empty() then - minetest.chat_send_player(name, 'Unable to pulverize, no item in hand.') - else - player:set_wielded_item(nil) - minetest.chat_send_player(name, 'An item was pulverized.') - end - return true - end -end) - -- -- Test some things -- local function test_get_craft_result() - print("test_get_craft_result()") + minetest.log("info", "test_get_craft_result()") -- normal local input = { method = "normal", width = 2, items = {"", "default:coal_lump", "", "default:stick"} } - print("torch crafting input: "..dump(input)) + minetest.log("info", "torch crafting input: "..dump(input)) local output, decremented_input = minetest.get_craft_result(input) - print("torch crafting output: "..dump(output)) - print("torch crafting decremented input: "..dump(decremented_input)) + minetest.log("info", "torch crafting output: "..dump(output)) + minetest.log("info", "torch crafting decremented input: "..dump(decremented_input)) assert(output.item) - print("torch crafting output.item:to_table(): "..dump(output.item:to_table())) + minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table())) assert(output.item:get_name() == "default:torch") assert(output.item:get_count() == 4) -- fuel @@ -1857,10 +1748,10 @@ local function test_get_craft_result() width = 1, items = {"default:coal_lump"} } - print("coal fuel input: "..dump(input)) + minetest.log("info", "coal fuel input: "..dump(input)) local output, decremented_input = minetest.get_craft_result(input) - print("coal fuel output: "..dump(output)) - print("coal fuel decremented input: "..dump(decremented_input)) + minetest.log("info", "coal fuel output: "..dump(output)) + minetest.log("info", "coal fuel decremented input: "..dump(decremented_input)) assert(output.time) assert(output.time > 0) -- cook @@ -1869,14 +1760,14 @@ local function test_get_craft_result() width = 1, items = {"default:cobble"} } - print("cobble cooking input: "..dump(output)) + minetest.log("info", "cobble cooking input: "..dump(output)) local output, decremented_input = minetest.get_craft_result(input) - print("cobble cooking output: "..dump(output)) - print("cobble cooking decremented input: "..dump(decremented_input)) + minetest.log("info", "cobble cooking output: "..dump(output)) + minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input)) assert(output.time) assert(output.time > 0) assert(output.item) - print("cobble cooking output.item:to_table(): "..dump(output.item:to_table())) + minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table())) assert(output.item:get_name() == "default:stone") assert(output.item:get_count() == 1) end |