commit
1225504258
53 changed files with 862 additions and 294 deletions
57
mods/other/hud_events/README.md
Normal file
57
mods/other/hud_events/README.md
Normal file
|
@ -0,0 +1,57 @@
|
|||
# `hud_events`
|
||||
|
||||
Forked and edited from `hud_score` by ANAND (ClobberXD), licensed under the LGPLv2.1+ license.
|
||||
|
||||
`hud_events` provides an API to display HUD event elements which can be used to
|
||||
display various hints and messages.
|
||||
|
||||
## Methods
|
||||
|
||||
- `hud_event.new(name, event_def)`: Adds a new HUD event element to player `name`.
|
||||
- `name` [string]: Player name
|
||||
- `event_def` [table]: HUD event element definition. See below.
|
||||
|
||||
## HUD event element definition
|
||||
|
||||
HUD event element definition table, passed to `hud_event.new`.
|
||||
|
||||
Example definition:
|
||||
|
||||
```lua
|
||||
{
|
||||
name = "ctf_bandages:healing", -- Can be any arbitrary string
|
||||
color = "0x00FF00", -- Should be compatible with Minetest's HUD def
|
||||
value = "x has healed y", -- The actual event to be displayed
|
||||
-- Field `time` is automatically added by `hud_event.new`
|
||||
-- to keep track of element expiry
|
||||
}
|
||||
```
|
||||
|
||||
## `players` table
|
||||
|
||||
This is a table of tables, indexed by player names. This table holds the HUD
|
||||
data of all online players. Each sub-table is a list of HUD event elements,
|
||||
which are added by `hud_event.new`.
|
||||
|
||||
```lua
|
||||
local players = {
|
||||
["name"] = {
|
||||
[1] = <hud_event_element>,
|
||||
[2] = <hud_event_element>,
|
||||
[3] = <hud_event_element>
|
||||
...
|
||||
},
|
||||
["name2"] = {
|
||||
...
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Changes
|
||||
|
||||
Changes that have been made compared to the original `hud_score` mod. Lines mentioned underneath refer to the lines in the `hud_events`' init.lua file.
|
||||
- replaced all occurences of `score` with `event` (10th March 2021)
|
||||
- changed variables and arguments in the lines 5, 6 and 36 (10th march 2021)
|
||||
- edited and added arguments in line 39 and 40 (10th march 2021)
|
||||
- deleted an `if` statement after line 28 (10th march 2021)
|
139
mods/other/hud_events/init.lua
Normal file
139
mods/other/hud_events/init.lua
Normal file
|
@ -0,0 +1,139 @@
|
|||
hud_event = {}
|
||||
local hud = hudkit()
|
||||
|
||||
local players = {}
|
||||
local duration = 7
|
||||
local max = 3
|
||||
local next_check = 10000000
|
||||
-- Bootstrap 5 palette
|
||||
local colors = {
|
||||
primary = 0x0D6EFD,
|
||||
secondary = 0x6C757D,
|
||||
success = 0x198754,
|
||||
info = 0x0DCAF0,
|
||||
warning = 0xFFC107,
|
||||
danger = 0xDC3545,
|
||||
light = 0xF8F9FA,
|
||||
dark = 0x212529,
|
||||
}
|
||||
hud_event.colors = colors
|
||||
|
||||
local function update(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
||||
-- Handle all elements marked for deletion
|
||||
-- and rebuild table
|
||||
local temp = {}
|
||||
for _, def in ipairs(players[name]) do
|
||||
if def.delete then
|
||||
if hud:exists(player, def.name) then
|
||||
hud:remove(player, def.name)
|
||||
end
|
||||
else
|
||||
table.insert(temp, def)
|
||||
end
|
||||
end
|
||||
|
||||
for i, def in ipairs(temp) do
|
||||
local text = tostring(def.value)
|
||||
if hud:exists(player, def.name) then
|
||||
hud:change(player, def.name, "text", text)
|
||||
hud:change(player, def.name, "offset", {x = 0, y = i * 20})
|
||||
else
|
||||
hud:add(player, def.name, {
|
||||
hud_elem_type = "text",
|
||||
alignment = {x = 0, y = 0},
|
||||
position = {x = 0.5, y = 0.7},
|
||||
offset = {x = 0, y = i * 20},
|
||||
number = tonumber(def.color),
|
||||
text = text,
|
||||
z_index = -200
|
||||
})
|
||||
end
|
||||
end
|
||||
players[name] = temp
|
||||
end
|
||||
|
||||
function hud_event.new(name, def)
|
||||
-- Verify HUD event element def
|
||||
if not name or not def or type(def) ~= "table" or
|
||||
not def.name or not def.value or not def.color then
|
||||
error("hud_event: Invalid HUD event element definition", 2)
|
||||
end
|
||||
|
||||
def.color = colors[def.color] or def.color
|
||||
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
||||
-- Store element expiration time in def.time
|
||||
-- and append event element def to players[name]
|
||||
def.time = os.time() + duration
|
||||
if next_check > duration then
|
||||
next_check = duration
|
||||
end
|
||||
|
||||
-- If a HUD event element with the same name exists already,
|
||||
-- reuse it instead of creating a new element
|
||||
local is_new = true
|
||||
for i, hud_event_spec in ipairs(players[name]) do
|
||||
if hud_event_spec.name == def.name then
|
||||
is_new = false
|
||||
players[name][i] = def
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if is_new then
|
||||
table.insert(players[name], def)
|
||||
end
|
||||
|
||||
-- If more than `max` active elements, mark oldest element for deletion
|
||||
if #players[name] > max then
|
||||
players[name][1].delete = true
|
||||
end
|
||||
|
||||
update(name)
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
next_check = next_check - dtime
|
||||
if next_check > 0 then
|
||||
return
|
||||
end
|
||||
|
||||
next_check = 10000000
|
||||
|
||||
-- Loop through HUD score elements of all players
|
||||
-- and remove them if they've expired
|
||||
for name, hudset in pairs(players) do
|
||||
local modified = false
|
||||
for i, def in pairs(hudset) do
|
||||
local rem = def.time - os.time()
|
||||
if rem <= 0 then
|
||||
def.delete = true
|
||||
modified = true
|
||||
elseif rem < next_check then
|
||||
next_check = rem
|
||||
end
|
||||
end
|
||||
|
||||
-- If a player's hudset was modified, update player's HUD
|
||||
if modified then
|
||||
update(name)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
players[player:get_player_name()] = {}
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
players[player:get_player_name()] = nil
|
||||
end)
|
3
mods/other/hud_events/mod.conf
Normal file
3
mods/other/hud_events/mod.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
name = hud_events
|
||||
description = API for displaying events on HUD
|
||||
depends = hudkit
|
|
@ -56,11 +56,11 @@ function random_messages.read_messages()
|
|||
"You gain more score the better the opponent you defeat.",
|
||||
"Find weapons in chests or mine and use furnaces to make stronger swords.",
|
||||
"Players are immune to attack for 5 seconds after they respawn.",
|
||||
"Access the pro section of the chest by achieving a 10k+ score and killing 3 people for every 2 deaths.",
|
||||
"Access the pro section of the chest by achieving a 10k+ score, killing 3 people for every 2 deaths and capture the flag 10 times.",
|
||||
"Use team doors (steel) to stop the enemy walking into your base.",
|
||||
"Craft 6 cobbles and 1 steel ingot together to make reinforced cobble.",
|
||||
"Sprint by pressing the fast key (E) when you have stamina.",
|
||||
"Like CTF? Give feedback using /report, and consider donating at rubenwardy.com/donate",
|
||||
"Like CTF? Give feedback using /report, and consider joining the Discord",
|
||||
"Want to submit your own map? Visit ctf.rubenwardy.com to get involved.",
|
||||
"Using limited resources for building structures that don't strengthen your base's defences is discouraged.",
|
||||
"To report misbehaving players to moderators, please use /report <name> <action>",
|
||||
|
@ -72,13 +72,14 @@ function random_messages.read_messages()
|
|||
"Use /r <number> or /rn <number> to check the rankings of the player in the given rank.",
|
||||
"Use bandages on team-mates to heal them by 3-4 HP if their health is below 15 HP.",
|
||||
"Use /m to add a team marker at pointed location, that's visible only to team-mates.",
|
||||
"Use /summary to check scores of the current match and the previous match.",
|
||||
"Use /mr to remove your marker.",
|
||||
"Use /summary or /s to check scores of the current match and the previous match.",
|
||||
"Use /maps to view the maps catalog. It also contains license info and attribution details.",
|
||||
"Change your class in your base by right clicking the home flag or typing /class.",
|
||||
"Medics cause troops within 10 metres to regenerate health faster.",
|
||||
"Hitting your enemy does more damage than not hitting them.",
|
||||
"Press right mouse button or double-tap the screen to activate scope while wielding a sniper rifle.",
|
||||
"The 'Updates' tab in your inventory will show some of the latest updates to CTF",
|
||||
"Medics can dig pillars by right clicking the base of one with their paxel.",
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue