1 ----- EXAMPLE EFFECT TYPES -----
2 --[[ Null effect. The apply function always returns false, which means applying the
3 effect will never succeed ]]
4 playereffects
.register_effect_type("null", "No effect", nil, {},
11 -- Makes the player screen black for 5 seconds (very experimental!)
12 playereffects
.register_effect_type("blind", "Blind", nil, {},
14 local hudid
= player
:hud_add({
15 hud_elem_type
= "image",
16 position
= { x
=0.5, y
=0.5 },
17 scale
= { x
=-100, y
=-100 },
18 text
= "playereffects_example_black.png",
21 return { hudid
= hudid
}
23 minetest
.log("error", "[playereffects] [examples] The effect \"Blind\" could not be applied. The call to hud_add(...) failed.")
28 local player
= minetest
.get_player_by_name(effect
.playername
)
29 player
:hud_remove(effect
.metadata
.hudid
)
33 -- Makes the user faster
34 playereffects
.register_effect_type("high_speed", "High speed", nil, {"speed"},
36 player
:set_physics_override(4,nil,nil)
40 local player
= minetest
.get_player_by_name(effect
.playername
)
41 player
:set_physics_override(1,nil,nil)
45 -- Makes the user faster (hidden effect)
46 playereffects
.register_effect_type("high_speed_hidden", "High speed", nil, {"speed"},
48 player
:set_physics_override(4,nil,nil)
52 local player
= minetest
.get_player_by_name(effect
.playername
)
53 player
:set_physics_override(1,nil,nil)
60 -- Slows the user down
61 playereffects
.register_effect_type("low_speed", "Low speed", nil, {"speed"},
63 player
:set_physics_override(0.25,nil,nil)
67 local player
= minetest
.get_player_by_name(effect
.playername
)
68 player
:set_physics_override(1,nil,nil)
72 -- Increases the jump height
73 playereffects
.register_effect_type("highjump", "Greater jump height", "playereffects_example_highjump.png", {"jump"},
75 player
:set_physics_override(nil,2,nil)
78 local player
= minetest
.get_player_by_name(effect
.playername
)
79 player
:set_physics_override(nil,1,nil)
83 -- Adds the “fly” privilege
84 playereffects
.register_effect_type("fly", "Fly mode available", "playereffects_example_fly.png", {"fly"},
86 local playername
= player
:get_player_name()
87 local privs
= minetest
.get_player_privs(playername
)
89 minetest
.set_player_privs(playername
, privs
)
92 local privs
= minetest
.get_player_privs(effect
.playername
)
94 minetest
.set_player_privs(effect
.playername
, privs
)
98 -- Dummy effect for the stree test
99 playereffects
.register_effect_type("stress", "Stress Test Effect", nil, {},
107 ------ Chat commands for the example effects ------
108 -- Null effect (never succeeds)
109 minetest
.register_chatcommand("null", {
111 description
= "Does nothing.",
113 func
= function(name
, param
)
114 playereffects
.apply_effect_type("null", 5, minetest
.get_player_by_name(name
))
118 minetest
.register_chatcommand("blind", {
120 description
= "Makes your screen black for a short time.",
122 func
= function(name
, param
)
123 playereffects
.apply_effect_type("blind", 5, minetest
.get_player_by_name(name
))
126 minetest
.register_chatcommand("fast", {
128 description
= "Makes you fast for a short time.",
130 func
= function(name
, param
)
131 playereffects
.apply_effect_type("high_speed", 10, minetest
.get_player_by_name(name
))
134 minetest
.register_chatcommand("hfast", {
136 description
= "Makes you fast for a short time (hidden effect).",
138 func
= function(name
, param
)
139 playereffects
.apply_effect_type("high_speed_hidden", 10, minetest
.get_player_by_name(name
))
142 minetest
.register_chatcommand("slow", {
144 description
= "Makes you slow for a long time.",
146 func
= function(name
, param
)
147 playereffects
.apply_effect_type("low_speed", 120, minetest
.get_player_by_name(name
))
150 minetest
.register_chatcommand("highjump", {
152 description
= "Makes you jump higher for a short time.",
154 func
= function(name
, param
)
155 playereffects
.apply_effect_type("highjump", 20, minetest
.get_player_by_name(name
))
159 minetest
.register_chatcommand("fly", {
161 description
= "Grants you the fly privilege for a short time.",
163 func
= function(name
, param
)
164 playereffects
.apply_effect_type("fly", 20, minetest
.get_player_by_name(name
))
168 --[[ The stress test applies a shitload of effects at once.
169 This is used to test the performance of this mod at very large effect numbers. ]]
170 minetest
.register_chatcommand("stresstest", {
171 params
= "[<effects>]",
172 descriptions
= "Start the stress test for Player Effects with <effects> effects.",
173 privs
= {server
=true},
174 func
= function(name
, param
)
175 local player
= minetest
.get_player_by_name(name
)
177 if(type(param
)=="string") then
178 if(type(tonumber(param
)) == "number") then
179 max = tonumber(param
)
180 if(max > 1000) then max = 1000 end
183 minetest
.debug("[playereffects] Stress test started for "..name
.." with "..max.." effects.")
185 playereffects
.apply_effect_type("stress", 10, player
)