mirror of
https://bitbucket.org/kingarthursteam/cannons.git
synced 2024-08-18 19:34:05 +02:00
pushed to bitbucket
This commit is contained in:
commit
5c7c677073
130
canonballs.lua
Normal file
130
canonballs.lua
Normal file
@ -0,0 +1,130 @@
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
--+ Stoneball +
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
local stone={
|
||||
physical = false,
|
||||
timer=0,
|
||||
textures = {"canons_bullet.png"},
|
||||
lastpos={},
|
||||
damage=20,
|
||||
range=2,
|
||||
gravity=10,
|
||||
velocity=40,
|
||||
name="canons:stone_bullet",
|
||||
collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25},
|
||||
on_player_hit = function(self,pos,player)
|
||||
local playername = player:get_player_name()
|
||||
player:punch(self.object, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=self.damage},
|
||||
}, nil)
|
||||
self.object:remove()
|
||||
minetest.chat_send_all(playername .." tried to catch a canonball")
|
||||
end,
|
||||
on_mob_hit = function(self,pos,mob)
|
||||
mob:punch(self.object, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=self.damage},
|
||||
}, nil)
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
if node.name == "default:dirt_with_grass" then
|
||||
minetest.env:set_node({x=pos.x, y=pos.y, z=pos.z},{name="default:dirt"})
|
||||
minetest.sound_play("canons_hit",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
self.object:remove()
|
||||
elseif node.name == "default:water_source" then
|
||||
minetest.sound_play("canons_splash",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
self.object:remove()
|
||||
else
|
||||
minetest.sound_play("canons_hit",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
|
||||
}
|
||||
canons.register_muni("default:stone",stone)
|
||||
|
||||
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
--+ Meseball +
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
local mese={
|
||||
physical = false,
|
||||
timer=0,
|
||||
textures = {"default_mese_block.png","default_mese_block.png","default_mese_block.png","default_mese_block.png","default_mese_block.png","default_mese_block.png"},
|
||||
lastpos={},
|
||||
damage=15,
|
||||
visual = "cube",
|
||||
visual_size = {x=0.5, y=0.5},
|
||||
range=1,
|
||||
gravity=10,
|
||||
velocity=30,
|
||||
name="canons:mese",
|
||||
collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25},
|
||||
on_player_hit = function(self,pos,player)
|
||||
local playername = player:get_player_name()
|
||||
player:punch(self.object, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=self.damage},
|
||||
}, nil)
|
||||
self.object:remove()
|
||||
end,
|
||||
on_mob_hit = function(self,pos,mob)
|
||||
mob:punch(self.object, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=self.damage},
|
||||
}, nil)
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
canons.destroy({x=pos.x, y=pos.y, z=pos.z},self.range)
|
||||
minetest.sound_play("canons_shot",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
self.object:remove()
|
||||
end,
|
||||
|
||||
}
|
||||
if enable_explosion then
|
||||
canons.register_muni("default:mese",mese)
|
||||
end
|
||||
|
||||
local tree={
|
||||
physical = false,
|
||||
timer=0,
|
||||
textures = {"default_tree.png","default_tree.png","default_tree.png","default_tree.png","default_tree.png","default_tree.png"},
|
||||
lastpos={},
|
||||
damage=10,
|
||||
visual = "cube",
|
||||
visual_size = {x=0.5, y=0.5},
|
||||
range=2,
|
||||
gravity=8,
|
||||
velocity=35,
|
||||
name="canons:tree",
|
||||
collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25},
|
||||
on_player_hit = function(self,pos,player)
|
||||
local playername = player:get_player_name()
|
||||
player:punch(self.object, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=self.damage},
|
||||
}, nil)
|
||||
self.object:remove()
|
||||
end,
|
||||
on_mob_hit = function(self,pos,mob)
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
pos = self.lastpos
|
||||
minetest.env:set_node({x=pos.x, y=pos.y, z=pos.z},{name="fire:basic_flame"})
|
||||
minetest.sound_play("default_break_glass",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
self.object:remove()
|
||||
end,
|
||||
|
||||
}
|
||||
if enable_fire then
|
||||
canons.register_muni("default:tree",tree)
|
||||
end
|
2
depends.txt
Normal file
2
depends.txt
Normal file
@ -0,0 +1,2 @@
|
||||
default
|
||||
bucket
|
166
functions.lua
Normal file
166
functions.lua
Normal file
@ -0,0 +1,166 @@
|
||||
|
||||
function canons.destroy(pos,range)
|
||||
for x=-range,range do
|
||||
for y=-range,range do
|
||||
for z=-range,range do
|
||||
if x*x+y*y+z*z <= range * range + range then
|
||||
local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
|
||||
local n = minetest.env:get_node(np)
|
||||
if n.name ~= "air" then
|
||||
minetest.env:remove_node(np)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function canons.inventory_modified(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack("muni", 1)
|
||||
local muni = stack:to_table()
|
||||
if muni == nil then
|
||||
muni = false
|
||||
else
|
||||
muni = canons.is_muni(muni.name)
|
||||
end
|
||||
|
||||
local gunpowder = inv:contains_item("gunpowder","canons:gunpowder 1")
|
||||
if not muni and not gunpowder then
|
||||
meta:set_string("infotext","Canon has no muni and no gunpowder")
|
||||
|
||||
elseif not muni then
|
||||
meta:set_string("infotext","Canon has no muni")
|
||||
|
||||
elseif not gunpowder then
|
||||
meta:set_string("infotext","Canon has no gunpowder")
|
||||
|
||||
else
|
||||
meta:set_string("infotext","Canon is ready")
|
||||
end
|
||||
end
|
||||
|
||||
function canons.fire(pos,node,puncher)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack("muni", 1)
|
||||
local muni = stack:to_table()
|
||||
if inv:contains_item("gunpowder","canons:gunpowder 1")
|
||||
and muni ~= nil
|
||||
and canons.is_muni(muni.name)
|
||||
and inv:contains_item("muni",muni.name.." 1")
|
||||
|
||||
then
|
||||
minetest.sound_play("canons_shot",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
|
||||
|
||||
inv:remove_item("muni", muni.name.." 1")
|
||||
inv:remove_item("gunpowder", "canons:gunpowder 1")
|
||||
canons.inventory_modified(pos)
|
||||
local settings = canons.get_settings(muni.name)
|
||||
local playerpos=puncher:getpos()
|
||||
local obj=minetest.env:add_entity(pos, canons.get_entity(muni.name))
|
||||
local dir=puncher:get_look_dir()
|
||||
obj:setvelocity({x=dir.x*settings.velocity, y=-1, z=dir.z*settings.velocity})
|
||||
obj:setacceleration({x=dir.x*-3, y=-settings.gravity, z=dir.z*-3})
|
||||
end
|
||||
end
|
||||
|
||||
function canons.punched(pos, node, puncher)
|
||||
if not puncher or not node then
|
||||
return
|
||||
end
|
||||
local wield = puncher:get_wielded_item()
|
||||
if not wield then
|
||||
return
|
||||
end
|
||||
wield = wield:get_name()
|
||||
if wield and wield == 'default:torch' then
|
||||
canons.fire(pos,node,puncher)
|
||||
end
|
||||
end
|
||||
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
--+ canons.register_muni +
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
|
||||
canons.registered_muni = {}
|
||||
|
||||
function canons.register_muni(node,entity)
|
||||
canons.registered_muni[node] = {}
|
||||
canons.registered_muni[node].entity = entity
|
||||
canons.registered_muni[node].entity.on_step = function(self, dtime)
|
||||
self.timer=self.timer+dtime
|
||||
--pr(self.timer,"Timer")
|
||||
if self.timer >= 0.3 then --easiesst less laggiest way to find out that it left his start position
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
if node.name == "air" then
|
||||
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, self.range)
|
||||
for k, obj in pairs(objs) do
|
||||
if obj:get_luaentity() ~= nil then
|
||||
if obj:get_luaentity().name ~= self.name and obj:get_luaentity().name ~= "__builtin:item" then --something other found
|
||||
local mob = obj
|
||||
self.on_mob_hit(self,pos,mob)
|
||||
end
|
||||
elseif obj:is_player() then --player found
|
||||
local player = obj
|
||||
self.on_player_hit(self,pos,player)
|
||||
end
|
||||
end
|
||||
elseif node.name ~=air then
|
||||
self.on_node_hit(self,pos,node)
|
||||
end
|
||||
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
||||
end
|
||||
end
|
||||
canons.registered_muni[node].obj = entity.name
|
||||
minetest.register_entity(entity.name, canons.registered_muni[node].entity)
|
||||
end
|
||||
|
||||
function canons.is_muni(node)
|
||||
return canons.registered_muni[node] ~= nil
|
||||
end
|
||||
function canons.get_entity(node)
|
||||
return canons.registered_muni[node].obj
|
||||
end
|
||||
function canons.get_settings(node)
|
||||
return canons.registered_muni[node].entity
|
||||
end
|
||||
|
||||
local apple={
|
||||
physical = false,
|
||||
timer=0,
|
||||
textures = {"default_apple.png"},
|
||||
lastpos={},
|
||||
damage=-10,
|
||||
range=2,
|
||||
gravity=10,
|
||||
velocity=30,
|
||||
name="canons:apple",
|
||||
collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25},
|
||||
on_player_hit = function(self,pos,player)
|
||||
local playername = player:get_player_name()
|
||||
player:punch(self.object, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=self.damage},
|
||||
}, nil)
|
||||
self.object:remove()
|
||||
minetest.chat_send_player(playername ," this is not an easter egg!")
|
||||
end,
|
||||
on_mob_hit = function(self,pos,mob)
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
pos = self.lastpos
|
||||
minetest.env:set_node({x=pos.x, y=pos.y, z=pos.z},{name="default:apple"})
|
||||
minetest.sound_play("canons_hit",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
self.object:remove()
|
||||
end,
|
||||
|
||||
}
|
||||
canons.register_muni("default:apple",apple)
|
13
init.lua
Normal file
13
init.lua
Normal file
@ -0,0 +1,13 @@
|
||||
enable_fire = true
|
||||
enable_explosion = true
|
||||
|
||||
|
||||
canons = {}
|
||||
local MODPATH = minetest.get_modpath(minetest.get_current_modname())
|
||||
dofile(MODPATH .."/print_r.lua")
|
||||
dofile(MODPATH .."/functions.lua")
|
||||
dofile(MODPATH .."/items.lua")
|
||||
dofile(MODPATH .."/canonballs.lua")
|
||||
|
||||
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded from "..minetest.get_modpath(minetest.get_current_modname()))
|
93
items.lua
Normal file
93
items.lua
Normal file
@ -0,0 +1,93 @@
|
||||
minetest.register_craftitem("canons:gunpowder", {
|
||||
groups = {gunpowder=1},
|
||||
Description = "Gunpowder",
|
||||
inventory_image = "canons_gunpowder.png"
|
||||
})
|
||||
minetest.register_craftitem("canons:sulfur", {
|
||||
Description = "Sulfur",
|
||||
inventory_image = "canons_sulfur.png"
|
||||
})
|
||||
minetest.register_craftitem("canons:salt", {
|
||||
Description = "Salt",
|
||||
inventory_image = "canons_salt.png"
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = 'canons:salt',
|
||||
recipe = 'bucket:bucket_water',
|
||||
})
|
||||
|
||||
minetest.register_craftitem("canons:stone_bullet", {
|
||||
Description = "Gunpowder",
|
||||
inventory_image = "canons_bullet.png"
|
||||
})
|
||||
|
||||
canons.formspec =
|
||||
"size[8,9]"..
|
||||
"list[current_name;gunpowder;2,3;1,1;]"..
|
||||
"list[current_name;muni;2,1;1,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]"
|
||||
|
||||
minetest.register_node("canons:canon", {
|
||||
description = "Canon",
|
||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||
"default_furnace_side.png","cannon_back.png", "cannon_front.png"},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2,canon=1},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_punch = canons.punched,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", canons.formspec)
|
||||
meta:set_string("infotext", "Canon has no muni and no gunpowder")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("gunpowder", 1)
|
||||
inv:set_size("muni", 1)
|
||||
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("gunpowder") then
|
||||
return false
|
||||
elseif not inv:is_empty("muni") then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
stack = stack:to_table()
|
||||
if listname == "gunpowder" and stack.name == "canons:gunpowder" then
|
||||
return stack.count
|
||||
elseif listname == "muni" and canons.is_muni(stack.name) then
|
||||
return stack.count
|
||||
else return 0
|
||||
end
|
||||
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
stack = stack:to_table()
|
||||
if to_list == "gunpowder" and stack.name == "canons:gunpowder" then
|
||||
return count
|
||||
|
||||
elseif to_list == "muni" and canons.is_muni(stack.name) then
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
|
||||
end,
|
||||
on_metadata_inventory_put = canons.inventory_modified,
|
||||
|
||||
on_metadata_inventory_take = canons.inventory_modified,
|
||||
|
||||
on_metadata_inventory_move = canons.inventory_modified,
|
||||
|
||||
})
|
7
license.txt
Normal file
7
license.txt
Normal file
@ -0,0 +1,7 @@
|
||||
canons_splash.1.ogg
|
||||
canons_splash.2.ogg
|
||||
canons_splash.3.ogg
|
||||
canons_splash.4.ogg
|
||||
|
||||
License: Public Domain
|
||||
source: http://www.mediacollege.com/downloads/sound-effects/water/
|
31
print_r.lua
Normal file
31
print_r.lua
Normal file
@ -0,0 +1,31 @@
|
||||
function print_r (t, name, indent)
|
||||
local tableList = {}
|
||||
function table_r (t, name, indent, full)
|
||||
local id = not full and name
|
||||
or type(name)~="number" and tostring(name) or '['..name..']'
|
||||
local tag = indent .. id .. ' = '
|
||||
local out = {} -- result
|
||||
if type(t) == "table" then
|
||||
if tableList[t] ~= nil then table.insert(out, tag .. '{} -- ' .. tableList[t] .. ' (self reference)')
|
||||
else
|
||||
tableList[t]= full and (full .. '.' .. id) or id
|
||||
if next(t) then -- Table not empty
|
||||
table.insert(out, tag .. '{')
|
||||
for key,value in pairs(t) do
|
||||
table.insert(out,table_r(value,key,indent .. '| ',tableList[t]))
|
||||
end
|
||||
table.insert(out,indent .. '}')
|
||||
else table.insert(out,tag .. '{}') end
|
||||
end
|
||||
else
|
||||
local val = type(t)~="number" and type(t)~="boolean" and '"'..tostring(t)..'"' or tostring(t)
|
||||
table.insert(out, tag .. val)
|
||||
end
|
||||
return table.concat(out, '\n')
|
||||
end
|
||||
return table_r(t,name or 'Value',indent or '')
|
||||
end
|
||||
|
||||
function pr (t, name)
|
||||
print(print_r(t,name))
|
||||
end
|
BIN
sounds/canons_hit.ogg
Normal file
BIN
sounds/canons_hit.ogg
Normal file
Binary file not shown.
BIN
sounds/canons_shot.ogg
Normal file
BIN
sounds/canons_shot.ogg
Normal file
Binary file not shown.
BIN
sounds/canons_splash.1.ogg
Normal file
BIN
sounds/canons_splash.1.ogg
Normal file
Binary file not shown.
BIN
sounds/canons_splash.2.ogg
Normal file
BIN
sounds/canons_splash.2.ogg
Normal file
Binary file not shown.
BIN
sounds/canons_splash.3.ogg
Normal file
BIN
sounds/canons_splash.3.ogg
Normal file
Binary file not shown.
BIN
sounds/canons_splash.4.ogg
Normal file
BIN
sounds/canons_splash.4.ogg
Normal file
Binary file not shown.
BIN
textures/cannon_back.png
Normal file
BIN
textures/cannon_back.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 176 KiB |
BIN
textures/cannon_front.png
Normal file
BIN
textures/cannon_front.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
BIN
textures/canons_bullet.png
Normal file
BIN
textures/canons_bullet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 420 B |
BIN
textures/canons_gunpowder.png
Normal file
BIN
textures/canons_gunpowder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 651 B |
Loading…
Reference in New Issue
Block a user