add pvpbutton and action_timers, update .conf, readme, and [db]

master
elite 2017-07-14 22:26:18 -04:00
parent 524f3dfc3b
commit 59ea915fab
11 changed files with 268 additions and 6 deletions

View File

@ -1,3 +1,3 @@
## UGX Mortal Realms
## UGX Realms
This is the repo for the Minetest server UGX Mortal Realms.
This is the repo for the Minetest server UGX Realms.

View File

@ -22,7 +22,7 @@ secure.trusted_mods = mysql_auth,mysql_base,sql,irc,stacktraceplus,multiskin
secure.enable_security = false
mysql_auth.cfgfile = /home/minetestservers/.minetest/worlds/UGXmr/mysql.cfgfile
mysql_base.cfgfile = /home/minetestservers/.minetest/worlds/UGXmr/mysql.cfgfile
name_restrictions.pronounceability = # nil=disalbed, 0=everything blocked, .5=strict, 1=normal, 2=relaxed
name_restrictions.pronounceability = # nil=disabled, 0=everything blocked, .5=strict, 1=normal, 2=relaxed
#
#################Game##################
@ -52,7 +52,7 @@ maximum_characters_per_message = 300
#################IRC################
#
irc.server = chat.freenode.net
irc.channel = #UGX-mortalrealms
irc.channel = #UGX-realms
irc.nick = UGXMR-Bot
#irc.password =
#

View File

@ -0,0 +1,78 @@
-------------------------------
-- Action timers
-- Mod handling action timers
--
action_timers = {}
action_timers.timers = {}
action_timers.limits = {}
action_timers.api = {}
function action_timers.api.register_timer(name, limit)
if action_timers.timers[name] then
minetest.log("error", "[ACTimers] Cannot register timer " .. name .. " a second time")
return
elseif not limit then
minetest.log("error", "[ACTimers] Cannot register timer " .. name .. " without limit")
return
end
action_timers.timers[name] = limit
action_timers.limits[name] = limit
minetest.log("action", "[ACTimers] Timer " .. name .. " registered with time limit " .. limit)
end
function action_timers.api.do_action(name, func, params)
if not action_timers.timers[name] then
minetest.log("error", "[ACTimers] Timer " .. name .. " doesn't exist")
return
elseif not func then
minetest.log("error", "[ACTimers] Function passed to time checker for " .. name .. " is nil")
return
elseif action_timers.timers[name] > 0 then
minetest.log("error", "[ACTimers] Timer " .. name .. " is still up to 0")
return action_timers.timers[name]
end
action_timers.timers[name] = action_timers.limits[name]
if not params then
return func()
else
return func(unpack(params))
end
end
function action_timers.api.get_timer(name)
return action_timers.timers[name]
end
minetest.register_globalstep(function(dtime)
for name, _ in pairs(action_timers.timers) do
action_timers.timers[name] = action_timers.timers[name] - dtime
if action_timers.timers[name] < 0 then
action_timers.timers[name] = 0
end
end
end)
minetest.log("action", "[ACTimers] Loaded")
function action_timers.wrapper(pname, name, timername, value, func, params)
if not action_timers.api.get_timer(timername) then
action_timers.api.register_timer(timername, value)
return func(unpack(params))
else
local res = action_timers.api.do_action(timername, func, params)
if tonumber(res) then
minetest.chat_send_player(pname, "Please retry later, you used " .. name .. " last time less than " .. value .. " seconds ago.")
minetest.chat_send_player(pname, "Retry in: " .. math.floor(res) .. " seconds.")
minetest.log("action", "[action_timers] Player " .. pname .. " tried to use'" .. name .. "' within forbidden interval.")
return false
elseif res == true then
return res
end
end
end

View File

@ -0,0 +1,3 @@
##[action_timers]
This mod is required by [pvpbuttons]

3
worldmods/db/readme.md Normal file
View File

@ -0,0 +1,3 @@
##[db]
[teleporter] depends on this mod

View File

@ -0,0 +1,46 @@
PvP-Button Mod by Phiwari123
============================
This mod adds a PvP-Button to the player's inventory, which allows each
player on a server whether he/she wants to be attackable by others or not.
Current Version: 1.3
Dependencies: Either one of unified_inventory (recommended) or inventory_plus needs to be installed in order to use this mod
Report bugs or request help on the forum topic!
Installation
------------
Unzip the archive and place the folder in minetest/mods
For further information or help see:
http://wiki.minetest.net/Installing_Mods
License for Code
----------------
Copyright (C) 2015 Phiwari123 phiwari123@web.de
This program 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 version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
License for Textures, Models and Sounds
---------------------------------------
CC-BY-SA 3.0 UNPORTED. Created by Phiwari123

