mirror of
https://bitbucket.org/kingarthursteam/cannons.git
synced 2025-01-07 11:57:28 +01:00
add support for sokomines locks mod
now its possible to lock your cannons and share it with other players you want.
This commit is contained in:
parent
8330738a70
commit
4e998283b5
@ -66,7 +66,7 @@ local fire={
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1])
|
||||
cannons.nodehitparticles(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",
|
||||
@ -112,7 +112,7 @@ local ball_wood={
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1])
|
||||
cannons.nodehitparticles(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("cannons_hit",
|
||||
@ -165,7 +165,7 @@ local ball_stone={
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1])
|
||||
cannons.nodehitparticles(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("cannons_hit",
|
||||
@ -218,7 +218,7 @@ local ball_steel={
|
||||
self.object:remove()
|
||||
end,
|
||||
on_node_hit = function(self,pos,node)
|
||||
cannons.nodehitparticles(pos,minetest.registered_nodes[node.name].tiles[1])
|
||||
cannons.nodehitparticles(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("cannons_hit",
|
||||
|
@ -1,3 +1,4 @@
|
||||
default
|
||||
bucket
|
||||
mesecons?
|
||||
locks?
|
@ -20,6 +20,10 @@ function cannons.inventory_modified(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack("muni", 1)
|
||||
local muni = stack:to_table()
|
||||
local addition = ""
|
||||
if meta:get_string("owner") ~="" then
|
||||
addition = " (owned by "..meta:get_string("owner")..")"
|
||||
end
|
||||
if muni == nil then
|
||||
muni = false
|
||||
else
|
||||
@ -28,21 +32,26 @@ function cannons.inventory_modified(pos)
|
||||
|
||||
local gunpowder = inv:contains_item("gunpowder","cannons:gunpowder 1")
|
||||
if not muni and not gunpowder then
|
||||
meta:set_string("infotext","Cannon has no muni and no gunpowder")
|
||||
meta:set_string("infotext","Cannon has no muni and no gunpowder"..addition)
|
||||
|
||||
elseif not muni then
|
||||
meta:set_string("infotext","Cannon has no muni")
|
||||
meta:set_string("infotext","Cannon has no muni"..addition)
|
||||
|
||||
elseif not gunpowder then
|
||||
meta:set_string("infotext","Cannon has no gunpowder")
|
||||
meta:set_string("infotext","Cannon has no gunpowder"..addition)
|
||||
|
||||
else
|
||||
meta:set_string("infotext","Cannon is ready")
|
||||
meta:set_string("infotext","Cannon is ready"..addition)
|
||||
end
|
||||
end
|
||||
|
||||
cannons.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
--pr(meta:get_string("owner"))
|
||||
if(meta:get_string("owner") ~="" and not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
local inv = meta:get_inventory()
|
||||
stack = stack:to_table()
|
||||
if listname == "gunpowder" and stack.name == "cannons:gunpowder" then
|
||||
@ -54,7 +63,12 @@ cannons.allow_metadata_inventory_put = function(pos, listname, index, stack, pla
|
||||
|
||||
end
|
||||
cannons.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
pr(meta:get_string("owner"))
|
||||
if(meta:get_string("owner") ~="" and not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
stack = stack:to_table()
|
||||
@ -69,8 +83,8 @@ cannons.allow_metadata_inventory_move = function(pos, from_list, from_index, to_
|
||||
end
|
||||
cannons.formspec =
|
||||
"size[8,9]"..
|
||||
"list[current_name;muni;2,1;1,1;] label[2,0.5;Muni:]"..
|
||||
"list[current_name;gunpowder;2,3;1,1;] label[2,2.5;Gunpowder:]"..
|
||||
"list[current_name;muni;0,1;1,1;] label[0,0.5;Muni:]"..
|
||||
"list[current_name;gunpowder;0,3;1,1;] label[0,2.5;Gunpowder:]"..
|
||||
"list[current_player;main;0,5;8,4;]"
|
||||
cannons.disabled_formspec =
|
||||
"size[8,9]"..
|
||||
@ -92,6 +106,24 @@ cannons.on_construct = function(pos)
|
||||
meta:set_string("infotext", "Cannon is out of order")
|
||||
end
|
||||
end
|
||||
cannons.on_construct_locks = function(pos)
|
||||
local node = minetest.get_node({x = pos.x ,y = pos.y-1, z = pos.z})
|
||||
--pr(minetest.registered_nodes[node.name])
|
||||
if minetest.registered_nodes[node.name].groups.cannonstand then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", cannons.formspec..
|
||||
"field[2,1.3;6,0.7;locks_sent_lock_command;Locked Cannon. Type /help for help:;]"..
|
||||
"button[6,2;1.7,0.7;locks_sent_input;Proceed]")
|
||||
meta:set_string("infotext", "Cannon has no muni and no gunpowder")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("gunpowder", 1)
|
||||
inv:set_size("muni", 1)
|
||||
else
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", cannons.disabled_formspec)
|
||||
meta:set_string("infotext", "Cannon is out of order")
|
||||
end
|
||||
end
|
||||
cannons.nodebox = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@ -123,7 +155,10 @@ cannons.stand_nodebox = {
|
||||
function cannons.meseconsfire(pos,node)
|
||||
cannons.fire(pos,node)
|
||||
end
|
||||
function cannons.nodehitparticles(pos,texture)
|
||||
function cannons.nodehitparticles(pos,node)
|
||||
pr(type(minetest.registered_nodes[node.name].tiles))
|
||||
if type(minetest.registered_nodes[node.name]) == "table" and type(minetest.registered_nodes[node.name].tiles) == "table" and type(minetest.registered_nodes[node.name].tiles[1])== "string" then
|
||||
local texture = minetest.registered_nodes[node.name].tiles[1]
|
||||
minetest.add_particlespawner(
|
||||
30, --amount
|
||||
0.5, --time
|
||||
@ -140,6 +175,7 @@ function cannons.nodehitparticles(pos,texture)
|
||||
false, --collisiondetection
|
||||
texture --texture
|
||||
)
|
||||
end
|
||||
end
|
||||
function cannons.fire(pos,node,puncher)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
16
init.lua
16
init.lua
@ -2,15 +2,19 @@
|
||||
|
||||
|
||||
cannons = {}
|
||||
local MODPATH = minetest.get_modpath(minetest.get_current_modname())
|
||||
cannons.MODPATH = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
|
||||
dofile(MODPATH .."/settings.txt")
|
||||
dofile(MODPATH .."/print_r.lua")
|
||||
dofile(MODPATH .."/functions.lua")
|
||||
dofile(MODPATH .."/items.lua")
|
||||
dofile(MODPATH .."/cannonballs.lua")
|
||||
dofile(cannons.MODPATH .."/settings.txt")
|
||||
dofile(cannons.MODPATH .."/print_r.lua")
|
||||
dofile(cannons.MODPATH .."/functions.lua")
|
||||
dofile(cannons.MODPATH .."/items.lua")
|
||||
dofile(cannons.MODPATH .."/cannonballs.lua")
|
||||
|
||||
if minetest.get_modpath("locks") ~=nil then
|
||||
minetest.log("locks mod enabled. execute locks.lua")
|
||||
dofile(cannons.MODPATH .."/locks.lua")--if the locks mod is installed execute this file
|
||||
end
|
||||
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded from "..minetest.get_modpath(minetest.get_current_modname()))
|
||||
|
||||
|
65
locks.lua
Normal file
65
locks.lua
Normal file
@ -0,0 +1,65 @@
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
--+ shared locked cannon +
|
||||
--++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
minetest.register_node("cannons:shared_locked_cannon", {
|
||||
description = "locked shareable Cannon",
|
||||
stack_max = 1,
|
||||
tiles = {"cannon_cannon_top.png^locks_lock16.png","cannon_cannon_top.png","cannon_cannon_side.png","cannon_cannon_side.png","cannon_cannon_top.png^cannons_rim.png","cannon_cannon_side.png"},
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
node_box = cannons.nodebox,
|
||||
on_place = cannons.on_place,
|
||||
selection_box = cannons.nodebox,
|
||||
on_punch = cannons.punched,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
locks:lock_handle_input( pos, formname, fields, sender );
|
||||
end,
|
||||
after_place_node = function(pos, placer)
|
||||
locks:lock_set_owner( pos, placer, "empty locked shareable cannon" );
|
||||
end,
|
||||
--no mesecons support for this type of cannon!
|
||||
--mesecons = {effector = {
|
||||
-- rules = cannons.rules,
|
||||
-- action_on = cannons.meseconsfire,
|
||||
-- }
|
||||
--},
|
||||
on_construct = cannons.on_construct_locks,
|
||||
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 locks:lock_allow_dig( pos, player )
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_put = cannons.allow_metadata_inventory_put,
|
||||
|
||||
allow_metadata_inventory_move = cannons.allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
if( not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
|
||||
on_metadata_inventory_put = cannons.inventory_modified,
|
||||
on_metadata_inventory_take = cannons.inventory_modified,
|
||||
on_metadata_inventory_move = cannons.inventory_modified,
|
||||
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'cannons:shared_locked_cannon',
|
||||
recipe = {
|
||||
{'cannons:cannon', 'locks:lock',},
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue
Block a user