add siege hammer
untested
This commit is contained in:
parent
4decb85583
commit
4c77e01461
21
mods/siege_hammer/LICENSE
Normal file
21
mods/siege_hammer/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Coder12a
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
3
mods/siege_hammer/depends.txt
Normal file
3
mods/siege_hammer/depends.txt
Normal file
@ -0,0 +1,3 @@
|
||||
ctf_protect
|
||||
ctf
|
||||
chatplus?
|
1
mods/siege_hammer/description.txt
Normal file
1
mods/siege_hammer/description.txt
Normal file
@ -0,0 +1 @@
|
||||
Siege hammer breaks down only protected ctf nodes.
|
196
mods/siege_hammer/init.lua
Normal file
196
mods/siege_hammer/init.lua
Normal file
@ -0,0 +1,196 @@
|
||||
material_Strengths = {}
|
||||
|
||||
minetest.register_chatcommand("node_strength", {
|
||||
params = "<node_name>",
|
||||
description = "Read HP of node. Example /node_strength default:dirt. To see all nodes strength /node_strength all.",
|
||||
func = function(name, param)
|
||||
if material_Strengths[param] then
|
||||
return true, "HP: " .. tostring(material_Strengths[param])
|
||||
else if string.lower(param) == "all" then
|
||||
local list = ""
|
||||
for i,j in pairs(material_Strengths) do
|
||||
list = list .. i .. " = " .. tostring(j) .. "\n"
|
||||
end
|
||||
return true,list
|
||||
else
|
||||
return false,param .. " does not exist."
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
local function div(base,value)
|
||||
if value then
|
||||
return base / value
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function mul(base,value)
|
||||
if value then
|
||||
return base * value
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function cac_Material_Strengths()
|
||||
local list = minetest.registered_nodes
|
||||
local node = nil
|
||||
for i in pairs(list) do
|
||||
node = list[i]
|
||||
local strength_Pool = 0
|
||||
local cracky = div(47,node.groups.cracky)
|
||||
local stone = div(68,node.groups.stone)
|
||||
local level = mul(150,node.groups.level)
|
||||
local crumbly = div(25,node.groups.crumbly)
|
||||
local oddly_breakable_by_hand = mul(5,node.groups.oddly_breakable_by_hand)
|
||||
local dig_immediate = mul(2,node.groups.dig_immediate)
|
||||
local choppy = div(35,node.groups.choppy)
|
||||
local snappy = div(15,node.groups.snappy)
|
||||
strength_Pool = strength_Pool + cracky
|
||||
strength_Pool = strength_Pool + stone
|
||||
strength_Pool = strength_Pool + level
|
||||
strength_Pool = strength_Pool + crumbly
|
||||
strength_Pool = strength_Pool - oddly_breakable_by_hand
|
||||
strength_Pool = strength_Pool - dig_immediate
|
||||
strength_Pool = strength_Pool + choppy
|
||||
strength_Pool = strength_Pool + snappy
|
||||
if strength_Pool < 0 then
|
||||
strength_Pool = 1
|
||||
end
|
||||
-- Round value.
|
||||
strength_Pool = math.floor(strength_Pool+0.5)
|
||||
material_Strengths[node.name] = strength_Pool
|
||||
end
|
||||
end
|
||||
|
||||
-- siege hammer
|
||||
minetest.register_tool("siege_hammer:siege_hammer", {
|
||||
description = "Siege Hammer",
|
||||
image = "siege_hammer.png",
|
||||
inventory_image = "siege_hammer.png",
|
||||
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 5,
|
||||
max_drop_level = 0,
|
||||
range = 1,
|
||||
groupcaps={
|
||||
cracky = {times={[1]=8.0, [2]=4.0, [3]=2.0}, uses=30, maxlevel=3},
|
||||
},
|
||||
damage_groups = {fleshy=5},
|
||||
},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local pos = nil
|
||||
local node = nil
|
||||
local realNode = nil
|
||||
if pointed_thing.under then
|
||||
pos = pointed_thing.under
|
||||
end
|
||||
if pointed_thing.above then
|
||||
pos = pointed_thing.under
|
||||
end
|
||||
if pos then
|
||||
node = minetest.get_node_or_nil(pos)
|
||||
realNode = minetest.registered_nodes[node.name]
|
||||
local name = user:get_player_name()
|
||||
local team = ctf.get_territory_owner(pos)
|
||||
local p_team = ctf.player(name).team
|
||||
if not team then
|
||||
minetest.chat_send_player(name, "This only works in protected areas.")
|
||||
return itemstack
|
||||
end
|
||||
if p_team == team then
|
||||
minetest.chat_send_player(name, "You can not use a siege hammer on your own team!")
|
||||
return itemstack
|
||||
end
|
||||
if not p_team then
|
||||
minetest.chat_send_player(name, "You need to be in a team in order to use this siege weapon.")
|
||||
return itemstack
|
||||
end
|
||||
if p_team ~= team then
|
||||
local state = ctf.diplo.get(p_team,team)
|
||||
if state ~= "war" then
|
||||
minetest.chat_send_player(name, "You need to be at war in order to use this siege weapon.")
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
local online = false
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
local player = playerslist[i]
|
||||
local player_name = player:get_player_name()
|
||||
local player_team = ctf.player(name).team
|
||||
if player_team then
|
||||
if player_team == team then
|
||||
online = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not online then
|
||||
minetest.chat_send_player(name, "There needs to be at least one member of this team online in order to siege them.")
|
||||
return itemstack
|
||||
end
|
||||
itemstack:add_wear(100)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local health = 1
|
||||
if meta then
|
||||
local tmp = meta:to_table()
|
||||
if tmp then
|
||||
if not tmp.fields.siege_health then
|
||||
tmp.fields.siege_health = material_Strengths[realNode.name]
|
||||
end
|
||||
-- Damage code.
|
||||
-- Remove 0.1 hit point.
|
||||
tmp.fields.siege_health = tmp.fields.siege_health - 0.1
|
||||
health = tmp.fields.siege_health
|
||||
meta:from_table(tmp)
|
||||
end
|
||||
end
|
||||
if health <= 0 then
|
||||
local drops = minetest.get_node_drops(minetest.get_node(pos).name, "siege_hammer:siege_hammer")
|
||||
minetest.remove_node(pos)
|
||||
nodeupdate(pos)
|
||||
local dropitem = ItemStack(drops[1])
|
||||
minetest.add_item(pos, dropitem)
|
||||
local msg = "Siege alert! Protected node at (" .. tostring(pos.x) .. "," .. tostring(pos.y) .. "," .. tostring(pos.z) .. ")" .. " Was removed by " .. name .. "."
|
||||
ctf.post(team, {
|
||||
msg = msg,
|
||||
icon="flag_red" })
|
||||
for i in pairs(playerslist) do
|
||||
local player = playerslist[i]
|
||||
local player_name = player:get_player_name()
|
||||
local player_team = ctf.player(player_name).team
|
||||
if player_team then
|
||||
if player_team == team then
|
||||
minetest.chat_send_player(player_name, msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
if realNode then
|
||||
if realNode.sounds.dug then
|
||||
minetest.sound_play("default_tool_breaks", {pos = pos, gain = 2.1,max_hear_distance = 127})
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
if realNode then
|
||||
if realNode.sounds.dug then
|
||||
minetest.sound_play(realNode.sounds.dug.name, {pos = pos, gain = 1.6,max_hear_distance = 95})
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
sound = {breaks = "default_tool_breaks"}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "siege_hammer:siege_hammer",
|
||||
recipe = {
|
||||
{'default:obsidian','default:obsidian','default:obsidian'},
|
||||
{'default:obsidian','default:obsidian','default:obsidian'},
|
||||
{'', 'default:stick', '' } }
|
||||
})
|
||||
|
||||
cac_Material_Strengths()
|
1
mods/siege_hammer/mod.conf
Normal file
1
mods/siege_hammer/mod.conf
Normal file
@ -0,0 +1 @@
|
||||
name = siege_hammer
|
BIN
mods/siege_hammer/sounds/default_tool_breaks.1.ogg
Normal file
BIN
mods/siege_hammer/sounds/default_tool_breaks.1.ogg
Normal file
Binary file not shown.
BIN
mods/siege_hammer/sounds/default_tool_breaks.2.ogg
Normal file
BIN
mods/siege_hammer/sounds/default_tool_breaks.2.ogg
Normal file
Binary file not shown.
BIN
mods/siege_hammer/sounds/default_tool_breaks.3.ogg
Normal file
BIN
mods/siege_hammer/sounds/default_tool_breaks.3.ogg
Normal file
Binary file not shown.
BIN
mods/siege_hammer/textures/siege_hammer.png
Normal file
BIN
mods/siege_hammer/textures/siege_hammer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 294 B |
Loading…
x
Reference in New Issue
Block a user