]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/player/init.lua
update readme
[Crafter.git] / mods / player / init.lua
index e5d10b9d805901bab315213ed8537f1acf97b711..6d638718ea67dbebb9d0561a78de8d07eb7e2437 100644 (file)
---[[
---map
-running - set fov set_fov(fov, is_multiplier) set_breath(value)
-sneaking --set eye offset
-
-]]--
 crafter_version = 0.03
 
 minetest.register_on_joinplayer(function(player)
-      --add in info
-      player:hud_set_flags({minimap=true})
-      player:hud_add({
-            hud_elem_type = "text",
-            position = {x=0,y=0},
-            text = "Crafter Alpha "..crafter_version,
-            number = 000000,
-            alignment = {x=1,y=1},
-            offset = {x=2, y=2},
-      })
-      player:hud_add({
-            hud_elem_type = "text",
-            position = {x=0,y=0},
-            text = "Crafter Alpha "..crafter_version,
-            number = 0xffffff,
-            alignment = {x=1,y=1},
-            offset = {x=0, y=0},
-      })
+       --add in version info
+       player:hud_add({
+               hud_elem_type = "image",
+               position = {x=1,y=0},
+               scale = {x=0.75,y=0.75},
+               text = "version.png",
+               --number = 000000,
+               --alignment = {x=-1,y=0},
+               offset = {x=-180, y=19},
+       })
 end)
 
 --hurt sound
 minetest.register_on_player_hpchange(function(player, hp_change, reason)
-      if hp_change < 0 then
-            minetest.sound_play("hurt", {object=player, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
-      end
+       if hp_change < 0 then
+               minetest.sound_play("hurt", {object=player, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
+       end
 end)
 
 --throw all items on death
 minetest.register_on_dieplayer(function(player, reason)
-      local pos = player:getpos()
-      local inv = player:get_inventory()
-      
-      for i = 1,inv:get_size("main") do
-            local stack = inv:get_stack("main", i)
-            local name = stack:get_name()
-            local count = stack:get_count()
-            if name ~= "" then
-                  local obj = minetest.add_item(pos, name.." "..count)
-                  obj:setvelocity(vector.new(math.random(-3,3),math.random(4,8),math.random(-3,3)))
-                  inv:set_stack("main", i, ItemStack(""))
-            end
-      end
-      for i = 1,inv:get_size("craft") do
-      
-      end 
-      
-
+       local pos = player:getpos()
+       local inv = player:get_inventory()
+       
+       for i = 1,inv:get_size("main") do
+               local stack = inv:get_stack("main", i)
+               local name = stack:get_name()
+               local count = stack:get_count()
+               if name ~= "" then
+                       local obj = minetest.add_item(pos, name.." "..count)
+                       if obj then
+                               obj:setvelocity(vector.new(math.random(-3,3),math.random(4,8),math.random(-3,3)))
+                       end
+                       inv:set_stack("main", i, ItemStack(""))
+               else
+                       inv:set_stack("main", i, ItemStack(""))
+               end
+       end
+       --for i = 1,inv:get_size("craft") do
+       
+       --end 
 end)
 
 minetest.register_globalstep(function(dtime)
-      --collection
-      for _,player in ipairs(minetest.get_connected_players()) do
-            local run = player:get_player_control().aux1
-            local walk = player:get_player_control().up
-            local sneak = player:get_player_control().sneak
-            
-            if run and walk and not sneak then
-                  --[[ I'll impliment this in later
-                  local meta = player:get_meta()
-                  
-                  local run_time = meta:get_float("running_timer")
-                  
-                  if not run_time then
-                        run_time = 0
-                  end
-                  
-                  if run_time >= 0.1 then
-                        --take breath away
-                        local breath = player:get_breath()
-                        breath = breath - 1
-                        player:set_breath(breath)
-                        run_time = 0
-                        print(breath)
-                  end
-                  
-                  meta:set_float("running_timer", run_time + dtime)
-                  
-                  ]]--
-                  
-                  local fov = player:get_fov()
-                  if fov == 0 then
-                        fov = 1
-                  end
-                  
-                  if fov < 1.2 then
-                        player:set_fov(fov + 0.05, true)
-                  end
-                  
-                  player:set_physics_override({speed=1.5})
-            else
-                  local meta = player:get_meta()
-                  local fov = player:get_fov()
-                  if fov > 1 then
-                        player:set_fov(fov - 0.05, true)
-                  end
-                  
-                  player:set_physics_override({speed=1})
-                  --meta:set_float("running_timer", 0)
-            end
-            
-            if sneak then
-                  player:set_eye_offset({x=0,y=-1,z=0},{x=0,y=-1,z=0})
-            else
-                  player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
-            end
-      end
+       --collection
+       for _,player in ipairs(minetest.get_connected_players()) do
+               local meta = player:get_meta()
+               if meta:get_int("roll credits") ~= 1 then
+                       local run = player:get_player_control().aux1
+                       local walk = player:get_player_control().up
+                       local sneak = player:get_player_control().sneak
+                       
+                       if run and walk and not sneak then
+                               --[[ I'll impliment this in later
+                               local meta = player:get_meta()
+                               
+                               local run_time = meta:get_float("running_timer")
+                               
+                               if not run_time then
+                                       run_time = 0
+                               end
+                               
+                               if run_time >= 0.1 then
+                                       --take breath away
+                                       local breath = player:get_breath()
+                                       breath = breath - 1
+                                       player:set_breath(breath)
+                                       run_time = 0
+                                       print(breath)
+                               end
+                               
+                               meta:set_float("running_timer", run_time + dtime)
+                               
+                               ]]--
+                               
+                               local fov = player:get_fov()
+                               if fov == 0 then
+                                       fov = 1
+                               end
+                               
+                               if fov < 1.2 then
+                                       player:set_fov(fov + dtime, true)
+                               elseif fov > 1.2 then
+                                                       player:set_fov(1.2, true)
+                               end
+                               
+                               player:set_physics_override({speed=1.5})
+                       else
+                               local meta = player:get_meta()
+                               local fov = player:get_fov()
+                               if fov > 1 then
+                                       player:set_fov(fov - dtime, true)
+                               elseif fov < 1 then
+                                                       player:set_fov(1, true)
+                               end
+                               
+                               player:set_physics_override({speed=1})
+                               --meta:set_float("running_timer", 0)
+                       end
+                       
+                       if sneak then
+                               player:set_eye_offset({x=0,y=-1,z=0},{x=0,y=-1,z=0})
+                       else
+                               player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
+                       end
+               end
+       end
 end)
 
 minetest.register_globalstep(function(dtime)
-      --collection
-      for _,player in ipairs(minetest.get_connected_players()) do
-            if player:get_player_control().RMB then
-                  local health = player:get_wielded_item():get_definition().health
-                  if health then
-                        local meta = player:get_meta()
-                        local eating = meta:get_float("eating")
-                        
-                        if meta:get_int("eating_ps") == 0 then
-                              local ps = minetest.add_particlespawner({
-                                    amount = 100,
-                                    time = 0,
-                                    minpos = {x=0, y=-1.5, z=0.5},
-                                    maxpos = {x=0, y=1.7, z=0.5},
-                                    minvel = vector.new(-0.5,0,-0.5),
-                                    maxvel = vector.new(0.5,0,0.5),
-                                    minacc = {x=0, y=-9.81, z=1},
-                                    maxacc = {x=0, y=-9.81, z=1},
-                                    minexptime = 0.5,
-                                    maxexptime = 1.5,
-                                    minsize = 1,
-                                    maxsize = 2,
-                                    attached = player,
-                                    collisiondetection = true,
-                                    vertical = false,
-                                    texture = "treecapitator.png"
-                              })
-                              meta:set_int("eating_ps", ps)
-                        end
-                              
-                        if eating + dtime >= 2 then
-                              local stack = player:get_wielded_item()
-                              stack:take_item(1)
-                              player:set_wielded_item(stack)
-                              player:set_hp(player:get_hp() + health)
-                              eating = 0
-                              minetest.sound_play("eat", {
-                                    object = player,
-                                    gain = 1.0,  -- default
-                                    max_hear_distance = 32,  -- default, uses an euclidean metric
-                                    pitch = math.random(70,100)/100,
-                              })
-                        end
-                        meta:set_float("eating", eating + dtime)
-                  else
-                        local meta = player:get_meta()
-                        meta:set_float("eating", 0)
-                        minetest.delete_particlespawner(meta:get_int("eating_ps"))
-                        meta:set_int("eating_ps", 0)
-                        
-                  end
-            else
-                  local meta = player:get_meta()
-                  meta:set_float("eating", 0)
-                  minetest.delete_particlespawner(meta:get_int("eating_ps"))
-                  meta:set_int("eating_ps", 0)
-            end
-            
-      end
-end)
-
-
-local inv =    "size[9,8.75]"..
-    "background[-0.19,-0.25;9.41,9.49;main_inventory.png]"..
-    "list[current_player;main;0,4.5;9,1;]".. --hot bar
-       "list[current_player;main;0,6;9,3;9]".. --big part
-    "list[current_player;craft;2.5,1;2,2;]"..
-    "list[current_player;craftpreview;6.1,1.5;1,1;]"..
-    "listring[current_player;main]"..
-       "listring[current_player;craft]"
-
-
-minetest.register_on_joinplayer(function(player)
-       player:set_inventory_formspec(inv)
-       local inv = player:get_inventory()
-       inv:set_width("craft", 2)
-       inv:set_width("main", 9)
-       inv:set_size("main", 9*4)
-       inv:set_size("craft", 4)
-       player:hud_set_hotbar_itemcount(9)
-       player:hud_set_hotbar_image("inventory_hotbar.png")
-       player:hud_set_hotbar_selected_image("hotbar_selected.png")
+       --collection
+       for _,player in ipairs(minetest.get_connected_players()) do
+               if player:get_player_control().RMB then
+                       local health = player:get_wielded_item():get_definition().health
+                       if health then
+                               local meta = player:get_meta()
+                               local eating = meta:get_float("eating")
+                               
+                               if meta:get_int("eating_ps") == 0 then
+                                       local ps = minetest.add_particlespawner({
+                                               amount = 100,
+                                               time = 0,
+                                               minpos = {x=0, y=-1.5, z=0.5},
+                                               maxpos = {x=0, y=1.7, z=0.5},
+                                               minvel = vector.new(-0.5,0,-0.5),
+                                               maxvel = vector.new(0.5,0,0.5),
+                                               minacc = {x=0, y=-9.81, z=1},
+                                               maxacc = {x=0, y=-9.81, z=1},
+                                               minexptime = 0.5,
+                                               maxexptime = 1.5,
+                                               minsize = 1,
+                                               maxsize = 2,
+                                               attached = player,
+                                               collisiondetection = true,
+                                               vertical = false,
+                                               texture = "treecapitator.png"
+                                       })
+                                       meta:set_int("eating_ps", ps)
+                               end
+                                       
+                               if eating + dtime >= 2 then
+                                       local stack = player:get_wielded_item()
+                                       stack:take_item(1)
+                                       player:set_wielded_item(stack)
+                                       player:set_hp(player:get_hp() + health)
+                                       eating = 0
+                                       minetest.sound_play("eat", {
+                                               object = player,
+                                               gain = 1.0,  -- default
+                                               max_hear_distance = 32,  -- default, uses an euclidean metric
+                                               pitch = math.random(70,100)/100,
+                                       })
+                               end
+                               meta:set_float("eating", eating + dtime)
+                       else
+                               local meta = player:get_meta()
+                               meta:set_float("eating", 0)
+                               minetest.delete_particlespawner(meta:get_int("eating_ps"))
+                               meta:set_int("eating_ps", 0)
+                               
+                       end
+               else
+                       local meta = player:get_meta()
+                       meta:set_float("eating", 0)
+                       minetest.delete_particlespawner(meta:get_int("eating_ps"))
+                       meta:set_int("eating_ps", 0)
+               end
+               
+       end
 end)
 
 --this dumps the players crafting table on closing the inventory
-local dump_craft = function(player)
+dump_craft = function(player)
        local inv = player:get_inventory()
        local pos = player:getpos()
        pos.y = pos.y + player:get_properties().eye_height
@@ -211,27 +182,22 @@ local dump_craft = function(player)
                local obj = minetest.add_item(pos, item)
                if obj then
                        local x=math.random(-2,2)*math.random()
-            local y=math.random(2,5)
-            local z=math.random(-2,2)*math.random()
-            obj:setvelocity({x=x, y=y, z=z})
+                       local y=math.random(2,5)
+                       local z=math.random(-2,2)*math.random()
+                       obj:setvelocity({x=x, y=y, z=z})
                end
                inv:set_stack("craft", i, nil)
        end
 end
 
---this resets the craft table
-minetest.register_on_player_receive_fields(function(player, formname, fields)
-       local inv = player:get_inventory()
-       dump_craft(player)
-       inv:set_width("craft", 2)
-       inv:set_size("craft", 4)
-end)
-
 --replace stack when empty (building)
 minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
        local old = itemstack:get_name()
        --pass through to check
        minetest.after(0,function(pos, newnode, placer, oldnode, itemstack, pointed_thing,old)
+               if not placer then
+                       return
+               end
                local new = placer:get_wielded_item():get_name()
                if old ~= new and new == "" then
                        local inv = placer:get_inventory()
@@ -258,6 +224,13 @@ minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack
        end,pos, newnode, placer, oldnode, itemstack, pointed_thing,old)
 end)
 
+minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
+       dir = vector.multiply(dir,10)
+       dir.y = 7
+       player:add_player_velocity(dir)
+       
+end)
+
 --play sound to keep up with player's placing vs inconsistent client placing sound 
 minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
        local node = minetest.registered_nodes[newnode.name]
@@ -275,3 +248,26 @@ minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack
                })
        end
 end)
+
+
+--this is to check if the player is exploring a cave
+--if exploring cave not near an open shaft then play a scary noise
+--every 5-7 minutes
+local scary_sound_player_timer = 0
+minetest.register_globalstep(function(dtime)
+       scary_sound_player_timer = scary_sound_player_timer + dtime
+       --print(scary_sound_player_timer)
+       --try to play every 5 minutes
+       if scary_sound_player_timer > 300 then
+               scary_sound_player_timer = math.random(-120,0)
+               for _,player in ipairs(minetest.get_connected_players()) do
+                       local pos = player:get_pos()
+                       pos.y = pos.y + 1.625
+                       local light = minetest.get_node_light(pos)
+                       if pos.y < 0 and light <= 13 then
+                               --print(light)
+                               minetest.sound_play("scary_noise",{to_player = player:get_player_name(),gain=0.7,pitch=math.random(70,100)/100})
+                       end     
+               end
+       end
+end)