diff options
author | James Stevenson <everamzah@gmail.com> | 2016-09-07 14:52:03 -0400 |
---|---|---|
committer | James Stevenson <everamzah@gmail.com> | 2016-09-07 14:52:03 -0400 |
commit | 8594d78bdd83ca0039f2526f0e73223d0ad7738a (patch) | |
tree | 731845b827f02d38fb8adf7bf8b47186dbc0e413 /init.lua |
Initial commit.
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..0a461f3 --- /dev/null +++ b/init.lua @@ -0,0 +1,59 @@ +-- pvp_areas +-- Copyright 2016 James Stevenson (everamzah) +-- LGPL v2.1+ + + +local pvp_areas = {} +local pvp_areas_store = AreaStore() +pvp_areas_store:from_file(minetest.get_worldpath() .. "/pvp_areas_store.dat") + +-- Register privilege and chat command. +minetest.register_privilege("pvp_areas_admin", "Can set and remove PvP areas.") + +minetest.register_chatcommand("pvp_areas", { + description = "Mark and set areas for PvP.", + params = "<pos1> <pos2> <set> <remove>", + privs = "pvp_areas_admin", + func = function(name, param) + local pos = vector.round(minetest.get_player_by_name(name):getpos()) + if param == "pos1" then + if not pvp_areas[name] then + pvp_areas[name] = {pos1 = pos} + else + pvp_areas[name].pos1 = pos + end + minetest.chat_send_player(name, "Position 1: " .. minetest.pos_to_string(pos)) + elseif param == "pos2" then + if not pvp_areas[name] then + pvp_areas[name] = {pos2 = pos} + else + pvp_areas[name].pos2 = pos + end + minetest.chat_send_player(name, "Position 2: " .. minetest.pos_to_string(pos)) + elseif param == "set" then + if not pvp_areas[name] or not pvp_areas[name].pos1 then + minetest.chat_send_player(name, "Position 1 missing, use \"/pvp_areas pos1\" to set.") + elseif not pvp_areas[name].pos2 then + minetest.chat_send_player(name, "Position 2 missing, use \"/pvp_areas pos2\" to set.") + else + minetest.chat_send_player(name, "Setting.") + pvp_areas_store:insert_area(pvp_areas[name].pos1, pvp_areas[name].pos2, "pvp_areas") + pvp_areas_store:to_file(minetest.get_worldpath() .. "/pvp_areas_store.dat") + end + elseif param == "remove" then + minetest.chat_send_player(name, "Removing.") + else + minetest.chat_send_player(name, "Invalid usage. Type \"/help pvp_areas\" for more information.") + end + end +}) + +-- Register punchplayer callback. +minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) + for k, v in pairs(pvp_areas_store:get_areas_for_pos(player:getpos())) do + if k then + return false + end + end + return true +end) |