jordan4ibanez wrote:I've seen this mob framework get laggier and laggier as time goes on. Please, use this for peaceful mobs.Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
mob.on_step = function(self, dtime)
self.timer = self.timer + 0.01
self.turn_timer = self.turn_timer + 0.01
self.jump_timer = self.jump_timer + 0.01
self.door_timer = self.door_timer + 0.01
self.present_timer = self.present_timer + 0.01
if self.timer > math.random(2,5) then
self.state = math.random(1,2)
self.timer = 0
end
--STANDING
if self.state == 1 then
self.yawwer = true
for _,object in ipairs(minetest.env:get_objects_inside_radius(self.object:getpos(), 3)) do
if object:is_player() then
self.yawwer = false
NPC = self.object:getpos()
PLAYER = object:getpos()
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if PLAYER.x > NPC.x then
self.yaw = self.yaw + math.pi
end
self.yaw = self.yaw - 2
self.object:setyaw(self.yaw)
end
end
if self.turn_timer > math.random(1,4) and yawwer == true then
self.yaw = 360 * math.random()
self.object:setyaw(self.yaw)
self.turn_timer = 0
end
self.object:setvelocity({x=0,y=self.object:getvelocity().y,z=0})
if self.player_anim ~= ANIM_STAND then
self.anim = player_get_animations(visual)
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, animation_speed_mod, animation_blend)
self.player_anim = ANIM_STAND
end
end
--WALKING
if self.state == 2 then
if self.present_timer > 1 then
minetest.env:add_item(self.object:getpos(),"default:coal_lump")
minetest.sound_play("fart", {pos=self.object:getpos(), gain=1.5, max_hear_distance=2*64})
self.present_timer = 0
end
if self.direction ~= nil then
self.object:setvelocity({x=self.direction.x*chillaxin_speed,y=self.object:getvelocity().y,z=self.direction.z*chillaxin_speed})
end
if self.turn_timer > math.random(1,4) then
self.yaw = 360 * math.random()
self.object:setyaw(self.yaw)
self.turn_timer = 0
self.direction = {x = math.sin(self.yaw)*-1, y = -10, z = math.cos(self.yaw)}
--self.object:setvelocity({x=self.direction.x,y=self.object:getvelocity().y,z=direction.z})
--self.object:setacceleration(self.direction)
end
if self.player_anim ~= ANIM_WALK then
self.anim = player_get_animations(visual)
self.object:set_animation({x=self.anim.walk_START,y=self.anim.walk_END}, animation_speed_mod, animation_blend)
self.player_anim = ANIM_WALK
end
--open a door [alpha]
if self.direction ~= nil then
if self.door_timer > 2 then
local is_a_door = minetest.env:get_node({x=self.object:getpos().x + self.direction.x,y=self.object:getpos().y,z=self.object:getpos().z + self.direction.z}).name
if is_a_door == "doors:door_wood_t_1" then
minetest.env:punch_node({x=self.object:getpos().x + self.direction.x,y=self.object:getpos().y-1,z=self.object:getpos().z + self.direction.z})
self.door_timer = 0
end
local is_in_door = minetest.env:get_node(self.object:getpos()).name
if is_in_door == "doors:door_wood_t_1" then
minetest.env:punch_node(self.object:getpos())
end
end
end
--jump
if self.direction ~= nil then
if self.jump_timer > 0.3 then
if minetest.registered_nodes[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].walkable then
self.object:setvelocity({x=self.object:getvelocity().x,y=5,z=self.object:getvelocity().z})
self.jump_timer = 0
end
end
end
end
end
Trust me, I have passive-till-aggressed, and aggressive ai too, please just use this for your mobs, they're plenty st00pid, and fun to work with, and you won't be wondering why your computer is spurting out fumes and smells like burning plastic after you change to this. Has extreme performance improvements, and allows for 200-300+ mobs in the same area without the server itself lagging. Please just use this so people can have fun with this mod.
If this works I suggest using this too. The more lag you can shave off, the better. Is there a way you could help with the creation of this mod, jordan4ibanez?