tidied code
This commit is contained in:
parent
ca5b4d2e7c
commit
cf805ebe67
61
api.lua
61
api.lua
@ -1,11 +1,11 @@
|
|||||||
-- Mobs Api (8th April 2015)
|
-- Mobs Api (10th April 2015)
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
|
|
||||||
-- Do mobs spawn in protected areas (0=yes, 1=no)
|
-- Do mobs spawn in protected areas (0=yes, 1=no)
|
||||||
mobs.protected = 0
|
mobs.protected = 0
|
||||||
|
|
||||||
-- Initial check to see if damage is enabled and peaceful mode active
|
-- Initial settings check
|
||||||
local damage_enabled = minetest.setting_getbool("enable_damage")
|
local damage_enabled = minetest.setting_getbool("enable_damage")
|
||||||
local peaceful_only = minetest.setting_getbool("only_peaceful_mobs")
|
local peaceful_only = minetest.setting_getbool("only_peaceful_mobs")
|
||||||
local enable_blood = minetest.setting_getbool("mobs_enable_blood") or true
|
local enable_blood = minetest.setting_getbool("mobs_enable_blood") or true
|
||||||
@ -21,6 +21,7 @@ jump_height = def.jump_height or 6,
|
|||||||
jump_chance = def.jump_chance or 0,
|
jump_chance = def.jump_chance or 0,
|
||||||
footstep = def.footstep,
|
footstep = def.footstep,
|
||||||
rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
||||||
|
lifetimer = def.lifetimer or 600,
|
||||||
hp_min = def.hp_min or 5,
|
hp_min = def.hp_min or 5,
|
||||||
hp_max = def.hp_max or 10,
|
hp_max = def.hp_max or 10,
|
||||||
physical = true,
|
physical = true,
|
||||||
@ -69,7 +70,6 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
env_damage_timer = 0, -- only if state = "attack"
|
env_damage_timer = 0, -- only if state = "attack"
|
||||||
attack = {player=nil, dist=nil},
|
attack = {player=nil, dist=nil},
|
||||||
state = "stand",
|
state = "stand",
|
||||||
lifetimer = 600,
|
|
||||||
tamed = false,
|
tamed = false,
|
||||||
pause_timer = 0,
|
pause_timer = 0,
|
||||||
horny = false,
|
horny = false,
|
||||||
@ -164,22 +164,20 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
|
|
||||||
if self.type == "monster" and peaceful_only then
|
if self.type == "monster" and peaceful_only then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.lifetimer = self.lifetimer - dtime
|
if self.type ~= "npc" and not self.tamed then
|
||||||
if self.lifetimer <= 0 and not self.tamed and self.type ~= "npc" then
|
self.lifetimer = self.lifetimer - dtime
|
||||||
local player_count = 0
|
end
|
||||||
|
if self.lifetimer <= 0 and self.state ~= "attack" then
|
||||||
for _,obj in ipairs(minetest.get_objects_inside_radius(self.object:getpos(), 10)) do
|
for _,obj in ipairs(minetest.get_objects_inside_radius(self.object:getpos(), 10)) do
|
||||||
if obj:is_player() then
|
if obj:is_player() then
|
||||||
player_count = player_count + 1
|
minetest.log("action","lifetimer expired, removed mob "..self.name)
|
||||||
break -- only really need 1 player to be found
|
self.object:remove()
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if player_count == 0 and self.state ~= "attack" then
|
|
||||||
minetest.log("action","lifetimer expired, removed mob "..self.name)
|
|
||||||
self.object:remove()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat)
|
-- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat)
|
||||||
@ -215,8 +213,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
self.old_y = self.object:getpos().y
|
self.old_y = self.object:getpos().y
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if pause state then this is where the loop ends
|
-- knock back timer
|
||||||
-- pause is only set after a monster is hit
|
|
||||||
if self.pause_timer > 0 then
|
if self.pause_timer > 0 then
|
||||||
self.pause_timer = self.pause_timer - dtime
|
self.pause_timer = self.pause_timer - dtime
|
||||||
if self.pause_timer < 1 then
|
if self.pause_timer < 1 then
|
||||||
@ -225,6 +222,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- attack timer
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
if self.state ~= "attack" then
|
if self.state ~= "attack" then
|
||||||
if self.timer < 1 then
|
if self.timer < 1 then
|
||||||
@ -269,7 +267,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
|
|
||||||
local do_jump = function(self)
|
local do_jump = function(self)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
pos.y = pos.y - (-self.collisionbox[2]+self.collisionbox[5])
|
pos.y = pos.y - (-self.collisionbox[2] + self.collisionbox[5])
|
||||||
local nod = minetest.get_node(pos)
|
local nod = minetest.get_node(pos)
|
||||||
if not nod or not minetest.registered_nodes[nod.name]
|
if not nod or not minetest.registered_nodes[nod.name]
|
||||||
or minetest.registered_nodes[nod.name].walkable == false then return end
|
or minetest.registered_nodes[nod.name].walkable == false then return end
|
||||||
@ -282,6 +280,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- environmental damage timer
|
||||||
self.env_damage_timer = self.env_damage_timer + dtime
|
self.env_damage_timer = self.env_damage_timer + dtime
|
||||||
if self.state == "attack" and self.env_damage_timer > 1 then
|
if self.state == "attack" and self.env_damage_timer > 1 then
|
||||||
self.env_damage_timer = 0
|
self.env_damage_timer = 0
|
||||||
@ -290,7 +289,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
do_env_damage(self)
|
do_env_damage(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- FIND SOMEONE TO ATTACK
|
-- find someone to attack
|
||||||
if self.type == "monster" and damage_enabled and self.state ~= "attack" then
|
if self.type == "monster" and damage_enabled and self.state ~= "attack" then
|
||||||
|
|
||||||
local s = self.object:getpos()
|
local s = self.object:getpos()
|
||||||
@ -328,7 +327,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- NPC FIND A MONSTER TO ATTACK
|
-- npc, find monster to attack
|
||||||
if self.type == "npc" and self.attacks_monsters and self.state ~= "attack" then
|
if self.type == "npc" and self.attacks_monsters and self.state ~= "attack" then
|
||||||
local s = self.object:getpos()
|
local s = self.object:getpos()
|
||||||
local obj = nil
|
local obj = nil
|
||||||
@ -377,10 +376,8 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
local num = 0
|
local num = 0
|
||||||
local ent = nil
|
local ent = nil
|
||||||
for i,obj in ipairs(ents) do
|
for i,obj in ipairs(ents) do
|
||||||
|
|
||||||
ent = obj:get_luaentity()
|
ent = obj:get_luaentity()
|
||||||
if ent and ent.name == self.name and ent.horny == true and ent.hornytimer <= 40 then num = num + 1 end
|
if ent and ent.name == self.name and ent.horny == true and ent.hornytimer <= 40 then num = num + 1 end
|
||||||
|
|
||||||
if num > 1 then
|
if num > 1 then
|
||||||
self.hornytimer = 41
|
self.hornytimer = 41
|
||||||
ent.hornytimer = 41
|
ent.hornytimer = 41
|
||||||
@ -407,6 +404,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- find player to follow
|
||||||
if (self.follow ~= "" or self.order == "follow") and not self.following and self.state ~= "attack" then
|
if (self.follow ~= "" or self.order == "follow") and not self.following and self.state ~= "attack" then
|
||||||
local s, p, dist
|
local s, p, dist
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
@ -432,8 +430,8 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- follow player or mob
|
||||||
if self.following then
|
if self.following then
|
||||||
|
|
||||||
local s = self.object:getpos()
|
local s = self.object:getpos()
|
||||||
local p
|
local p
|
||||||
|
|
||||||
@ -520,7 +518,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
self.set_animation(self, "walk")
|
self.set_animation(self, "walk")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ADDED jumping mobs only
|
-- jumping mobs only
|
||||||
if self.jump_chance ~= 0 and math.random(1, 100) <= self.jump_chance then
|
if self.jump_chance ~= 0 and math.random(1, 100) <= self.jump_chance then
|
||||||
do_jump(self)
|
do_jump(self)
|
||||||
self.set_velocity(self, self.walk_velocity)
|
self.set_velocity(self, self.walk_velocity)
|
||||||
@ -572,7 +570,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
end
|
end
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
if self.attack.dist > 2 then
|
if self.attack.dist > 2 then
|
||||||
-- ADDED if not in air and jump_chance isnt 0 them jump attack
|
-- jump attack
|
||||||
if (self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0)
|
if (self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0)
|
||||||
or (self.object:getvelocity().y == 0 and self.jump_chance > 0) then
|
or (self.object:getvelocity().y == 0 and self.jump_chance > 0) then
|
||||||
do_jump(self)
|
do_jump(self)
|
||||||
@ -672,7 +670,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
if self.type ~= "npc" then
|
if self.type ~= "npc" then
|
||||||
self.lifetimer = 600 - dtime_s
|
self.lifetimer = self.lifetimer - dtime_s
|
||||||
end
|
end
|
||||||
if staticdata then
|
if staticdata then
|
||||||
local tmp = minetest.deserialize(staticdata)
|
local tmp = minetest.deserialize(staticdata)
|
||||||
@ -771,7 +769,7 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
|
|
||||||
--blood_particles
|
--blood_particles
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
pos.y = pos.y + (self.collisionbox[2] + self.collisionbox[5]) / 2
|
pos.y = pos.y + (-self.collisionbox[2] + self.collisionbox[5]) / 2
|
||||||
if self.blood_amount > 0 and pos and enable_blood == true then
|
if self.blood_amount > 0 and pos and enable_blood == true then
|
||||||
effect(pos, self.blood_amount, self.blood_texture)
|
effect(pos, self.blood_amount, self.blood_texture)
|
||||||
end
|
end
|
||||||
@ -780,18 +778,13 @@ rotate = def.rotate or 0, -- 0=front, 1.5=side, 3.0=back, 4.5=side2
|
|||||||
-- https://github.com/BlockMen/pyramids
|
-- https://github.com/BlockMen/pyramids
|
||||||
local kb = self.knock_back
|
local kb = self.knock_back
|
||||||
local r = self.recovery_time
|
local r = self.recovery_time
|
||||||
|
local ykb = 2
|
||||||
|
local v = self.object:getvelocity()
|
||||||
if tflp < tool_capabilities.full_punch_interval then
|
if tflp < tool_capabilities.full_punch_interval then
|
||||||
kb = kb * ( tflp / tool_capabilities.full_punch_interval )
|
kb = kb * ( tflp / tool_capabilities.full_punch_interval )
|
||||||
r = r * ( tflp / tool_capabilities.full_punch_interval )
|
r = r * ( tflp / tool_capabilities.full_punch_interval )
|
||||||
end
|
end
|
||||||
|
if v.y ~= 0 then ykb = 0 end
|
||||||
local ykb=2
|
|
||||||
local v = self.object:getvelocity()
|
|
||||||
if v.y ~= 0 then
|
|
||||||
ykb = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
self.object:setvelocity({x=dir.x*kb,y=ykb,z=dir.z*kb})
|
self.object:setvelocity({x=dir.x*kb,y=ykb,z=dir.z*kb})
|
||||||
self.pause_timer = r
|
self.pause_timer = r
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user