add shooting sword - only obtainable by drops

master
Juraj Vajda 2017-08-09 22:18:37 +02:00
parent 30ead76735
commit e04e0c4405
7 changed files with 208 additions and 9 deletions

Binary file not shown.

Binary file not shown.

217
init.lua
View File

@ -1,15 +1,15 @@
--
--Init
-- Init
--
dofile(minetest.get_modpath("obsidianmese").."/api.lua")
dofile(minetest.get_modpath("obsidianmese").."/obsidianmese_chest.lua")
--
--Tools
-- Tools
--
-- sword
-- sword - mese
minetest.register_tool("obsidianmese:sword", {
description = "Obsidian Mese Sword",
inventory_image = "obsidianmese_sword.png",
@ -26,6 +26,205 @@ minetest.register_tool("obsidianmese:sword", {
}
})
-- sword - engraved
-- check if within physical map limits (-30911 to 30927)
local fired_table = {}
local within_limits = function(pos, radius)
if (pos.x - radius) > -30913
and (pos.x + radius) < 30928
and (pos.y - radius) > -30913
and (pos.y + radius) < 30928
and (pos.z - radius) > -30913
and (pos.z + radius) < 30928 then
return true -- within limits
end
return false -- beyond limits
end
local sync_table = function(owner)
if fired_table[owner] ~= nil then
fired_table[owner] = fired_table[owner] - 1
-- print(minetest.serialize(fired_table))
end
end
minetest.register_entity("obsidianmese:sword_bullet", {
physical = false,
visual = "sprite",
visual_size = { x = 1, y = 1 },
textures = { "obsidianmese_shard.png" },
collisionbox = {0.25, 0.25, 0.25, -0.25, -0.25, -0.25},
timer = 0,
speed = 8,
owner = "",
on_activate = function(self, staticdata, dtime_s)
self.object:set_armor_groups({ immortal = 1 })
end,
on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
if time_from_last_punch < 0.5 then return end
local name = puncher:get_player_name()
local pos = self.object:getpos()
local v = math.random(1, 8)
local velocity = dir
velocity.x = velocity.x * v
velocity.y = velocity.y * v
velocity.z = velocity.z * v
self.object:setvelocity(velocity)
end,
on_step = function(self, dtime)
local pos = self.object:getpos()
local node = minetest.get_node_or_nil(pos)
self.timer = self.timer + 1
if self.timer > 50
or not within_limits(pos, 0) then
sync_table(self.owner)
self.object:remove()
return
end
-- hit node
if node
and minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].walkable then
sync_table(self.owner)
self.object:remove()
return
end
-- hit player or mob
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.0)) do
if player:is_player() then
player:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = 8},
}, nil)
sync_table(self.owner)
self.object:remove()
return
end
local entity = player:get_luaentity()
if entity
and entity._cmi_is_mob == true
and entity.name ~= self.object:get_luaentity().name then
player:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = 8},
}, nil)
sync_table(self.owner)
self.object:remove()
return
end
end
self.lastpos = pos
end
})
function fire_sword(itemstack, user, pointed_thing)
local speed = 8
local pos = user:getpos()
local v = user:get_look_dir()
local player_name = user:get_player_name()
if fired_table[player_name] ~= nil then
if fired_table[player_name] >= 1 then
minetest.chat_send_player(player_name, "You can shoot 1 shot at the same time!")
return
else
fired_table[player_name] = fired_table[player_name] + 1
end
else
fired_table[player_name] = 1
end
-- print(minetest.serialize(fired_table))
pos.x = pos.x + v.x
pos.z = pos.z + v.z
if v.y > 0.4 or v.y < -0.4 then
pos.y = pos.y + v.y
else
pos.y = pos.y + 1
end
-- play shoot attack sound
minetest.sound_play("throwing_sound", {
pos = pos,
gain = 1.0, -- default
max_hear_distance = 32, -- default, uses an euclidean metric
})
local obj = minetest.add_entity(pos, "obsidianmese:sword_bullet")
local ent = obj:get_luaentity()
ent.owner = player_name or ""
if ent then
v.x = v.x * speed
v.y = v.y * speed
v.z = v.z * speed
obj:setvelocity(v)
else
obj:remove() -- arrow entity does not exist
end
-- wear tool
local wdef = itemstack:get_definition()
itemstack:add_wear(65535 / (150 - 1))
-- Tool break sound
if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then
minetest.sound_play(wdef.sound.breaks, {pos = pointed_thing.above, gain = 0.5})
end
return itemstack
end
minetest.register_tool("obsidianmese:sword_engraved", {
description = "Obsidian Mese Sword Engraved - right click shoot 1 shot",
inventory_image = "obsidianmese_sword_diamond_engraved.png",
tool_capabilities = {
full_punch_interval = 0.6,
max_drop_level=1,
groupcaps={
snappy={times={[1]=1.90, [2]=0.90, [3]=0.30}, uses=300, maxlevel=3},
},
damage_groups = {fleshy=8},
sound = {breaks = "default_tool_breaks"},
},
on_secondary_use = function(itemstack, user, pointed_thing)
if user:get_player_control().RMB then
return fire_sword(itemstack, user, pointed_thing)
end
end
})
-- pick axe
minetest.register_tool("obsidianmese:pick", {
description = "Obsidian Mese Pickaxe",
@ -34,9 +233,9 @@ minetest.register_tool("obsidianmese:pick", {
full_punch_interval = 0.9,
max_drop_level=3,
groupcaps={
cracky={times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=300, maxlevel=3},
crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=400, maxlevel=3},
snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=350, maxlevel=3}
cracky={times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=250, maxlevel=3},
crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=350, maxlevel=3},
snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=300, maxlevel=3}
},
damage_groups = {fleshy=5},
sound = {breaks = "default_tool_breaks"},
@ -55,8 +254,8 @@ minetest.register_craftitem("obsidianmese:mese_apple", {
minetest.sound_play("apple_eat", {
pos = user:getpos(),
max_hear_distance = 100,
gain = 0.7,
max_hear_distance = 32,
gain = 0.5,
})
user:set_hp(20)
@ -66,7 +265,7 @@ minetest.register_craftitem("obsidianmese:mese_apple", {
})
--
--Crafting
-- Crafting
--
minetest.register_craft({

BIN
sounds/throwing_sound.ogg Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 B

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B