People are now visible, experimental support for animals
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Wed, 28 Jun 2017 15:58:10 +0000 (17:58 +0200)
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Wed, 28 Jun 2017 15:58:10 +0000 (17:58 +0200)
init.lua

index c0d5e26..5de8eac 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -4,20 +4,20 @@ minetest.register_entity("walkway:moving_dummy",{
                         initial_properties = {
                            hp_max = 1,
                            physical = false,
-                           collisionbox = {0.025, 0.025, 0.025, 0.025, 0.025, 0.025},
-                           visual = "wielditem",
+                           collisionbox = {0.005, -0.005, 0.005, -0.005, 0.005, -0.025},
+                           visual = "cube",
                            visual_size = {x = 1, y = 1},
-                           textures = {""},
+                           textures = {"blank.png","blank.png", "blank.png","blank.png","blank.png","blank.png"},
                            spritediv = {x = 1, y = 1},
                            initial_sprite_basepos = {x = 0, y = 0},
-                           is_visible = false,
+                           is_visible = true;
                         },
                         player = nil,
                         on_step = function (self, dtime)
                            local name = ""
-                           if self.player then
+                           if self.player and self.player:is_player() then
                               name = self.player:get_player_name()
-                           else
+                           elseif not self.player then
                               self.object:remove()
                            end
                            local pos = self.object:getpos()
@@ -25,7 +25,7 @@ minetest.register_entity("walkway:moving_dummy",{
                            local dir = vector.new(minetest.facedir_to_dir(napos.param2)) -- a copy of the facedir so we don't overwrite the facedir table
                            local vx=0
                            local vz=0
-                           if self.player then
+                           if name ~="" then
                               -- based on code from the tower crane mod --
                               local ctrl = self.player:get_player_control()
                               local yaw = self.player:get_look_horizontal()
@@ -34,6 +34,12 @@ minetest.register_entity("walkway:moving_dummy",{
                               local speed_forward = 0
                               local speed_right= 0
 
+                              if (ctrl.up or ctrl.down or ctrl.left or ctrl.right) then
+                                 default.player_set_animation(self.player, "walk" , 30)
+                              else
+                                 default.player_set_animation(self.player, "stand" , 30)
+                              end
+
                               if ctrl.up then             -- forward
                                  speed_forward = walk_speed
                               elseif ctrl.down then       -- backward
@@ -67,9 +73,15 @@ minetest.register_entity("walkway:moving_dummy",{
                               end
                               self.object:setvelocity({x = dir.x / speed + vx, y = 0, z = dir.z / speed+vz})
                            else
-                              self.player:set_detach()
-                              default.player_attached[name] = false
-                              self.object:remove()
+                              if self.player then
+                                 self.player:set_detach()
+                                 self.object:remove()
+                              else
+                                 self.object:remove()
+                              end
+                              if name ~="" then
+                                 default.player_attached[name] = false
+                              end
                            end
                         end
 })
@@ -134,14 +146,20 @@ minetest.register_abm({
                local all_objects = minetest.get_objects_inside_radius(pos, 0.75)
                local _,obj
                for _,obj in ipairs(all_objects) do
+                  if obj:get_luaentity() then
+                     minetest.chat_send_all(obj:get_luaentity().name)
+                  end
                   if obj:is_player() and not obj:get_attach() then
                      dum = walkway.do_moving_dummy({x = pos.x, y = pos.y + 0.15, z = pos.z}, obj):get_luaentity()
-                        dum.player = obj
-                        obj:set_attach(dum.object, "", {x=0,y=15,z=-3}, {x=0,y=0,z=0})
-                        local name = obj:get_player_name()
-                        default.player_attached[name] = true
---                   obj:get_luaentity().itemstring = ""
---                   obj:remove()
+                     dum.player = obj
+                     obj:set_attach(dum.object, "", {x=0,y=9,z=0}, {x=0,y=0,z=0})
+                     local name = obj:get_player_name()
+                     default.player_attached[name] = true
+                  elseif obj:get_luaentity() and string.sub(obj:get_luaentity().name,1,string.len("mobs_animal"))  == "mobs_animal" then
+                     dum = walkway.do_moving_dummy({x = pos.x, y = pos.y + 0.15, z = pos.z}, obj):get_luaentity()
+                     dum.player = obj
+                     minetest.chat_send_all("Attaching "..obj:get_luaentity().name)
+                     obj:set_attach(dum.object, "", {x=0,y=-1,z=0}, {x=0,y=0,z=0})
                   end
                end
        end,