2014-07-06 18:37:32 +02:00
|
|
|
----- EXAMPLE EFFECT TYPES -----
|
2014-07-14 17:55:48 +02:00
|
|
|
--[[ Null effect. The apply function always returns false, which means applying the
|
|
|
|
effect will never succeed ]]
|
|
|
|
playereffects.register_effect_type("null", "No effect", nil, {},
|
|
|
|
function()
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2014-07-14 17:28:51 +02:00
|
|
|
-- 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",
|
|
|
|
})
|
2014-07-14 17:55:48 +02:00
|
|
|
if(hudid ~= nil) then
|
|
|
|
return { hudid = hudid }
|
|
|
|
else
|
|
|
|
minetest.log("error", "[playereffects] [examples] The effect \"Blind\" could not be applied. The call to hud_add(...) failed.")
|
|
|
|
return false
|
|
|
|
end
|
2014-07-14 17:28:51 +02:00
|
|
|
end,
|
|
|
|
function(effect)
|
|
|
|
local player = minetest.get_player_by_name(effect.playername)
|
|
|
|
player:hud_remove(effect.metadata.hudid)
|
|
|
|
end
|
|
|
|
)
|
2014-07-06 18:37:32 +02:00
|
|
|
|
2014-07-13 21:19:02 +02:00
|
|
|
-- Makes the user faster
|
2014-07-07 09:38:55 +02:00
|
|
|
playereffects.register_effect_type("high_speed", "High speed", nil, {"speed"},
|
2014-07-06 18:37:32 +02:00
|
|
|
function(player)
|
|
|
|
player:set_physics_override(4,nil,nil)
|
|
|
|
end,
|
|
|
|
|
|
|
|
function(effect)
|
|
|
|
local player = minetest.get_player_by_name(effect.playername)
|
|
|
|
player:set_physics_override(1,nil,nil)
|
|
|
|
end
|
|
|
|
)
|
2014-07-13 21:19:02 +02:00
|
|
|
|
2014-07-13 22:07:04 +02:00
|
|
|
-- Makes the user faster (hidden effect)
|
|
|
|
playereffects.register_effect_type("high_speed_hidden", "High speed", nil, {"speed"},
|
|
|
|
function(player)
|
|
|
|
player:set_physics_override(4,nil,nil)
|
|
|
|
end,
|
|
|
|
|
|
|
|
function(effect)
|
|
|
|
local player = minetest.get_player_by_name(effect.playername)
|
|
|
|
player:set_physics_override(1,nil,nil)
|
|
|
|
end,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-13 21:19:02 +02:00
|
|
|
-- Slows the user down
|
2014-07-07 09:38:55 +02:00
|
|
|
playereffects.register_effect_type("low_speed", "Low speed", nil, {"speed"},
|
2014-07-06 18:37:32 +02:00
|
|
|
function(player)
|
|
|
|
player:set_physics_override(0.25,nil,nil)
|
|
|
|
end,
|
|
|
|
|
|
|
|
function(effect)
|
|
|
|
local player = minetest.get_player_by_name(effect.playername)
|
|
|
|
player:set_physics_override(1,nil,nil)
|
|
|
|
end
|
|
|
|
)
|
2014-07-13 21:19:02 +02:00
|
|
|
|
|
|
|
-- Increases the jump height
|
2014-07-07 09:38:55 +02:00
|
|
|
playereffects.register_effect_type("highjump", "Greater jump height", "playereffects_example_highjump.png", {"jump"},
|
2014-07-06 18:37:32 +02:00
|
|
|
function(player)
|
|
|
|
player:set_physics_override(nil,2,nil)
|
|
|
|
end,
|
|
|
|
function(effect)
|
|
|
|
local player = minetest.get_player_by_name(effect.playername)
|
|
|
|
player:set_physics_override(nil,1,nil)
|
|
|
|
end
|
|
|
|
)
|
2014-07-13 21:19:02 +02:00
|
|
|
|
|
|
|
-- Adds the “fly” privilege
|
2014-07-07 09:38:55 +02:00
|
|
|
playereffects.register_effect_type("fly", "Fly mode available", "playereffects_example_fly.png", {"fly"},
|
2014-07-06 18:37:32 +02:00
|
|
|
function(player)
|
|
|
|
local playername = player:get_player_name()
|
|
|
|
local privs = minetest.get_player_privs(playername)
|
|
|
|
privs.fly = true
|
|
|
|
minetest.set_player_privs(playername, privs)
|
|
|
|
end,
|
|
|
|
function(effect)
|
|
|
|
local privs = minetest.get_player_privs(effect.playername)
|
|
|
|
privs.fly = nil
|
|
|
|
minetest.set_player_privs(effect.playername, privs)
|
|
|
|
end
|
|
|
|
)
|
2014-07-13 21:19:02 +02:00
|
|
|
|
|
|
|
-- Dummy effect for the stree test
|
2014-07-07 10:39:21 +02:00
|
|
|
playereffects.register_effect_type("stress", "Stress Test Effect", nil, {},
|
|
|
|
function(player)
|
|
|
|
end,
|
|
|
|
function(effect)
|
|
|
|
end
|
|
|
|
)
|
2014-07-06 18:37:32 +02:00
|
|
|
|
|
|
|
|
2014-07-13 21:19:02 +02:00
|
|
|
------ Chat commands for the example effects ------
|
2014-07-14 17:55:48 +02:00
|
|
|
-- Null effect (never succeeds)
|
|
|
|
minetest.register_chatcommand("null", {
|
|
|
|
params = "",
|
|
|
|
description = "Does nothing.",
|
|
|
|
privs = {},
|
|
|
|
func = function(name, param)
|
|
|
|
playereffects.apply_effect_type("null", 5, minetest.get_player_by_name(name))
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2014-07-14 17:28:51 +02:00
|
|
|
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,
|
|
|
|
})
|
2014-07-06 18:37:32 +02:00
|
|
|
minetest.register_chatcommand("fast", {
|
|
|
|
params = "",
|
|
|
|
description = "Makes you fast for a short time.",
|
|
|
|
privs = {},
|
|
|
|
func = function(name, param)
|
|
|
|
playereffects.apply_effect_type("high_speed", 10, minetest.get_player_by_name(name))
|
|
|
|
end,
|
|
|
|
})
|
2014-07-13 22:07:04 +02:00
|
|
|
minetest.register_chatcommand("hfast", {
|
|
|
|
params = "",
|
|
|
|
description = "Makes you fast for a short time (hidden effect).",
|
|
|
|
privs = {},
|
|
|
|
func = function(name, param)
|
|
|
|
playereffects.apply_effect_type("high_speed_hidden", 10, minetest.get_player_by_name(name))
|
|
|
|
end,
|
|
|
|
})
|
2014-07-06 18:37:32 +02:00
|
|
|
minetest.register_chatcommand("slow", {
|
|
|
|
params = "",
|
|
|
|
description = "Makes you slow for a long time.",
|
|
|
|
privs = {},
|
|
|
|
func = function(name, param)
|
|
|
|
playereffects.apply_effect_type("low_speed", 120, minetest.get_player_by_name(name))
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
minetest.register_chatcommand("highjump", {
|
|
|
|
params = "",
|
|
|
|
description = "Makes you jump higher for a short time.",
|
|
|
|
privs = {},
|
|
|
|
func = function(name, param)
|
|
|
|
playereffects.apply_effect_type("highjump", 20, minetest.get_player_by_name(name))
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("fly", {
|
|
|
|
params = "",
|
|
|
|
description = "Grants you the fly privilege for a short time.",
|
|
|
|
privs = {},
|
|
|
|
func = function(name, param)
|
|
|
|
playereffects.apply_effect_type("fly", 20, minetest.get_player_by_name(name))
|
|
|
|
end,
|
|
|
|
})
|
2014-07-13 21:19:02 +02:00
|
|
|
|
|
|
|
--[[ The stress test applies a shitload of effects at once.
|
|
|
|
This is used to test the performance of this mod at very large effect numbers. ]]
|
2014-07-07 10:39:21 +02:00
|
|
|
minetest.register_chatcommand("stresstest", {
|
|
|
|
params = "[<effects>]",
|
|
|
|
descriptions = "Start the stress test for Player Effects with <effects> effects.",
|
|
|
|
privs = {server=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
local max = 100
|
|
|
|
if(type(param)=="string") then
|
|
|
|
if(type(tonumber(param)) == "number") then
|
|
|
|
max = tonumber(param)
|
|
|
|
if(max > 1000) then max = 1000 end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.debug("[playereffects] Stress test started for "..name.." with "..max.." effects.")
|
|
|
|
for i=1,max do
|
|
|
|
playereffects.apply_effect_type("stress", 10, player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|