Working on the special weapons: fixed the axe of pride and added sword_of_gluttony and gratuitousness_battleaxe

master
npx 2016-11-06 16:11:40 +01:00
parent 3f2a47ff88
commit 4b8c0be212
2 changed files with 112 additions and 95 deletions

View File

@ -507,87 +507,3 @@ function midas_ability( --ability to transform every blocks it touches in the m
end
end
end
function check_for_death_obj(obj)
local hp = obj:get_hp()
-- still got some health? play hurt sound
if self.health > 0 then
if self.sounds.damage then
minetest.sound_play(self.sounds.damage, {
object = self.object,
gain = 1.0,
max_hear_distance = self.sounds.distance
})
end
-- make sure health isn't higher than max
if self.health > self.hp_max then
self.health = self.hp_max
end
-- backup nametag so we can show health stats
if not self.nametag2 then
self.nametag2 = self.nametag or ""
end
self.htimer = 2
self.nametag = "health: " .. self.health .. " of " .. self.hp_max
update_tag(self)
return false
end
-- drop items when dead
local obj
local pos = self.object:getpos()
for n = 1, #self.drops do
if random(1, self.drops[n].chance) == 1 then
obj = minetest.add_item(pos,
ItemStack(self.drops[n].name .. " "
.. random(self.drops[n].min, self.drops[n].max)))
if obj then
obj:setvelocity({
x = random(-10, 10) / 9,
y = 5,
z = random(-10, 10) / 9,
})
end
end
end
-- play death sound
if self.sounds.death then
minetest.sound_play(self.sounds.death, {
object = self.object,
gain = 1.0,
max_hear_distance = self.sounds.distance
})
end
-- execute custom death function
if self.on_die then
self.on_die(self, pos)
return true
end
-- default death function
self.object:remove()
effect(pos, 20, "tnt_smoke.png")
return true
end

View File

@ -780,9 +780,6 @@ minetest.register_tool("nssm:axe_of_pride", {
local flag = 0
for _,obj in ipairs(objects) do
if flag == 0 then
minetest.chat_send_all("Attenzione")
local pname = dropper:get_player_name()
local player_inv = minetest.get_inventory({type='player', name = pname})
@ -791,15 +788,11 @@ minetest.register_tool("nssm:axe_of_pride", {
else
local found = 0
for i = 1,32 do
--minetest.chat_send_all("Inventory is not empty")
local items = player_inv:get_stack('main', i)
local n = items:get_name()
if n == "nssm:energy_globe" then
if found == 0 then
found = 1
items:take_item()
player_inv:set_stack('main', i, items)
end
found = i
break
end
end
if found == 0 then
@ -811,14 +804,24 @@ minetest.register_tool("nssm:axe_of_pride", {
if (obj:get_player_name()~=dropper:get_player_name()) then
obj:set_hp(obj:get_hp()-10)
dropper:set_hp(dropper:get_hp()+10)
flag = 1
--flag = 1
local items = player_inv:get_stack('main', found)
items:take_item()
player_inv:set_stack('main', found, items)
end
else
if (obj:get_luaentity().health) then
--minetest.chat_send_all("Entity")
obj:get_luaentity().health = obj:get_luaentity().health -10
check_for_death(obj:get_luaentity())
dropper:set_hp(dropper:get_hp()+10)
flag = 1
--flag = 1
local items = player_inv:get_stack('main', found)
items:take_item()
player_inv:set_stack('main', found, items)
end
end
end
@ -841,6 +844,38 @@ minetest.register_tool("nssm:gratuitousness_battleaxe", {
},
damage_groups = {fleshy=18},
},
on_drop = function(itemstack, dropper, pos)
local objects = minetest.env:get_objects_inside_radius(pos, 10)
local flag = 0
local vec = dropper:get_look_dir()
local pos = dropper:getpos()
vec.y = 0
for i=1,10 do
pos = vector.add(pos, vec)
end
local pname = dropper:get_player_name()
local player_inv = minetest.get_inventory({type='player', name = pname})
local found = 0
for i = 1,32 do
local items = player_inv:get_stack('main', i)
local n = items:get_name()
if n == "nssm:energy_globe" then
found = i
break
end
end
if found == 0 then
minetest.chat_send_player(pname, "You haven't got any Energy Globe!")
return
else
local items = player_inv:get_stack('main', found)
items:take_item()
player_inv:set_stack('main', found, items)
explosion(pos, 5, 1)
end
end,
})
minetest.register_tool("nssm:sword_of_eagerness", {
@ -886,6 +921,72 @@ minetest.register_tool("nssm:sword_of_gluttony", {
},
damage_groups = {fleshy=14},
},
on_drop = function(itemstack, dropper, pos)
local objects = minetest.env:get_objects_inside_radius(pos, 10)
local flag = 0
for _,obj in ipairs(objects) do
if flag == 0 then
local pname = dropper:get_player_name()
local player_inv = minetest.get_inventory({type='player', name = pname})
if player_inv:is_empty('main') then
--minetest.chat_send_all("Inventory empty")
else
local found = 0
for i = 1,32 do
local items = player_inv:get_stack('main', i)
local n = items:get_name()
if n == "nssm:energy_globe" then
found = i
break
end
end
if found == 0 then
minetest.chat_send_player(pname, "You haven't got any Energy Globe!")
return
else
if (obj:is_player()) then
if (obj:get_player_name()~=dropper:get_player_name()) then
obj:set_hp(obj:get_hp()-10)
--flag = 1
--take energy globe from inventory:
local items = player_inv:get_stack('main', found)
items:take_item()
player_inv:set_stack('main', found, items)
end
else
if (obj:get_luaentity().health) then
if obj:get_luaentity().health <= 10 then
local pos = obj:getpos()
obj:remove()
--check_for_death(obj:get_luaentity())
--flag = 1
--take energy globe from inventory:
local items = player_inv:get_stack('main', found)
items:take_item()
player_inv:set_stack('main', found, items)
for i = 1,math.random(1,4) do
drop = minetest.add_item(pos, "nssm:roasted_duck_legs 1")
if drop then
drop:setvelocity({
x = math.random(-10, 10) / 9,
y = 5,
z = math.random(-10, 10) / 9,
})
end
end
end
end
end
end
end
end
end
end,
})
minetest.register_tool("nssm:death_scythe", {