mirror of
https://repo.or.cz/minetest_playereffects.git
synced 2025-01-08 10:20:15 +01:00
Add effect metadata
Effect metadata is a means to store additional user-defined data for the effect, which can be reused when the cancel function of the effect is called. This commit also adds a new example (blind) to demonstrate usage of that.
This commit is contained in:
parent
a91e4c79ce
commit
21f053270f
25
examples.lua
25
examples.lua
@ -1,4 +1,20 @@
|
|||||||
----- EXAMPLE EFFECT TYPES -----
|
----- EXAMPLE EFFECT TYPES -----
|
||||||
|
-- Makes the player screen black for 5 seconds (very experimental!)
|
||||||
|
playereffects.register_effect_type("blind", "Blind", nil, {},
|
||||||
|
function(player)
|
||||||
|
local hudid = player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = { x=0.5, y=0.5 },
|
||||||
|
scale = { x=-100, y=-100 },
|
||||||
|
text = "playereffects_example_black.png",
|
||||||
|
})
|
||||||
|
return { hudid = hudid }
|
||||||
|
end,
|
||||||
|
function(effect)
|
||||||
|
local player = minetest.get_player_by_name(effect.playername)
|
||||||
|
player:hud_remove(effect.metadata.hudid)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
-- Makes the user faster
|
-- Makes the user faster
|
||||||
playereffects.register_effect_type("high_speed", "High speed", nil, {"speed"},
|
playereffects.register_effect_type("high_speed", "High speed", nil, {"speed"},
|
||||||
@ -75,7 +91,14 @@ playereffects.register_effect_type("stress", "Stress Test Effect", nil, {},
|
|||||||
|
|
||||||
|
|
||||||
------ Chat commands for the example effects ------
|
------ Chat commands for the example effects ------
|
||||||
|
minetest.register_chatcommand("blind", {
|
||||||
|
params = "",
|
||||||
|
description = "Makes your screen black for a short time.",
|
||||||
|
privs = {},
|
||||||
|
func = function(name, param)
|
||||||
|
playereffects.apply_effect_type("blind", 5, minetest.get_player_by_name(name))
|
||||||
|
end,
|
||||||
|
})
|
||||||
minetest.register_chatcommand("fast", {
|
minetest.register_chatcommand("fast", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Makes you fast for a short time.",
|
description = "Makes you fast for a short time.",
|
||||||
|
9
init.lua
9
init.lua
@ -105,6 +105,8 @@ 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,
|
||||||
@ -113,11 +115,11 @@ function playereffects.apply_effect_type(effect_type_id, duration, player)
|
|||||||
time_left = duration,
|
time_left = duration,
|
||||||
hudids = hudids,
|
hudids = hudids,
|
||||||
hudpos = free_hudpos,
|
hudpos = free_hudpos,
|
||||||
}
|
metadata = metadata,
|
||||||
|
}
|
||||||
|
|
||||||
playereffects.effects[effect_id] = effect
|
playereffects.effects[effect_id] = effect
|
||||||
|
|
||||||
playereffects.effect_types[effect_type_id].apply(player)
|
|
||||||
minetest.log("action", "[playereffects] Effect type "..effect_type_id.." applied to player "..playername.."!")
|
minetest.log("action", "[playereffects] Effect type "..effect_type_id.." applied to player "..playername.."!")
|
||||||
minetest.after(duration, function(effect_id) playereffects.cancel_effect(effect_id) end, effect_id)
|
minetest.after(duration, function(effect_id) playereffects.cancel_effect(effect_id) end, effect_id)
|
||||||
end
|
end
|
||||||
@ -202,6 +204,7 @@ function playereffects.save_to_file()
|
|||||||
time_left = new_duration,
|
time_left = new_duration,
|
||||||
start_time = effect.start_time,
|
start_time = effect.start_time,
|
||||||
playername = effect.playername,
|
playername = effect.playername,
|
||||||
|
metadata = effect.metadata
|
||||||
}
|
}
|
||||||
if(inactive_effects[effect.playername] == nil) then
|
if(inactive_effects[effect.playername] == nil) then
|
||||||
inactive_effects[effect.playername] = {}
|
inactive_effects[effect.playername] = {}
|
||||||
|
BIN
textures/playereffects_example_black.png
Normal file
BIN
textures/playereffects_example_black.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 B |
Loading…
Reference in New Issue
Block a user