From 85fbd146b145af79d5e197957caa5308f4101d66 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 13 Jul 2014 22:07:04 +0200 Subject: [PATCH] Add support for hidden effects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hidden effects are effects which are not exposed to the player’s HUD. --- examples.lua | 23 +++++++++++++++++++++++ init.lua | 10 ++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/examples.lua b/examples.lua index 8f0ff67..69950fe 100644 --- a/examples.lua +++ b/examples.lua @@ -12,6 +12,21 @@ playereffects.register_effect_type("high_speed", "High speed", nil, {"speed"}, end ) +-- Makes the user faster (hidden effect) +playereffects.register_effect_type("high_speed_hidden", "High speed", nil, {"speed"}, + function(player) + player:set_physics_override(4,nil,nil) + end, + + function(effect) + local player = minetest.get_player_by_name(effect.playername) + player:set_physics_override(1,nil,nil) + end, + true +) + + + -- Slows the user down playereffects.register_effect_type("low_speed", "Low speed", nil, {"speed"}, function(player) @@ -69,6 +84,14 @@ minetest.register_chatcommand("fast", { playereffects.apply_effect_type("high_speed", 10, minetest.get_player_by_name(name)) end, }) +minetest.register_chatcommand("hfast", { + params = "", + description = "Makes you fast for a short time (hidden effect).", + privs = {}, + func = function(name, param) + playereffects.apply_effect_type("high_speed_hidden", 10, minetest.get_player_by_name(name)) + end, +}) minetest.register_chatcommand("slow", { params = "", description = "Makes you slow for a long time.", diff --git a/init.lua b/init.lua index cad14d6..992b62d 100644 --- a/init.lua +++ b/init.lua @@ -48,7 +48,7 @@ function playereffects.next_effect_id() end --[=[ API functions ]=] -function playereffects.register_effect_type(name, description, icon, groups, apply, cancel) +function playereffects.register_effect_type(name, description, icon, groups, apply, cancel, hidden) effect_type = {} effect_type.description = description effect_type.apply = apply @@ -59,6 +59,11 @@ function playereffects.register_effect_type(name, description, icon, groups, app else effect_type.cancel = function() end end + if hidden ~= nil then + effect_type.hidden = hidden + else + effect_type.hidden = false + end playereffects.effect_types[name] = effect_type minetest.log("action", "Effect type "..name.." registered!") end @@ -306,7 +311,8 @@ end function playereffects.hud_effect(effect_type_id, player, pos, time_left) local text_id, icon_id - if(playereffects.use_hud == true) then + local effect_type = playereffects.effect_types[effect_type_id] + if(playereffects.use_hud == true and effect_type.hidden == false) then text_id = player:hud_add({ hud_elem_type = "text", position = { x = 1, y = 0.3 },