1 --hurt sound and disable fall damage group handling
2 minetest.register_on_player_hpchange(function(player, hp_change, reason)
3 if reason.type == "fall" then
4 if minetest.get_node_group(minetest.get_node(player:get_pos()).name, "disable_fall_damage") > 0 then
9 minetest.sound_play("hurt", {object=player, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
14 --throw all items on death
15 minetest.register_on_dieplayer(function(player, reason)
16 local pos = player:getpos()
17 local inv = player:get_inventory()
19 for i = 1,inv:get_size("main") do
20 local stack = inv:get_stack("main", i)
21 local name = stack:get_name()
22 local count = stack:get_count()
24 local obj = minetest.add_item(pos, name.." "..count)
26 obj:setvelocity(vector.new(math.random(-3,3),math.random(4,8),math.random(-3,3)))
28 inv:set_stack("main", i, ItemStack(""))
30 inv:set_stack("main", i, ItemStack(""))
36 --this dumps the players crafting table on closing the inventory
37 dump_craft = function(player)
38 local inv = player:get_inventory()
39 local pos = player:getpos()
40 pos.y = pos.y + player:get_properties().eye_height
41 for i = 1,inv:get_size("craft") do
42 local item = inv:get_stack("craft", i)
43 local obj = minetest.add_item(pos, item)
45 local x=math.random(-2,2)*math.random()
46 local y=math.random(2,5)
47 local z=math.random(-2,2)*math.random()
48 obj:setvelocity({x=x, y=y, z=z})
50 inv:set_stack("craft", i, nil)
55 --play sound to keep up with player's placing vs inconsistent client placing sound
56 minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
57 local node = minetest.registered_nodes[newnode.name]
58 local sound = node.sounds
61 placing = sound.placing
63 --only play the sound when is defined
64 if type(placing) == "table" then
65 minetest.sound_play(placing.name, {
68 --pitch = math.random(60,100)/100
73 --replace stack when empty (building)
74 minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
75 local old = itemstack:get_name()
76 --pass through to check
77 minetest.after(0,function(pos, newnode, placer, oldnode, itemstack, pointed_thing,old)
81 local new = placer:get_wielded_item():get_name()
82 if old ~= new and new == "" then
83 local inv = placer:get_inventory()
84 --check if another stack
85 if inv:contains_item("main", old) then
86 --print("moving stack")
87 --run through inventory
88 for i = 1,inv:get_size("main") do
89 --if found set wielded item and remove old stack
90 if inv:get_stack("main", i):get_name() == old then
91 local count = inv:get_stack("main", i):get_count()
92 placer:set_wielded_item(old.." "..count)
93 inv:set_stack("main",i,ItemStack(""))
94 minetest.sound_play("pickup", {
97 pitch = math.random(60,100)/100
104 end,pos, newnode, placer, oldnode, itemstack, pointed_thing,old)
107 --this throws the player when they're punched
108 minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
109 dir = vector.multiply(dir,10)
110 local vel = player:get_player_velocity()
115 player:add_player_velocity(dir)