Add effect failure
The apply function of effects can return false, in that case, the effect is not applied
This commit is contained in:
parent
21f053270f
commit
15daa210c4
26
examples.lua
26
examples.lua
|
@ -1,4 +1,13 @@
|
||||||
----- EXAMPLE EFFECT TYPES -----
|
----- 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!)
|
-- Makes the player screen black for 5 seconds (very experimental!)
|
||||||
playereffects.register_effect_type("blind", "Blind", nil, {},
|
playereffects.register_effect_type("blind", "Blind", nil, {},
|
||||||
function(player)
|
function(player)
|
||||||
|
@ -8,7 +17,12 @@ playereffects.register_effect_type("blind", "Blind", nil, {},
|
||||||
scale = { x=-100, y=-100 },
|
scale = { x=-100, y=-100 },
|
||||||
text = "playereffects_example_black.png",
|
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,
|
end,
|
||||||
function(effect)
|
function(effect)
|
||||||
local player = minetest.get_player_by_name(effect.playername)
|
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 ------
|
------ 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", {
|
minetest.register_chatcommand("blind", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Makes your screen black for a short time.",
|
description = "Makes your screen black for a short time.",
|
||||||
|
|
12
init.lua
12
init.lua
|
@ -69,7 +69,17 @@ end
|
||||||
|
|
||||||
function playereffects.apply_effect_type(effect_type_id, duration, player)
|
function playereffects.apply_effect_type(effect_type_id, duration, player)
|
||||||
local start_time = os.time()
|
local start_time = os.time()
|
||||||
|
local status = playereffects.effect_types[effect_type_id].apply(player)
|
||||||
local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
|
local metadata
|
||||||
|
|
||||||
|
if(status == false) then
|
||||||
|
minetest.log("action", "[playereffects] Attempt to apply effect type "..effect_type_id.." to player "..playername.." failed!")
|
||||||
|
return
|
||||||
|
else
|
||||||
|
metadata = status
|
||||||
|
end
|
||||||
|
|
||||||
local groups = playereffects.effect_types[effect_type_id].groups
|
local groups = playereffects.effect_types[effect_type_id].groups
|
||||||
for k,v in pairs(groups) do
|
for k,v in pairs(groups) do
|
||||||
playereffects.cancel_effect_group(v, playername)
|
playereffects.cancel_effect_group(v, playername)
|
||||||
|
@ -105,8 +115,6 @@ function playereffects.apply_effect_type(effect_type_id, duration, player)
|
||||||
hudids = {text_id=nil, icon_id=nil}
|
hudids = {text_id=nil, icon_id=nil}
|
||||||
end
|
end
|
||||||
|
|
||||||
local metadata = playereffects.effect_types[effect_type_id].apply(player)
|
|
||||||
|
|
||||||
local effect = {
|
local effect = {
|
||||||
playername = playername,
|
playername = playername,
|
||||||
effect_id = effect_id,
|
effect_id = effect_id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user