Compare commits
5 Commits
c36fdfa8f0
...
e76fe9c72d
Author | SHA1 | Date |
---|---|---|
rnd1 | e76fe9c72d | |
rnd1 | 7bb06fd8c7 | |
rnd1 | 45a7cef90a | |
AndrejIT | 61473f3dc6 | |
AndrejIT | 468d4503da |
119
init.lua
119
init.lua
|
@ -1,6 +1,8 @@
|
|||
-- Minetest mod "City block"
|
||||
-- City block disables use of water/lava buckets and also sends aggressive players to jail
|
||||
|
||||
-- modified by rnd: only send player in jail if he kills by punching, no more innocent players in jail
|
||||
|
||||
--This library is free software; you can redistribute it and/or
|
||||
--modify it under the terms of the GNU Lesser General Public
|
||||
--License as published by the Free Software Foundation; either
|
||||
|
@ -47,6 +49,18 @@ function city_block:in_city(pos)
|
|||
return false
|
||||
end
|
||||
|
||||
function city_block:city_boundaries(pos)
|
||||
for i, EachBlock in ipairs(self.blocks) do
|
||||
if (pos.x == (EachBlock.pos.x - 21) or pos.x == (EachBlock.pos.x + 21)) and pos.z > (EachBlock.pos.z - 22) and pos.z < (EachBlock.pos.z + 22 ) then
|
||||
return true
|
||||
end
|
||||
if (pos.z == (EachBlock.pos.z - 21) or pos.z == (EachBlock.pos.z + 21)) and pos.x > (EachBlock.pos.x - 22) and pos.x < (EachBlock.pos.x + 22 ) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
city_block:load()
|
||||
|
||||
minetest.register_node("city_block:cityblock", {
|
||||
|
@ -56,7 +70,7 @@ minetest.register_node("city_block:cityblock", {
|
|||
groups = {cracky=1,level=3},
|
||||
is_ground_content = false,
|
||||
light_source = LIGHT_MAX,
|
||||
walkable = false,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
if placer and placer:is_player() then
|
||||
table.insert(city_block.blocks, {pos=vector.round(pos), owner=placer:get_player_name()} )
|
||||
|
@ -104,28 +118,91 @@ minetest.registered_craftitems["bucket:bucket_lava"].on_place=function(itemstack
|
|||
end
|
||||
end
|
||||
|
||||
minetest.register_on_dieplayer(
|
||||
function(player)
|
||||
pos=player:getpos()
|
||||
if city_block:in_city(pos) and not(pos.x>-25 and pos.x<25 and pos.y>-5 and pos.y<25 and pos.z>-25 and pos.z<25) then
|
||||
for _,suspect in pairs(minetest.get_objects_inside_radius(pos, 3.8)) do
|
||||
if suspect:is_player() and suspect:get_player_name()~=player:get_player_name() then
|
||||
suspect_name=suspect:get_player_name()
|
||||
if city_block.suspects[suspect_name] then
|
||||
if city_block.suspects[suspect_name]>3 then
|
||||
suspect:setpos( {x=0, y=-2, z=0} )
|
||||
minetest.chat_send_all("Player "..suspect_name.." sent to jail as suspect for killing in town")
|
||||
minetest.log("action", "Player "..suspect_name.." warned for killing in town")
|
||||
city_block.suspects[suspect_name]=1
|
||||
else
|
||||
city_block.suspects[suspect_name]=city_block.suspects[suspect_name]+1
|
||||
|
||||
-- rnd: now only players who kill others by punching go to jail, no more fail jailings
|
||||
|
||||
city_block.attacker = {};city_block.attack = {};
|
||||
minetest.register_on_punchplayer(
|
||||
function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
|
||||
local pname = player:get_player_name(); local name = hitter:get_player_name();if not pname or not name then return end
|
||||
if name=="" or pname=="" then return end -- no mob killers/victims
|
||||
local t = minetest.get_gametime() or 0;
|
||||
city_block.attacker[pname] = name;city_block.attack[pname]=t;
|
||||
local hp = player:get_hp();
|
||||
|
||||
if hp-damage<=0 then -- player will die
|
||||
|
||||
local pos = player:getpos()
|
||||
|
||||
if city_block:in_city(pos) then
|
||||
local t0 = city_block.attack[name] or t;t0=t-t0;
|
||||
if not city_block.attacker[name] then city_block.attacker[name] = "" end
|
||||
--minetest.chat_send_all(" killers attacker ".. city_block.attacker[name] .. " attacked before " .. t0)
|
||||
if city_block.attacker[name]==pname and t0<10 then -- justified killing 10 seconds after provocation
|
||||
return
|
||||
else -- go to jail spawn killer, drop items for punishment
|
||||
local hitter_inv = hitter:get_inventory();pos.y = pos.y+1
|
||||
if hittern_inv then
|
||||
-- drop items instead of delete
|
||||
for i=1,hitter_inv:get_size("main") do
|
||||
minetest.add_item(pos, hitter_inv:get_stack("main", i))
|
||||
end
|
||||
for i=1,hitter_inv:get_size("craft") do
|
||||
minetest.add_item(pos, hitter_inv:get_stack("craft", i))
|
||||
end
|
||||
-- empty lists main and craft
|
||||
hitter_inv:set_list("main", {})
|
||||
hitter_inv:set_list("craft", {})
|
||||
end
|
||||
else
|
||||
city_block.suspects[suspect_name]=1
|
||||
hitter:setpos( {x=0, y=-2, z=0} )
|
||||
minetest.chat_send_all("Player "..name.." sent to jail for killing " .. pname .." without reason in town")
|
||||
minetest.log("action", "Player "..name.." warned for killing in town")
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
|
||||
-- minetest.register_on_dieplayer(
|
||||
-- function(player)
|
||||
-- pos=player:getpos()
|
||||
-- if city_block:in_city(pos) and not(pos.x>-25 and pos.x<25 and pos.y>-5 and pos.y<25 and pos.z>-25 and pos.z<25) then
|
||||
-- for _,suspect in pairs(minetest.get_objects_inside_radius(pos, 3.8)) do
|
||||
-- if suspect:is_player() and suspect:get_player_name()~=player:get_player_name() then
|
||||
-- suspect_name=suspect:get_player_name()
|
||||
-- if city_block.suspects[suspect_name] then
|
||||
-- if city_block.suspects[suspect_name]>3 then
|
||||
-- suspect:setpos( {x=0, y=-2, z=0} )
|
||||
-- minetest.chat_send_all("Player "..suspect_name.." sent to jail as suspect for killing in town")
|
||||
-- minetest.log("action", "Player "..suspect_name.." warned for killing in town")
|
||||
-- city_block.suspects[suspect_name]=1
|
||||
-- else
|
||||
-- city_block.suspects[suspect_name]=city_block.suspects[suspect_name]+1
|
||||
-- end
|
||||
-- else
|
||||
-- city_block.suspects[suspect_name]=1
|
||||
-- end
|
||||
-- return false
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- )
|
||||
|
||||
--do not let lava flow across boundary of city block
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:lava_flowing"},
|
||||
interval = 10,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if pos.y>14 and city_block:city_boundaries(pos) then
|
||||
minetest.set_node(pos, {name="default:stone"})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue