--these are helpers to create entities exploder = {} exploder.initial_properties = { physical = true, collide_with_objects = false, collisionbox = {-0.37, -0.4, -0.37, 0.37, 0.5, 0.37}, visual = "mesh", visual_size = {x = 3, y = 3}, mesh = "exploder.b3d", textures = { "grass.png","grass.png","grass.png","grass.png","grass.png","exploder_head.png" --"body.png","leg.png","leg.png","leg.png","leg.png" }, is_visible = true, pointable = true, automatic_face_movement_dir = -90.0, automatic_face_movement_max_rotation_per_sec = 300, --makes_footstep_sound = true, } exploder.hp = 10 exploder.speed = 5 exploder.jump_timer = 0 exploder.hurt_inside_timer = 0 exploder.death_animation_timer = 0 exploder.dead = false exploder.mob = true exploder.hostile = false exploder.hostile_timer = 0 exploder.timer = 0 exploder.state = 0 exploder.hunger = 200 exploder.view_distance = 20 exploder.punch_timer = 0 exploder.punched_timer = 0 --head stuff exploder.head_mount = vector.new(0,1.2,1.9) local path = minetest.get_modpath(minetest.get_current_modname()).."/exploder" dofile(path.."/timers.lua") --dofile(path.."/head_code.lua") dofile(path.."/movement_code.lua") dofile(path.."/data_handling_code.lua") dofile(path.."/interaction_code.lua") ---------------------------------- --repel from players exploder.push = function(self) local pos = self.object:getpos() local radius = 1 for _,object in ipairs(minetest.get_objects_inside_radius(pos, radius)) do if object:is_player() or object:get_luaentity().mob == true then local player_pos = object:getpos() pos.y = 0 player_pos.y = 0 local currentvel = self.object:getvelocity() local vel = vector.subtract(pos, player_pos) vel = vector.normalize(vel) local distance = vector.distance(pos,player_pos) distance = (radius-distance)*10 vel = vector.multiply(vel,distance) local acceleration = vector.new(vel.x-currentvel.x,0,vel.z-currentvel.z) self.object:add_velocity(acceleration) acceleration = vector.multiply(acceleration, 5) object:add_player_velocity(acceleration) end end end --sets the mob animation and speed exploder.set_animation = function(self) if self.speed == 0 or vector.equals(self.direction,vector.new(0,0,0)) then --self.object:set_animation({x=0,y=0}, 1, 0, true) else --self.object:set_animation({x=0,y=20}, 1, 0, true) local speed = self.object:get_velocity() speed.y = 0 --self.object:set_animation_frame_speed(vector.distance(vector.new(0,0,0),speed)*5) end end --this depletes the mobs hunger exploder.do_hunger = function(self,dtime) self.hunger = self.hunger - dtime end --this sets the state of the mob exploder.set_state = function(self,dtime) self.do_hunger(self,dtime) end exploder.on_step = function(self, dtime) self.manage_death_animation(self,dtime) if self.death_animation_timer == 0 then self.set_state(self,dtime) self.move(self,dtime) self.set_animation(self) self.look_around(self,dtime) self.manage_punch_timer(self,dtime) --self.debug_nametag(self,dtime) end --fix zombie state again if self.dead == true and self.death_animation_timer <= 0 then self.on_death(self) end end minetest.register_entity("mob:exploder", exploder) ------------------------------------------------------------------------the head --[[ exploder.head = {} exploder.head.initial_properties = { hp_max = 1, physical = false, collide_with_objects = false, collisionbox = {0, 0, 0, 0, 0, 0}, visual = "mesh", visual_size = {x = 1.1, y = 1.1}, mesh = "exploder.b3d", textures = { "grass.png" }, is_visible = true, pointable = false, --automatic_face_movement_dir = 0.0, --automatic_face_movement_max_rotation_per_sec = 600, } --remove the head if no body exploder.head.on_step = function(self, dtime) if self.parent == nil then self.object:remove() end end minetest.register_entity("mob:exploder_head", exploder.head) ]]--