1 ----- EXAMPLE EFFECT TYPES -----
2 --[[ This is just a helper function to inform the user of the chat command
3 of the result and, if successful, shows the effect ID. ]]
4 local function notify(name
, retcode
)
5 if(retcode
== false) then
6 minetest
.chat_send_player(name
, "Effect application failed. Effect was NOT applied.")
8 minetest
.chat_send_player(name
, "Effect applied. Effect ID: "..tostring(retcode
))
12 --[[ Null effect. The apply function always returns false, which means applying the
13 effect will never succeed ]]
14 playereffects
.register_effect_type("null", "No effect", nil, {},
21 -- Makes the player screen black for 5 seconds (very experimental!)
22 playereffects
.register_effect_type("blind", "Blind", nil, {},
24 local hudid
= player
:hud_add({
25 hud_elem_type
= "image",
26 position
= { x
=0.5, y
=0.5 },
27 scale
= { x
=-100, y
=-100 },
28 text
= "playereffects_example_black.png",
31 return { hudid
= hudid
}
33 minetest
.log("error", "[playereffects] [examples] The effect \"Blind\" could not be applied. The call to hud_add(...) failed.")
37 function(effect
, player
)
38 player
:hud_remove(effect
.metadata
.hudid
)
42 -- Makes the user faster
43 playereffects
.register_effect_type("high_speed", "High speed", nil, {"speed"},
45 player
:set_physics_override(4,nil,nil)
48 function(effect
, player
)
49 player
:set_physics_override(1,nil,nil)
53 -- Makes the user faster (hidden effect)
54 playereffects
.register_effect_type("high_speed_hidden", "High speed", nil, {"speed"},
56 player
:set_physics_override(4,nil,nil)
59 function(effect
, player
)
60 player
:set_physics_override(1,nil,nil)
67 -- Slows the user down
68 playereffects
.register_effect_type("low_speed", "Low speed", nil, {"speed"},
70 player
:set_physics_override(0.25,nil,nil)
73 function(effect
, player
)
74 player
:set_physics_override(1,nil,nil)
78 -- Increases the jump height
79 playereffects
.register_effect_type("highjump", "Greater jump height", "playereffects_example_highjump.png", {"jump"},
81 player
:set_physics_override(nil,2,nil)
83 function(effect
, player
)
84 player
:set_physics_override(nil,1,nil)
88 -- Adds the “fly” privilege. Keep the privilege even if the player dies
89 playereffects
.register_effect_type("fly", "Fly mode available", "playereffects_example_fly.png", {"fly"},
91 local playername
= player
:get_player_name()
92 local privs
= minetest
.get_player_privs(playername
)
94 minetest
.set_player_privs(playername
, privs
)
96 function(effect
, player
)
97 local privs
= minetest
.get_player_privs(effect
.playername
)
99 minetest
.set_player_privs(effect
.playername
, privs
)
102 false -- do NOT cancel the effect on death
105 -- Repeating effect type: Adds 1 HP per second
106 playereffects
.register_effect_type("regen", "Regeneration", "heart.png", {"health"},
108 player
:set_hp(player
:get_hp()+1)
113 -- Repeating effect type: Adds 1 HP per 3 seconds
114 playereffects
.register_effect_type("slowregen", "Slow Regeneration", "heart.png", {"health"},
116 player
:set_hp(player
:get_hp()+1)
122 -- Dummy effect for the stree test
123 playereffects
.register_effect_type("stress", "Stress Test Effect", nil, {},
126 function(effect
, player
)
132 ------ Chat commands for the example effects ------
133 -- Null effect (never succeeds)
134 minetest
.register_chatcommand("null", {
136 description
= "Does nothing.",
138 func
= function(name
, param
)
139 local ret
= playereffects
.apply_effect_type("null", 5, minetest
.get_player_by_name(name
))
144 minetest
.register_chatcommand("blind", {
146 description
= "Makes your screen black for a short time.",
148 func
= function(name
, param
)
149 local ret
= playereffects
.apply_effect_type("blind", 5, minetest
.get_player_by_name(name
))
153 minetest
.register_chatcommand("fast", {
155 description
= "Makes you fast for a short time.",
157 func
= function(name
, param
)
158 local ret
= playereffects
.apply_effect_type("high_speed", 10, minetest
.get_player_by_name(name
))
162 minetest
.register_chatcommand("hfast", {
164 description
= "Makes you fast for a short time (hidden effect).",
166 func
= function(name
, param
)
167 local ret
= playereffects
.apply_effect_type("high_speed_hidden", 10, minetest
.get_player_by_name(name
))
171 minetest
.register_chatcommand("slow", {
173 description
= "Makes you slow for a long time.",
175 func
= function(name
, param
)
176 local ret
= playereffects
.apply_effect_type("low_speed", 120, minetest
.get_player_by_name(name
))
180 minetest
.register_chatcommand("highjump", {
182 description
= "Makes you jump higher for a short time.",
184 func
= function(name
, param
)
185 local ret
= playereffects
.apply_effect_type("highjump", 20, minetest
.get_player_by_name(name
))
190 minetest
.register_chatcommand("fly", {
192 description
= "Grants you the fly privilege for a minute. You keep the effect when you die.",
194 func
= function(name
, param
)
195 local ret
= playereffects
.apply_effect_type("fly", 60, minetest
.get_player_by_name(name
))
200 minetest
.register_chatcommand("regen", {
202 description
= "Gives you 1 half heart per second 10 times, healing you by 5 hearts in total.",
204 func
= function(name
, param
)
205 local ret
= playereffects
.apply_effect_type("regen", 10, minetest
.get_player_by_name(name
))
210 minetest
.register_chatcommand("slowregen", {
212 description
= "Gives you 1 half heart every 3 seconds 10 times, healing you by 5 hearts in total.",
214 func
= function(name
, param
)
215 local ret
= playereffects
.apply_effect_type("slowregen", 10, minetest
.get_player_by_name(name
))
221 Cancel all active effects
223 minetest
.register_chatcommand("cancelall", {
225 description
= "Cancels all your effects.",
227 func
= function(name
, param
)
228 local effects
= playereffects
.get_player_effects(name
)
230 playereffects
.cancel_effect(effects
[e
].effect_id
)
232 minetest
.chat_send_player(name
, "All effects cancelled.")
236 --[[ The stress test applies a shitload of effects at once.
237 This is used to test the performance of this mod at very large effect numbers. ]]
238 minetest
.register_chatcommand("stresstest", {
239 params
= "[<effects>]",
240 descriptions
= "Start the stress test for Player Effects with <effects> effects.",
241 privs
= {server
=true},
242 func
= function(name
, param
)
243 local player
= minetest
.get_player_by_name(name
)
245 if(type(param
)=="string") then
246 if(type(tonumber(param
)) == "number") then
247 max = tonumber(param
)
250 minetest
.debug("[playereffects] Stress test started for "..name
.." with "..max.." effects.")
252 playereffects
.apply_effect_type("stress", math
.random(6,60), player
)
254 minetest
.debug("[playereffects] Effect "..i
.." of "..max.." applied.")
255 minetest
.chat_send_player(name
, "[playereffects] Effect "..i
.." of "..max.." applied.")