3 local mummy_walk_limit
= 1
4 local mummy_chillaxin_speed
= 1
5 local mummy_animation_speed
= 10
6 -- Note: This is currently broken due to a bug in Irrlicht, leave at 0
7 local mummy_animation_blend
= 0
9 -- Default player appearance
10 local mummy_mesh
= "pyramids_mummy.x"
11 local mummy_texture
= {"pyramids_mummy.png"}
13 local mummy_drop
= "default:papyrus"
15 local sound_normal
= "mummy"
16 local sound_hit
= "mummy_hurt"
17 local sound_dead
= "mummy_death"
19 local spawner_range
= 17
20 local spawner_max_mobs
= 6
22 local function get_animations()
46 local ANIM_WALK_MINE
= 5
52 textures
= {"pyramids_mummy.png^pyramids_hit.png"},
54 self
.object
:set_properties(prop
)
55 minetest
.after(0.4, function()
56 local prop
= {textures
= mummy_texture
,}
57 self
.object
:set_properties(prop
)
61 function mummy_update_visuals_def(self
)
62 --local name = get_player_name()
63 --visual = default_model_def
64 npc_anim
= 0 -- Animation will be set further below immediately
65 --npc_sneak[name] = false
68 textures
= mummy_texture
,
69 --visual_size = {x=1, y=1, z=1},
71 self
.object
:set_properties(prop
)
76 collisionbox
= {-0.4, -0.01, -0.4, 0.4, 1.9, 0.4},
78 visual_size
= {x
=8,y
=8},
80 textures
= mummy_texture
,
81 makes_footstep_sound
= true,
100 collisionbox
= {0,0,0,0,0,0},
102 visual_size
= {x
=3.3,y
=3.3},
104 textures
= mummy_texture
,
105 makes_footstep_sound
= false,
107 automatic_rotate
= math
.pi
* 2.9,
111 spawner_DEF
.on_activate
= function(self
)
112 mummy_update_visuals_def(self
)
113 self
.object
:setvelocity({x
=0, y
=0, z
=0})
114 self
.object
:setacceleration({x
=0, y
=0, z
=0})
115 self
.object
:set_armor_groups({immortal
=1})
119 spawner_DEF
.on_step
= function(self
, dtime
)
120 self
.timer
= self
.timer
+ 0.01
121 local n
= minetest
.get_node_or_nil(self
.object
:getpos())
122 if self
.timer
> 1 then
123 if n
and n
.name
and n
.name
~= "pyramids:spawner_mummy" then
129 spawner_DEF
.on_punch
= function(self
, hitter
)
133 MUMMY_DEF
.on_activate
= function(self
)
134 mummy_update_visuals_def(self
)
135 self
.anim
= get_animations()
136 self
.object
:set_animation({x
=self
.anim
.stand_START
,y
=self
.anim
.stand_END
}, mummy_animation_speed
, mummy_animation_blend
)
137 self
.npc_anim
= ANIM_STAND
138 self
.object
:setacceleration({x
=0,y
=-20,z
=0})--20
140 self
.object
:set_hp(mummy_hp
)
141 self
.object
:set_armor_groups({fleshy
=130})
144 MUMMY_DEF
.on_punch
= function(self
, puncher
, time_from_last_punch
, tool_capabilities
, dir
)
147 --[[for _,object in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 5)) do
148 if not object:is_player() then
149 if object:get_luaentity().name == "peaceful_npc:npc_def" then
150 object:get_luaentity().state = 3
151 object:get_luaentity().attacker = puncher:get_player_name()
156 --if self.state ~= 3 then
158 self
.attacker
= puncher
--:get_player_name()
161 if puncher
~= nil then
162 local sound
= sound_hit
163 if self
.object
:get_hp() == 0 then sound
= sound_dead
end
164 minetest
.sound_play(sound
, {to_player
= puncher
:get_player_name(), loop
= false, gain
= 0.3})
165 if time_from_last_punch
>= 0.45 then
167 --local dir = puncher:get_look_dir()
168 --self.direction = dir
169 self
.direction
= {x
=self
.object
:getvelocity().x
, y
=self
.object
:getvelocity().y
, z
=self
.object
:getvelocity().z
}
171 self
.object
:setvelocity({x
=dir
.x
*mummy_chillaxin_speed
,y
=5,z
=dir
.z
*mummy_chillaxin_speed
})--self.object:setvelocity({x=dir.x*4,y=5,z=dir.z*4})
172 if self
.state
== 1 then
174 elseif self
.state
>= 2 then
180 if self
.object
:get_hp() == 0 then
181 local obj
= minetest
.env
:add_item(self
.object
:getpos(), mummy_drop
.." "..math
.random(0,3))
188 MUMMY_DEF
.on_step
= function(self
, dtime
)
189 self
.timer
= self
.timer
+ 0.01
190 self
.turn_timer
= self
.turn_timer
+ 0.01
191 self
.jump_timer
= self
.jump_timer
+ 0.01
192 self
.punch_timer
= self
.punch_timer
+ 0.01
193 self
.attacking_timer
= self
.attacking_timer
+ 0.01
194 self
.sound_timer
= self
.sound_timer
+ 0.01
196 local current_pos
= self
.object
:getpos()
197 local current_node
= minetest
.env
:get_node(current_pos
)
198 if self
.time_passed
== nil then
202 --self.time_passed = self.time_passed + dtime
203 if self
.object
:get_hp() == 0 then-- self.object:remove() end
205 --if self.time_passed >= 5 then
206 minetest
.sound_play(sound_dead
, {pos
= current_pos
, max_hear_distance
= 10 , gain
= 0.3})
209 if current_node
.name
== "default:water_source" or current_node
.name
== "default:water_flowing" or current_node
.name
== "default:lava_source" or current_node
.name
== "default:lava_flowing" then
210 --self.time_passed = self.time_passed + dtime
211 self
.sound_timer
= self
.sound_timer
+ dtime
212 if self
.sound_timer
>= 0.8 then
214 self
.object
:set_hp(self
.object
:get_hp()-5)
216 minetest
.sound_play(sound_hit
, {pos
= current_pos
, max_hear_distance
= 10, gain
= 0.3})
223 --update moving state every 1 or 2 seconds
224 if self
.state
< 3 then
225 if self
.timer
> math
.random(1,2) then
226 if self
.attacker
== "" then
227 self
.state
= math
.random(1,2)
228 else self
.state
= 1 end
234 if self
.sound_timer
> math
.random(5,35) then
235 minetest
.sound_play(sound_normal
, {pos
= current_pos
, max_hear_distance
= 10, gain
= 0.2})
240 if self
.state
>= 8 then
241 if self
.punch_timer
> 0.15 then
242 --self.direction = {x = math.sin(self.yaw)*-1, y = -20, z = math.cos(self.yaw)}
243 if self
.state
== 9 then
244 self
.object
:setvelocity({x
=self
.direction
.x
*mummy_chillaxin_speed
,y
=-20,z
=self
.direction
.z
*mummy_chillaxin_speed
})
246 elseif self
.state
== 8 then
247 self
.object
:setvelocity({x
=0,y
=-20,z
=0})
254 if self
.state
== 1 then
257 for _
,object
in ipairs(minetest
.env
:get_objects_inside_radius(self
.object
:getpos(), 4)) do
258 if object
:is_player() then
260 local NPC
= self
.object
:getpos()
261 local PLAYER
= object
:getpos()
262 self
.vec
= {x
=PLAYER
.x
-NPC
.x
, y
=PLAYER
.y
-NPC
.y
, z
=PLAYER
.z
-NPC
.z
}
263 self
.yaw
= math
.atan(self
.vec
.z
/self
.vec
.x
)+math
.pi^
2
264 if PLAYER
.x
> NPC
.x
then
265 self
.yaw
= self
.yaw
+ math
.pi
267 self
.yaw
= self
.yaw
- 2
268 self
.object
:setyaw(self
.yaw
)
269 self
.attacker
= object
--:get_player_name()
273 if self
.attacker
== "" and self
.turn_timer
> math
.random(1,4) then--and yawwer == true then
274 self
.yaw
= 360 * math
.random()
275 self
.object
:setyaw(self
.yaw
)
277 self
.direction
= {x
= math
.sin(self
.yaw
)*-1, y
= -20, z
= math
.cos(self
.yaw
)}
279 self
.object
:setvelocity({x
=0,y
=self
.object
:getvelocity().y
,z
=0})
280 if self
.npc_anim
~= ANIM_STAND
then
281 self
.anim
= get_animations()
282 self
.object
:set_animation({x
=self
.anim
.stand_START
,y
=self
.anim
.stand_END
}, mummy_animation_speed
, mummy_animation_blend
)
283 self
.npc_anim
= ANIM_STAND
285 if self
.attacker
~= "" then
286 self
.direction
= {x
= math
.sin(self
.yaw
)*-1, y
= -20, z
= math
.cos(self
.yaw
)}
291 if self
.state
== 2 then
293 if self
.direction
~= nil then
294 self
.object
:setvelocity({x
=self
.direction
.x
*mummy_chillaxin_speed
,y
=self
.object
:getvelocity().y
,z
=self
.direction
.z
*mummy_chillaxin_speed
})
296 if self
.turn_timer
> math
.random(1,4) and not self
.attacker
then
297 self
.yaw
= 360 * math
.random()
298 self
.object
:setyaw(self
.yaw
)
300 self
.direction
= {x
= math
.sin(self
.yaw
)*-1, y
= -20, z
= math
.cos(self
.yaw
)}
301 --self.object:setvelocity({x=self.direction.x,y=self.object:getvelocity().y,z=direction.z})
302 --self.object:setacceleration(self.direction)
304 if self
.npc_anim
~= ANIM_WALK
then
305 self
.anim
= get_animations()
306 self
.object
:set_animation({x
=self
.anim
.walk_START
,y
=self
.anim
.walk_END
}, mummy_animation_speed
, mummy_animation_blend
)
307 self
.npc_anim
= ANIM_WALK
310 if self.direction ~= nil then
311 if self.jump_timer > 0.3 then
312 if minetest.env:get_node({x=self.object:getpos().x + self.direction.x,y=self.object:getpos().y-1,z=self.object:getpos().z + self.direction.z}).name ~= "air" then
313 self.object:setvelocity({x=self.object:getvelocity().x,y=5,z=self.object:getvelocity().z})
319 if self
.attacker
~= "" and minetest
.setting_getbool("enable_damage") then
320 local s
= self
.object
:getpos()
321 local p
= self
.attacker
:getpos()
322 if (s
~= nil and p
~= nil) then
323 local dist
= ((p
.x
-s
.x
)^
2 + (p
.y
-s
.y
)^
2 + (p
.z
-s
.z
)^
2)^
0.5
325 if dist
< 2 and self
.attacking_timer
> 0.6 then
326 self
.attacker
:punch(self
.object
, 1.0, {
327 full_punch_interval
=1.0,
328 damage_groups
= {fleshy
=1}
330 self
.attacking_timer
= 0
337 minetest
.register_entity("pyramids:mummy", MUMMY_DEF
)
338 minetest
.register_entity("pyramids:mummy_spawner", spawner_DEF
)
343 minetest
.register_craftitem("pyramids:spawn_egg", {
344 description
= "Mummy spawn-egg",
345 inventory_image
= "pyramids_mummy_egg.png",
346 liquids_pointable
= false,
348 on_place
= function(itemstack
, placer
, pointed_thing
)
349 if pointed_thing
.type == "node" then
350 minetest
.env
:add_entity(pointed_thing
.above
,"pyramids:mummy")
351 if not minetest
.setting_getbool("creative_mode") then itemstack
:take_item() end
358 function pyramids
.spawn_mummy (pos
, number)
360 minetest
.env
:add_entity(pos
,"pyramids:mummy")
364 minetest
.register_node("pyramids:spawner_mummy", {
365 description
= "Mummy spawner",
367 tiles
= {"pyramids_spawner.png"},
368 is_ground_content
= true,
369 drawtype
= "allfaces",--_optional",
370 groups
= {cracky
=1,level
=1},
372 on_construct
= function(pos
)
374 minetest
.env
:add_entity(pos
,"pyramids:mummy_spawner")
376 on_destruct
= function(pos
)
377 for _
,obj
in ipairs(minetest
.env
:get_objects_inside_radius(pos
, 1)) do
378 if not obj
:is_player() then
379 if obj
~= nil and obj
:get_luaentity().m_name
== "dummy" then
386 if not minetest
.setting_getbool("only_peaceful_mobs") then
387 minetest
.register_abm({
388 nodenames
= {"pyramids:spawner_mummy"},
391 action
= function(pos
, node
, active_object_count
, active_object_count_wider
)
392 local player_near
= false
394 for _
,obj
in ipairs(minetest
.env
:get_objects_inside_radius(pos
, spawner_range
)) do
395 if obj
:is_player() then
398 if obj
:get_luaentity().mob_name
== "mummy" then mobs
= mobs
+ 1 end
402 if mobs
< spawner_max_mobs
then
404 local p
= minetest
.find_node_near(pos
, 5, {"air"})
405 minetest
.env
:add_entity(p
,"pyramids:mummy")