Rewrite water and lava damage and add damage params to defintion

master
PilzAdam 2012-09-19 18:54:30 +02:00
parent 8929fda7e7
commit 5ec7ae8f21
3 changed files with 34 additions and 7 deletions

View File

@ -44,7 +44,7 @@ This mod add some functions that you can use in other mods:
makes_footstep_sound: same is in minetest.register_entity()
view_range: the range in that the monster will see the player
and follow him
walk_velocity: the velocity when the monster is walking arround
walk_velocity: the velocity when the monster is walking around
run_velocity: the velocity when the monster is attacking a player
damage: the damage per second
light_resistant: light wont cause damage on day
@ -52,6 +52,8 @@ This mod add some functions that you can use in other mods:
drop_count: the number of items that are dropped
armor: the armor (integer)(3=lowest; 1=highest)(fleshy group is used)
drawtype: "front" or "side"
water_damage: the damage per second if the mob is in water
lava_damage: the damage per second if the mob is in lava
2. mobs:register_animal(name, def)
This adds a animal to Minetest that will just walk arround
"name" is the name of the monster ("[modname]:[animalname]")

25
api.lua
View File

@ -13,6 +13,8 @@ function mobs:register_monster(name, def)
run_velocity = def.run_velocity,
damage = def.damage,
light_resistant = def.light_resistant,
water_damage = def.water_damage,
lava_damage = def.lava_damage,
drop = def.drop,
drop_count = def.drop_count,
armor = def.armor,
@ -69,20 +71,20 @@ function mobs:register_monster(name, def)
}, nil)
end
if string.find(minetest.env:get_node(self.object:getpos()).name, "default:water") then
if self.water_damage and self.water_damage ~= 0 and string.find(minetest.env:get_node(self.object:getpos()).name, "default:water") then
self.object:punch(self.object, 1.0, {
full_punch_interval=1.0,
groupcaps={
fleshy={times={[3]=1/1}},
fleshy={times={[self.armor]=1/self.water_damage}},
}
}, nil)
end
if string.find(minetest.env:get_node(self.object:getpos()).name, "default:lava") then
if self.lava_damage and self.lava_damage ~= 0 and string.find(minetest.env:get_node(self.object:getpos()).name, "default:lava") then
self.object:punch(self.object, 1.0, {
full_punch_interval=1.0,
groupcaps={
fleshy={times={[3]=1/2}},
fleshy={times={[self.armor]=1/self.lava_damage}},
}
}, nil)
end
@ -242,6 +244,8 @@ function mobs:register_animal(name, def)
on_rightclick = def.on_rightclick,
drop_count = def.drop_count,
drawtype = def.drawtype,
water_damage = def.water_damage,
lava_damage = def.lava_damage,
timer = 0,
state = "stand",
@ -281,11 +285,20 @@ function mobs:register_animal(name, def)
end
self.timer = 0
if string.find(minetest.env:get_node(self.object:getpos()).name, "default:lava") then
if self.water_damage and self.water_damage ~= 0 and string.find(minetest.env:get_node(self.object:getpos()).name, "default:water") then
self.object:punch(self.object, 1.0, {
full_punch_interval=1.0,
groupcaps={
fleshy={times={[3]=1/2}},
fleshy={times={[3]=1/self.water_damage}},
}
}, nil)
end
if self.lava_damage and self.lava_damage ~= 0 and string.find(minetest.env:get_node(self.object:getpos()).name, "default:lava") then
self.object:punch(self.object, 1.0, {
full_punch_interval=1.0,
groupcaps={
fleshy={times={[3]=1/self.lava_damage}},
}
}, nil)
end

View File

@ -15,6 +15,8 @@ mobs:register_monster("mobs:dirt_monster", {
drop_count = 3,
armor = 3,
drawtype = "front",
water_damage = 1,
lava_damage = 5,
})
mobs:register_spawn("mobs:dirt_monster", {"default:dirt_with_grass"}, 3, -1, 5000, 5)
@ -34,6 +36,8 @@ mobs:register_monster("mobs:stone_monster", {
light_resistant = true,
armor = 2,
drawtype = "front",
water_damage = 0,
lava_damage = 0,
})
mobs:register_spawn("mobs:stone_monster", {"default:stone"}, 3, -1, 5000, 5)
@ -54,6 +58,8 @@ mobs:register_monster("mobs:sand_monster", {
light_resistant = true,
armor = 3,
drawtype = "front",
water_damage = 3,
lava_damage = 1,
})
mobs:register_spawn("mobs:sand_monster", {"default:desert_sand"}, 20, -1, 5000, 5)
@ -68,6 +74,8 @@ mobs:register_animal("mobs:sheep", {
drop = "mobs:meat_raw",
drop_count = 2,
drawtype = "side",
water_damage = 1,
lava_damage = 5,
on_rightclick = function(self, clicker)
if self.naked then
@ -113,6 +121,8 @@ mobs:register_animal("mobs:rat", {
drop = "",
drop_count = 0,
drawtype = "side",
water_damage = 0,
lava_damage = 1,
on_rightclick = function(self, clicker)
if clicker:is_player() and clicker:get_inventory() then
@ -166,5 +176,7 @@ mobs:register_monster("mobs:oerkki", {
armor = 3,
drawtype = "front",
light_resistant = true,
water_damage = 1,
lava_damage = 1,
})
mobs:register_spawn("mobs:oerkki", {"default:stone"}, 2, -1, 5000, 5)