Add setting use_hud, used to control player HUDs
[minetest_playereffects.git] / examples.lua
blob8f0ff67e20762be9587e6e8a138aabd777cd4f06
1 ----- EXAMPLE EFFECT TYPES -----
3 -- Makes the user faster
4 playereffects.register_effect_type("high_speed", "High speed", nil, {"speed"},
5 function(player)
6 player:set_physics_override(4,nil,nil)
7 end,
9 function(effect)
10 local player = minetest.get_player_by_name(effect.playername)
11 player:set_physics_override(1,nil,nil)
12 end
15 -- Slows the user down
16 playereffects.register_effect_type("low_speed", "Low speed", nil, {"speed"},
17 function(player)
18 player:set_physics_override(0.25,nil,nil)
19 end,
21 function(effect)
22 local player = minetest.get_player_by_name(effect.playername)
23 player:set_physics_override(1,nil,nil)
24 end
27 -- Increases the jump height
28 playereffects.register_effect_type("highjump", "Greater jump height", "playereffects_example_highjump.png", {"jump"},
29 function(player)
30 player:set_physics_override(nil,2,nil)
31 end,
32 function(effect)
33 local player = minetest.get_player_by_name(effect.playername)
34 player:set_physics_override(nil,1,nil)
35 end
38 -- Adds the “fly” privilege
39 playereffects.register_effect_type("fly", "Fly mode available", "playereffects_example_fly.png", {"fly"},
40 function(player)
41 local playername = player:get_player_name()
42 local privs = minetest.get_player_privs(playername)
43 privs.fly = true
44 minetest.set_player_privs(playername, privs)
45 end,
46 function(effect)
47 local privs = minetest.get_player_privs(effect.playername)
48 privs.fly = nil
49 minetest.set_player_privs(effect.playername, privs)
50 end
53 -- Dummy effect for the stree test
54 playereffects.register_effect_type("stress", "Stress Test Effect", nil, {},
55 function(player)
56 end,
57 function(effect)
58 end
62 ------ Chat commands for the example effects ------
64 minetest.register_chatcommand("fast", {
65 params = "",
66 description = "Makes you fast for a short time.",
67 privs = {},
68 func = function(name, param)
69 playereffects.apply_effect_type("high_speed", 10, minetest.get_player_by_name(name))
70 end,
72 minetest.register_chatcommand("slow", {
73 params = "",
74 description = "Makes you slow for a long time.",
75 privs = {},
76 func = function(name, param)
77 playereffects.apply_effect_type("low_speed", 120, minetest.get_player_by_name(name))
78 end,
80 minetest.register_chatcommand("highjump", {
81 params = "",
82 description = "Makes you jump higher for a short time.",
83 privs = {},
84 func = function(name, param)
85 playereffects.apply_effect_type("highjump", 20, minetest.get_player_by_name(name))
86 end,
89 minetest.register_chatcommand("fly", {
90 params = "",
91 description = "Grants you the fly privilege for a short time.",
92 privs = {},
93 func = function(name, param)
94 playereffects.apply_effect_type("fly", 20, minetest.get_player_by_name(name))
95 end,
98 --[[ The stress test applies a shitload of effects at once.
99 This is used to test the performance of this mod at very large effect numbers. ]]
100 minetest.register_chatcommand("stresstest", {
101 params = "[<effects>]",
102 descriptions = "Start the stress test for Player Effects with <effects> effects.",
103 privs = {server=true},
104 func = function(name, param)
105 local player = minetest.get_player_by_name(name)
106 local max = 100
107 if(type(param)=="string") then
108 if(type(tonumber(param)) == "number") then
109 max = tonumber(param)
110 if(max > 1000) then max = 1000 end
113 minetest.debug("[playereffects] Stress test started for "..name.." with "..max.." effects.")
114 for i=1,max do
115 playereffects.apply_effect_type("stress", 10, player)