New drop system

This commit is contained in:
PilzAdam 2012-09-20 18:03:41 +02:00
parent b901a7875e
commit 86664b5cbb
3 changed files with 52 additions and 30 deletions

View File

@ -48,8 +48,11 @@ This mod add some functions that you can use in other mods:
walk_velocity: the velocity when the monster is walking around walk_velocity: the velocity when the monster is walking around
run_velocity: the velocity when the monster is attacking a player run_velocity: the velocity when the monster is attacking a player
damage: the damage per second damage: the damage per second
drop: the drop item of the monster drops: is list of tables with the following fields:
drop_count: the number of items that are dropped name: itemname
chance: the inverted chance (same as in abm) to get the item
min: the minimum number of items
max: the maximum number of items
armor: the armor (integer)(3=lowest; 1=highest)(fleshy group is used) armor: the armor (integer)(3=lowest; 1=highest)(fleshy group is used)
drawtype: "front" or "side" drawtype: "front" or "side"
water_damage: the damage per second if the mob is in water water_damage: the damage per second if the mob is in water

17
api.lua
View File

@ -15,8 +15,7 @@ function mobs:register_mob(name, def)
light_damage = def.light_damage, light_damage = def.light_damage,
water_damage = def.water_damage, water_damage = def.water_damage,
lava_damage = def.lava_damage, lava_damage = def.lava_damage,
drop = def.drop, drops = def.drops,
drop_count = def.drop_count,
armor = def.armor, armor = def.armor,
drawtype = def.drawtype, drawtype = def.drawtype,
on_rightclick = def.on_rightclick, on_rightclick = def.on_rightclick,
@ -235,12 +234,16 @@ function mobs:register_mob(name, def)
on_punch = function(self, hitter) on_punch = function(self, hitter)
if self.object:get_hp() <= 0 then if self.object:get_hp() <= 0 then
if hitter and hitter:is_player() and hitter:get_inventory() then if hitter and hitter:is_player() and hitter:get_inventory() then
for i=1,math.random(0,2)-1+self.drop_count do for _,drop in ipairs(self.drops) do
hitter:get_inventory():add_item("main", ItemStack(self.drop)) if math.random(1, drop.chance) == 1 then
hitter:get_inventory():add_item("main", ItemStack(drop.name.." "..math.random(drop.min, drop.max)))
end
end end
else else
for i=1,math.random(0,2)-1+self.drop_count do for _,drop in ipairs(self.drops) do
local obj = minetest.env:add_item(self.object:getpos(), self.drop) if math.random(1, drop.chance) == 1 then
for i=1,math.random(drop.min, drop.max) do
local obj = minetest.env:add_item(self.object:getpos(), drop.name)
if obj then if obj then
obj:get_luaentity().collect = true obj:get_luaentity().collect = true
local x = math.random(1, 5) local x = math.random(1, 5)
@ -256,6 +259,8 @@ function mobs:register_mob(name, def)
end end
end end
end end
end
end
end, end,
}) })

View File

@ -12,8 +12,12 @@ mobs:register_mob("mobs:dirt_monster", {
walk_velocity = 1, walk_velocity = 1,
run_velocity = 3, run_velocity = 3,
damage = 2, damage = 2,
drop = "default:dirt", drops = {
drop_count = 3, {name = "default:dirt",
chance = 1,
min = 3,
max = 5,},
},
armor = 3, armor = 3,
drawtype = "front", drawtype = "front",
water_damage = 1, water_damage = 1,
@ -35,8 +39,12 @@ mobs:register_mob("mobs:stone_monster", {
walk_velocity = 0.5, walk_velocity = 0.5,
run_velocity = 2, run_velocity = 2,
damage = 3, damage = 3,
drop = "default:mossycobble", drops = {
drop_count = 3, {name = "default:mossycobble",
chance = 1,
min = 3,
max = 5,},
},
light_resistant = true, light_resistant = true,
armor = 2, armor = 2,
drawtype = "front", drawtype = "front",
@ -59,8 +67,12 @@ mobs:register_mob("mobs:sand_monster", {
walk_velocity = 1.5, walk_velocity = 1.5,
run_velocity = 4, run_velocity = 4,
damage = 1, damage = 1,
drop = "default:sand", drops = {
drop_count = 3, {name = "default:sand",
chance = 1,
min = 3,
max = 5,},
},
light_resistant = true, light_resistant = true,
armor = 3, armor = 3,
drawtype = "front", drawtype = "front",
@ -80,8 +92,12 @@ mobs:register_mob("mobs:sheep", {
makes_footstep_sound = true, makes_footstep_sound = true,
walk_velocity = 1, walk_velocity = 1,
armor = 3, armor = 3,
drop = "mobs:meat_raw", drops = {
drop_count = 2, {name = "mobs:meat_raw",
chance = 1,
min = 2,
max = 3,},
},
drawtype = "side", drawtype = "side",
water_damage = 1, water_damage = 1,
lava_damage = 5, lava_damage = 5,
@ -130,8 +146,7 @@ mobs:register_mob("mobs:rat", {
makes_footstep_sound = false, makes_footstep_sound = false,
walk_velocity = 1, walk_velocity = 1,
armor = 3, armor = 3,
drop = "", drops = {},
drop_count = 0,
drawtype = "side", drawtype = "side",
water_damage = 0, water_damage = 0,
lava_damage = 1, lava_damage = 1,
@ -185,8 +200,7 @@ mobs:register_mob("mobs:oerkki", {
walk_velocity = 1, walk_velocity = 1,
run_velocity = 3, run_velocity = 3,
damage = 4, damage = 4,
drop = "", drops = {},
drop_count = 0,
armor = 3, armor = 3,
drawtype = "front", drawtype = "front",
light_resistant = true, light_resistant = true,