Compare commits

...

2 commits

Author SHA1 Message Date
philipmi
cd355bc9cd Merge branch 'master' of https://github.com/MT-CTF/capturetheflag 2021-03-31 18:36:17 +02:00
Lars Müller
87f7212f43
Replace chat with HUD events, add BS 5 palette (#848)
* Replace chat with HUD events, add BS 5 palette

* Use HUD events for paxel too

* Move paxel_stop function up
2021-03-29 14:00:46 -07:00
9 changed files with 106 additions and 34 deletions

View file

@ -22,7 +22,19 @@ minetest.register_craftitem("ctf_bandages:bandage", {
local hp = object:get_hp()
local limit = ctf_bandages.heal_percent * object:get_properties().hp_max
if hp > 0 and hp < limit then
if hp <= 0 then
hud_event.new(name, {
name = "ctf_bandages:dead",
color = "warning",
value = pname .. " is dead!",
})
elseif hp >= limit then
hud_event.new(name, {
name = "ctf_bandages:limit",
color = "warning",
value = pname .. " already has " .. limit .. " HP!",
})
else
local hp_add = math.random(3,4)
kill_assist.add_heal_assist(pname, hp_add)
@ -33,14 +45,18 @@ minetest.register_craftitem("ctf_bandages:bandage", {
end
object:set_hp(hp)
minetest.chat_send_player(pname, minetest.colorize("#C1FF44", name .. " has healed you!"))
return itemstack
else
minetest.chat_send_player(name, pname .. " has " .. hp .. " HP. You can't heal them.")
hud_event.new(pname, {
name = "ctf_bandages:heal",
color = 0xC1FF44,
value = name .. " healed you!",
})
end
else
minetest.chat_send_player(name, pname.." isn't in your team!")
hud_event.new(name, {
name = "ctf_bandages:team",
color = "warning",
value = pname .. " isn't in your team!",
})
end
end,
})

View file

@ -148,6 +148,15 @@ local function isdiggable(name)
)
end
local function paxel_stop(pname, reason)
hud_event.new(pname, {
name = "ctf_classes:paxel_stop",
color = "success",
value = table.concat({"Pillar digging stopped", reason, "- wait " .. DIG_COOLDOWN .. "s"}, " "),
})
diggers[pname] = minetest.after(DIG_COOLDOWN, function() diggers[pname] = nil end)
end
local function remove_pillar(pos, pname)
local name = minetest.get_node(pos).name
@ -161,13 +170,11 @@ local function remove_pillar(pos, pname)
pos.y = pos.y + 1
minetest.after(DIG_SPEED, remove_pillar, pos, pname)
else
minetest.chat_send_player(pname, "Pillar digging stopped, too far away from digging pos. Can activate again in "..DIG_COOLDOWN.." seconds")
diggers[pname] = minetest.after(DIG_COOLDOWN, function() diggers[pname] = nil end)
paxel_stop(pname, "at too far away node")
end
end
else
minetest.chat_send_player(pname, "Pillar digging stopped at undiggable node. Can activate again in "..DIG_COOLDOWN.." seconds")
diggers[pname] = minetest.after(DIG_COOLDOWN, function() diggers[pname] = nil end)
paxel_stop(pname, "at undiggable node")
end
end
@ -191,20 +198,39 @@ minetest.register_tool("ctf_classes:paxel_bronze", {
if pointed_thing.type == "node" then
local pname = placer:get_player_name()
if not isdiggable(minetest.get_node(pointed_thing.under).name) or ctf_match.is_in_build_time() then
minetest.chat_send_player(pname, "Can't dig node or build time active")
if not isdiggable(minetest.get_node(pointed_thing.under).name) then
hud_event.new(pname, {
name = "ctf_classes:paxel_undiggable",
color = "warning",
value = "Can't paxel node!",
})
return minetest.item_place(itemstack, placer, pointed_thing)
end
if ctf_match.is_in_build_time() then
hud_event.new(pname, {
name = "ctf_classes:paxel_build_time",
color = "warning",
value = "Build time active!",
})
return minetest.item_place(itemstack, placer, pointed_thing)
end
if not diggers[pname] then
minetest.chat_send_player(pname, "Pillar digging started")
hud_event.new(pname, {
name = "ctf_classes:paxel_start",
color = "primary",
value = "Pillar digging started",
})
diggers[pname] = true
remove_pillar(pointed_thing.under, pname)
elseif type(diggers[pname]) ~= "table" then
minetest.chat_send_player(pname, "Pillar digging stopped. Can activate again in "..DIG_COOLDOWN.." seconds")
diggers[pname] = minetest.after(DIG_COOLDOWN, function() diggers[pname] = nil end)
paxel_stop(pname)
else
minetest.chat_send_player(pname, "You can't activate yet")
hud_event.new(pname, {
name = "ctf_classes:paxel_timer",
color = "warning",
value = "You can't activate yet!",
})
end
end
end,
@ -216,8 +242,7 @@ minetest.register_tool("ctf_classes:paxel_bronze", {
minetest.after(2, function()
if user and user:get_player_control().RMB then
if diggers[pname] and type(diggers[pname]) ~= "table" then
minetest.chat_send_player(pname, "Pillar digging stopped. Can activate again in "..DIG_COOLDOWN.." seconds")
diggers[pname] = minetest.after(DIG_COOLDOWN, function() diggers[pname] = nil end)
paxel_stop(pname)
end
end
end)

View file

@ -84,8 +84,11 @@ function minetest.is_protected(pos, name, ...)
local flag, distSQ = ctf_flag.get_nearest(pos)
if flag and pos.y >= flag.y - 1 and distSQ < rs then
minetest.chat_send_player(name,
"Too close to the flag to build! Leave at least " .. r .. " blocks around the flag.")
hud_event.new(name, {
name = "ctf_bandages:team",
color = "warning",
value = "Too close to the flag to build (< " .. r .. " nodes) !",
})
return true
else
return old_is_protected(pos, name, ...)

View file

@ -66,7 +66,11 @@ local old_can_attack = ctf.can_attack
function ctf.can_attack(player, hitter, ...)
if ctf_match.is_in_build_time() then
if hitter:is_player() then
minetest.chat_send_player(hitter:get_player_name(), "Match hasn't started yet!")
hud_event.new(hitter:get_player_name(), {
name = "ctf_match:buildtime_hit",
color = "warning",
value = "Match hasn't started yet!",
})
end
return false
end

View file

@ -44,14 +44,20 @@ function ctf.can_attack(player, hitter, ...)
local hname = hitter:get_player_name()
if ctf_respawn_immunity.is_immune(player) then
minetest.chat_send_player(hname, minetest.colorize("#EE8822", pname ..
" just respawned or joined," .. " and is immune to attacks!"))
hud_event.new(hname, {
name = "ctf_respawn_immunity:hit",
color = 0xEE8822,
value = pname .. " has respawn immunity!",
})
return false
end
if ctf_respawn_immunity.is_immune(hitter) then
minetest.chat_send_player(hname, minetest.colorize("#FF8C00",
"Your immunity has ended because you attacked a player"))
hud_event.new(hname, {
name = "ctf_respawn_immunity:end",
color = 0xFF8C00,
value = "Your immunity has ended!",
})
immune_players[hname] = nil
ctf_respawn_immunity.update_effects(hitter)
end

View file

@ -5,6 +5,18 @@ 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)
@ -52,6 +64,8 @@ function hud_event.new(name, def)
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

View file

@ -71,8 +71,11 @@ local function stop_healing(player, interrupted)
players[name] = nil
if interrupted then
minetest.chat_send_player(name, minetest.colorize("#FF4444",
"Your healing was interrupted"..reason_handler(interrupted)))
hud_event.new(name, {
name = "medkits:interrupt",
color = 0xFF4444,
value = "Your healing was interrupted" .. reason_handler(interrupted),
})
player:set_hp(info.hp)
player:get_inventory():add_item("main", ItemStack("medkits:medkit 1"))
end

View file

@ -2,8 +2,6 @@
local players = {}
local blocks_per_second = 5
local resend_notification_seconds = 10
-- Bootstrap 4 "warning" color
local warning_color = 0xFFC107
minetest.register_on_joinplayer(function(player)
-- player has to wait after join before they can place a node
@ -22,7 +20,7 @@ minetest.register_on_placenode(function(pos, _newnode, placer, oldnode, _itemsta
-- This should happen rarely
hud_event.new(name, {
name = "place_limit:unpointable",
color = warning_color,
color = "warning",
value = "Block not pointable (dug/replaced)!",
})
minetest.set_node(pos, oldnode)
@ -39,7 +37,7 @@ minetest.register_on_placenode(function(pos, _newnode, placer, oldnode, _itemsta
if (time - placements.last_notification_sent) / 1e6 >= resend_notification_seconds then
hud_event.new(name, {
name = "place_limit:speed",
color = warning_color,
color = "warning",
value = "Placing too fast!",
})
placements.last_notification_sent = time

View file

@ -163,8 +163,11 @@ function minetest.is_protected(pos, name, info, ...)
local flag, distSQ = ctf_flag.get_nearest(pos)
if flag and pos.y >= flag.y - 1 and distSQ < rs then
minetest.chat_send_player(name,
"You can't shoot blocks within "..r.." nodes of a flag!")
hud_event.new(name, {
name = "sniper_rifles:hit_base",
color = "warning",
value = "You can't shoot blocks within " .. r .. " nodes of a flag!",
})
return true
else
return old_is_protected(pos, name, info, ...)