Compare commits
5 Commits
dc7ee11594
...
e28f6a839a
Author | SHA1 | Date |
---|---|---|
Juraj Vajda | e28f6a839a | |
Juraj Vajda | 7bef70b433 | |
Juraj Vajda | a8588d84d6 | |
Juraj Vajda | ecb66db860 | |
Juraj Vajda | 99b721d4a0 |
125
api.lua
125
api.lua
|
@ -40,6 +40,10 @@ function pvp_block:in_area(pos)
|
|||
local pos1 = block.pos1
|
||||
local pos2 = block.pos2
|
||||
|
||||
if not pos1 or not pos2 then
|
||||
return
|
||||
end
|
||||
|
||||
-- print("pos: ", dump(pos0))
|
||||
-- print("pos1: ", dump(pos1))
|
||||
-- print("pos2: ", dump(pos2))
|
||||
|
@ -128,6 +132,48 @@ pvp_block.mark_pos2 = function(pname)
|
|||
end
|
||||
end
|
||||
|
||||
function pvp_block.drop_inventory(pos, player)
|
||||
-- local pname = player:get_player_name()
|
||||
-- local name = hitter:get_player_name()
|
||||
local player_inv = player:get_inventory()
|
||||
pos.y = pos.y + 1
|
||||
|
||||
if player_inv then
|
||||
-- drop items
|
||||
local obj
|
||||
|
||||
for i = 1, player_inv:get_size("main") do
|
||||
obj = minetest.add_item(pos, player_inv:get_stack("main", i))
|
||||
if obj and obj:get_luaentity() then
|
||||
obj:setvelocity({
|
||||
x = math.random(-15, 15) / 9,
|
||||
y = 6,
|
||||
z = math.random(-15, 15) / 9,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, player_inv:get_size("craft") do
|
||||
obj = minetest.add_item(pos, player_inv:get_stack("craft", i))
|
||||
if obj and obj:get_luaentity() then
|
||||
obj:setvelocity({
|
||||
x = math.random(-15, 15) / 9,
|
||||
y = 6,
|
||||
z = math.random(-15, 15) / 9,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- empty lists main and craft
|
||||
player_inv:set_list("main", {})
|
||||
player_inv:set_list("craft", {})
|
||||
end
|
||||
-- hitter:set_pos( {x=50, y=15.5, z=117} )
|
||||
|
||||
-- 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
|
||||
|
||||
function pvp_block.register_on_punchplayer(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
if not player or not hitter then
|
||||
return
|
||||
|
@ -135,59 +181,50 @@ function pvp_block.register_on_punchplayer(player, hitter, time_from_last_punch,
|
|||
if not player:is_player() or not hitter:is_player() then
|
||||
return
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
local name = hitter:get_player_name()
|
||||
local hp = player:get_hp()
|
||||
|
||||
local pos = player:getpos()
|
||||
local hp = player:get_hp()
|
||||
local pos = player:get_pos()
|
||||
-- local nametag_attr = player:get_nametag_attributes()
|
||||
-- print("in_area: ", dump(pvp_block:in_area(pos)))
|
||||
-- print("hp: ", hp)
|
||||
-- print("damage: ", damage)
|
||||
-- print("new hp: ", hp - damage)
|
||||
-- if hp < 20 then
|
||||
-- player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}})
|
||||
-- else
|
||||
-- player:set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}})
|
||||
-- end
|
||||
if hp > 0 and (hp - damage) <= 0 then
|
||||
|
||||
if pvp_block:in_area(pos) then
|
||||
--spawn killer, drop items
|
||||
local player_inv = player:get_inventory()
|
||||
pos.y = pos.y + 1
|
||||
|
||||
if player_inv then
|
||||
-- drop items
|
||||
local obj
|
||||
|
||||
for i = 1, player_inv:get_size("main") do
|
||||
obj = minetest.add_item(pos, player_inv:get_stack("main", i))
|
||||
if obj and obj:get_luaentity() then
|
||||
obj:setvelocity({
|
||||
x = math.random(-15, 15) / 9,
|
||||
y = 6,
|
||||
z = math.random(-15, 15) / 9,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, player_inv:get_size("craft") do
|
||||
obj = minetest.add_item(pos, player_inv:get_stack("craft", i))
|
||||
if obj and obj:get_luaentity() then
|
||||
obj:setvelocity({
|
||||
x = math.random(-15, 15) / 9,
|
||||
y = 6,
|
||||
z = math.random(-15, 15) / 9,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- empty lists main and craft
|
||||
player_inv:set_list("main", {})
|
||||
player_inv:set_list("craft", {})
|
||||
end
|
||||
-- hitter:setpos( {x=50, y=15.5, z=117} )
|
||||
|
||||
-- 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")
|
||||
pvp_block.drop_inventory(pos, player)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_punchplayer(pvp_block.register_on_punchplayer)
|
||||
|
||||
-- die player - water, lava..
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
if not player:is_player() then
|
||||
return
|
||||
end
|
||||
|
||||
local hp = player:get_hp()
|
||||
local pos = player:get_pos()
|
||||
|
||||
if pvp_block:in_area(pos) then
|
||||
pvp_block.drop_inventory(pos, player)
|
||||
end
|
||||
end)
|
||||
|
||||
-- protection
|
||||
local old_is_protected = minetest.is_protected
|
||||
function minetest.is_protected(pos, name)
|
||||
if pvp_block:in_area(pos) then
|
||||
return true
|
||||
end
|
||||
return old_is_protected(pos, name)
|
||||
end
|
||||
|
|
|
@ -25,13 +25,16 @@ minetest.register_node("pvp_block:pvpblock", {
|
|||
if not pname or pname == "" then
|
||||
return
|
||||
end
|
||||
local privs = minetest.get_player_privs(pname)
|
||||
if not privs.privs then
|
||||
return
|
||||
end
|
||||
minetest.chat_send_player(pname, "--- Select positions by punching two nodes.")
|
||||
pvp_block.pos0[pname] = vector.round(pos)
|
||||
pvp_block.set_pos[pname] = "pos1"
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
print("on_rightclick")
|
||||
local pos0 = vector.round(pos)
|
||||
local pname = clicker:get_player_name()
|
||||
|
||||
|
|
Loading…
Reference in New Issue