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 -- Dummy effect for the stree test
106 playereffects
.register_effect_type("stress", "Stress Test Effect", nil, {},
109 function(effect
, player
)
114 ------ Chat commands for the example effects ------
115 -- Null effect (never succeeds)
116 minetest
.register_chatcommand("null", {
118 description
= "Does nothing.",
120 func
= function(name
, param
)
121 local ret
= playereffects
.apply_effect_type("null", 5, minetest
.get_player_by_name(name
))
126 minetest
.register_chatcommand("blind", {
128 description
= "Makes your screen black for a short time.",
130 func
= function(name
, param
)
131 local ret
= playereffects
.apply_effect_type("blind", 5, minetest
.get_player_by_name(name
))
135 minetest
.register_chatcommand("fast", {
137 description
= "Makes you fast for a short time.",
139 func
= function(name
, param
)
140 local ret
= playereffects
.apply_effect_type("high_speed", 10, minetest
.get_player_by_name(name
))
144 minetest
.register_chatcommand("hfast", {
146 description
= "Makes you fast for a short time (hidden effect).",
148 func
= function(name
, param
)
149 local ret
= playereffects
.apply_effect_type("high_speed_hidden", 10, minetest
.get_player_by_name(name
))
153 minetest
.register_chatcommand("slow", {
155 description
= "Makes you slow for a long time.",
157 func
= function(name
, param
)
158 local ret
= playereffects
.apply_effect_type("low_speed", 120, minetest
.get_player_by_name(name
))
162 minetest
.register_chatcommand("highjump", {
164 description
= "Makes you jump higher for a short time.",
166 func
= function(name
, param
)
167 local ret
= playereffects
.apply_effect_type("highjump", 20, minetest
.get_player_by_name(name
))
172 minetest
.register_chatcommand("fly", {
174 description
= "Grants you the fly privilege for a minute. You keep the effect when you die.",
176 func
= function(name
, param
)
177 local ret
= playereffects
.apply_effect_type("fly", 60, minetest
.get_player_by_name(name
))
183 Cancel all active effects
185 minetest
.register_chatcommand("cancelall", {
187 description
= "Cancels all your effects.",
189 func
= function(name
, param
)
190 local effects
= playereffects
.get_player_effects(name
)
192 playereffects
.cancel_effect(effects
[e
].effect_id
)
194 minetest
.chat_send_player(name
, "All effects cancelled.")
198 --[[ The stress test applies a shitload of effects at once.
199 This is used to test the performance of this mod at very large effect numbers. ]]
200 minetest
.register_chatcommand("stresstest", {
201 params
= "[<effects>]",
202 descriptions
= "Start the stress test for Player Effects with <effects> effects.",
203 privs
= {server
=true},
204 func
= function(name
, param
)
205 local player
= minetest
.get_player_by_name(name
)
207 if(type(param
)=="string") then
208 if(type(tonumber(param
)) == "number") then
209 max = tonumber(param
)
210 if(max > 1000) then max = 1000 end
213 minetest
.debug("[playereffects] Stress test started for "..name
.." with "..max.." effects.")
215 playereffects
.apply_effect_type("stress", 10, player
)