diff options
author | Wuzzy <almikes@aol.com> | 2014-07-14 17:55:48 +0200 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2014-07-14 17:55:48 +0200 |
commit | 15daa210c496232caa110e32bfb61bfb54e13183 (patch) | |
tree | 964cd3c395d5154fe72e216350e04527983ab627 /examples.lua | |
parent | 21f053270f0015438e28b347a87ba9a151c59aff (diff) |
Add effect failure
The apply function of effects can return false, in that case, the effect
is not applied
Diffstat (limited to 'examples.lua')
-rw-r--r-- | examples.lua | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/examples.lua b/examples.lua index ce3fbcd..ba798f7 100644 --- a/examples.lua +++ b/examples.lua @@ -1,4 +1,13 @@ ----- EXAMPLE EFFECT TYPES ----- +--[[ Null effect. The apply function always returns false, which means applying the +effect will never succeed ]] +playereffects.register_effect_type("null", "No effect", nil, {}, + function() + return false + end +) + + -- Makes the player screen black for 5 seconds (very experimental!) playereffects.register_effect_type("blind", "Blind", nil, {}, function(player) @@ -8,7 +17,12 @@ playereffects.register_effect_type("blind", "Blind", nil, {}, scale = { x=-100, y=-100 }, text = "playereffects_example_black.png", }) - return { hudid = hudid } + if(hudid ~= nil) then + return { hudid = hudid } + else + minetest.log("error", "[playereffects] [examples] The effect \"Blind\" could not be applied. The call to hud_add(...) failed.") + return false + end end, function(effect) local player = minetest.get_player_by_name(effect.playername) @@ -91,6 +105,16 @@ playereffects.register_effect_type("stress", "Stress Test Effect", nil, {}, ------ Chat commands for the example effects ------ +-- Null effect (never succeeds) +minetest.register_chatcommand("null", { + params = "", + description = "Does nothing.", + privs = {}, + func = function(name, param) + playereffects.apply_effect_type("null", 5, minetest.get_player_by_name(name)) + end, +}) + minetest.register_chatcommand("blind", { params = "", description = "Makes your screen black for a short time.", |