View File

@ -0,0 +1,3 @@
action_timers
unified_inventory?
inventory_plus?

View File

@ -0,0 +1,129 @@
-- Needed variables
local pvptable = {}
local huds = {}
local toggle_interval = 5 * 60
-- Inventory mod determination
local inv_mod = ""
if minetest.get_modpath("unified_inventory") ~= nil then
inv_mod = "unified_inventory"
minetest.log("action", "[pvpbutton] Using UnifiedInventory (u_inv) as inventory management mod")
elseif minetest.get_modpath("inventory_plus") ~= nil then
inv_mod = "inventory_plus"
minetest.log("action", "[pvpbutton] Using Inventory+ (inv+) as inventory management mod")
end
if inv_mod == "" then
error("No inventory mod could be found! Please install either unified_inventory (recommended) or inventory_plus")
end
-- The toggle callback
function toggle_pvp(localname)
local player = minetest.get_player_by_name(localname)
if pvptable[localname] == 0 then
pvptable[localname] = 1
minetest.chat_send_player(localname,
"PvP was enabled for "..localname)
player:hud_remove(huds[localname])
huds[localname] = player:hud_add({
hud_elem_type = "text",
position = {x = 1, y = 0},
offset = {x=-100, y = 20},
scale = {x = 100, y = 100},
text = "PvP is enabled for you!",
number = 0xFF0000 -- Red
})
-- Change nametag
local nametag = player:get_nametag_attributes()
player:set_nametag_attributes({
text = nametag.text,
color = {a=255, r=222, g=2, b=3},
})
return
else
pvptable[localname] = 0
minetest.chat_send_player(localname,
"PvP was disabled for "..localname)
player:hud_remove(huds[localname])
-- Change nametag
local nametag = player:get_nametag_attributes()
player:set_nametag_attributes({
text = nametag.text,
color = {a=255, r=255, g=255, b=255},
})
return
end
end
-- Link the toggle callback to the proper hook
if inv_mod == "unified_inventory" then
unified_inventory.register_button("pvp", {
type = "image",
show_with = "pvp",
image = "pvpbutton_pvp.png",
tooltip = "Toggle pvp",
action = function(player)
local pname = player:get_player_name()
action_timers.wrapper(pname,
"pvp toggle",
"pvp_" .. pname,
toggle_interval,
toggle_pvp, {pname}
)
end
})
else
minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.pvp then
local pname = player:get_player_name()
action_timers.wrapper(pname,
"pvp toggle",
"pvp_" .. pname,
toggle_interval,
toggle_pvp, {pname}
)
end
end)
end
-- Initialize values for players
minetest.register_on_joinplayer(function(player)
pvptable[player:get_player_name()] = 0
huds[player:get_player_name()] = nil
if inv_mod == "inventory_plus" then
inventory_plus.register_button(player, "pvpbutton_pvp", "PvP")
minetest.after(1, function()
inventory_plus.set_inventory_formspec(player, inventory_plus.get_formspec(player, inventory_plus.default))
end)
end
end)
-- Support on on_punchplayer hook
if minetest.setting_getbool("enable_pvp") then
if minetest.register_on_punchplayer then
minetest.register_on_punchplayer(
function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage, pvp)
if not hitter:is_player() then
return false
end
local localname = player:get_player_name()
local hittername = hitter:get_player_name()
if pvptable[hittername] == 1 then
if pvptable[localname] == 1 then
return false
else
minetest.chat_send_player(hittername, "Player " .. localname .. " does not have PvP activated")
end
else
minetest.chat_send_player(hittername, "PvP is disabled for you")
end
minetest.chat_send_player(localname, "Player " .. hittername .. " tried hurting you. It failed")
return true
end)
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

View File

@ -218,7 +218,7 @@ function time_reg.loop(loop, forceupdate)
time_reg.log("Entering day period : period skipped", "info")
else
minetest.settings:set("time_speed", time_reg.day_time_speed)
time_reg.log("Entering day period : time_speed " .. time_reg.day_time_speed, "action")
time_reg.log("Entering day period : time_speed " .. time_reg.day_time_speed, "info")
end
else
if time_reg.ratio.night == 0 then
@ -226,7 +226,7 @@ function time_reg.loop(loop, forceupdate)
time_reg.log("Entering night period : period skipped", "info")
else
minetest.settings:set("time_speed", time_reg.night_time_speed)
time_reg.log("Entering night period : time_speed " .. time_reg.night_time_speed, "action")
time_reg.log("Entering night period : time_speed " .. time_reg.night_time_speed, "info")
end
end
end