forked from ThomasMonroe314/ugxrealms
add playereffects and server_essentials mods
This commit is contained in:
parent
b46b12cb8b
commit
02b05fa7ba
@ -108,4 +108,4 @@ minetest.register_on_joinplayer(function(player)
|
||||
end
|
||||
end, player)
|
||||
end)
|
||||
]]--
|
||||
--]]
|
228
worldmods/playereffects/README.md
Normal file
228
worldmods/playereffects/README.md
Normal file
@ -0,0 +1,228 @@
|
||||
# Player Effects
|
||||
## Summary
|
||||
This is an framework for assigning temporary status effects to players. This mod is aimed to modders and maybe interested people. This framework is a work in progress and not finished.
|
||||
|
||||
## Profile
|
||||
* Name: Player Effects
|
||||
* Short name: `playereffects`
|
||||
* Current version: 1.2.0 (This is a [SemVer](http://semver.org/).)
|
||||
* Dependencies: None!
|
||||
* License of everything: MIT License
|
||||
* Discussion page: [here](https://forum.minetest.net/viewtopic.php?f=11&t=9689)
|
||||
|
||||
## Information for players
|
||||
This mod alone is not aimed directly at players. Briefly, the point of this mod is to help other mods to implement temporary status effects for players in a clean and consistant way.
|
||||
Here is the information which may be relevant to you: Your current status effects are shown on the HUD on the right side, along with a timer which shows the time until the effect gets disabled. It is possible for the server to disable this feature entirely. Some status effects may also be hidden and are never exposed to the HUD.
|
||||
|
||||
You only have to install this mod iff you have a mod which implements Player Effects. Here is a list of known mods which do:
|
||||
|
||||
* Magic Beans—Wuzzy’s Fork [`magicbeans_w`]
|
||||
|
||||
## Information for server operators
|
||||
By default, this mod stores the effects into the file `playereffects.mt` in the current world path every 10 seconds. On a regular server shutdown, this file is also written to. The data in this file is read when the mod is started.
|
||||
|
||||
It is save to delete `playereffects.mt` when the mod does currently not run. This simply erases all active and inactive effects when the server starts again.
|
||||
|
||||
You can disable the automatic saving in `settings.lua`.
|
||||
|
||||
### Configuration
|
||||
Player Effects can be configured. Just edit the file `settings.lua`. You find everything you need to know in that file. Be careful to not delete the lines, just edit them.
|
||||
|
||||
## Information for modders
|
||||
This is a framework for other mods to depend on. It provides means to define, apply and remove temporary status effects to players in a (hopefully) unobstrusive way.
|
||||
A status effect is an effect for a player which changes some property of the player. This property can be practically everything. Currently, the framework supports one kind of effect, which I call “exclusive effects”. For each property (speed, gravity, whatver), there can be only one effect in place at the same time. Here are some examples for possible status effects:
|
||||
|
||||
* high walking speed (`speed` property)
|
||||
* high jump height (`jump` property)
|
||||
* low player gravity (`gravity` property)
|
||||
* high player gravity (`gravity` property)
|
||||
* having the X privilege granted (binary “do I have the property?” property) (yes, this is weird, but it works!)
|
||||
|
||||
The framework aims to provide means to define effect types and to apply and cancel effects to players. The framework aims to be a stable foundation stone. This means it needs a lot of testing.
|
||||
|
||||
## Known bugs
|
||||
### Effect timers don’t stop when game gets paused
|
||||
When you paused the game in singleplayer mode, the effect timers just continue as if nothing happened. Of course, all effect timers should be stopped while the game is paused, like everything else. Apparently this bug cannot be fixed with the current Lua API.
|
||||
|
||||
## API documentation
|
||||
### Data types
|
||||
#### Effect type (`effect_type`)
|
||||
An effect type is a description of what is later to be concretely applied as an effect to a player. An effect type, however, is *not* assigned to a player. There are two kinds of effect types: Repeating and non-repeating. See the section on `effect` for more information.
|
||||
|
||||
`effect_type` is a table with these fields:
|
||||
|
||||
* `description`: Human-readable short description of the effect. Will be exposed to the HUD, iff `hidden` is `false`.
|
||||
* `groups`: A table of groups to which this effect type belongs to.
|
||||
* `apply`: Function to be called when effect is applied. See `playereffects.register_effect_type`.
|
||||
* `cancel`: Function to be called when effect is cancelled. See `playereffects.register_effect_type`.
|
||||
* `icon`: This is optional. It can be the file name of a texture. Should have a size of 16px×16px. Will be exposed to the HUD, iff `hidden` is `false`.
|
||||
* `hidden`: Iff this is false, it will not be exposed to the HUD when this effect is active.
|
||||
* `cancel_on_death`: Iff this is true, the effect will be cancelled automatically when the player dies.
|
||||
* `repeat_interval` is an optional number. When specified, the effects of this type becomes a repeating effect. Repeating effects call `apply` an arbitrary number of times; non-repeating effects just call it once when the effect is created. The number specifies the interval in seconds between each call. Iff this parameter is `nil`, the effect type is a non-repeating effect.
|
||||
|
||||
Normally you don’t need to read or edit fields of this table. Use `playereffects.register_effect_type` to add a new effect type to Player Effects.
|
||||
|
||||
#### Effect group
|
||||
An effect group is basically a concept. Any effect type can be member of any number of effect groups. The main point of effect groups is to find effects which affect the same property. For example, an effect which makes you faster and another effect which makes you slower both affect the same property: speed. The group for that then would be the string `"speed"`. See also `examples.lua`, which includes the effects `high_speed` and `low_speed`.
|
||||
|
||||
Currently, the main rule of Player Effects requires that there can only be one effect in place. Don’t worry, Player Effects already does that job for you. Back to the example: it is possible to be fast and it is possible to be slow. But it is not possible to be fast `and` slow at the same time. Player Effects ensures that by cancelling all conflicting concepts before applying a new one.
|
||||
|
||||
The concept of groups may be changed or extended in the future.
|
||||
|
||||
You can invent effect groups (like the groups in Minetest) on the fly. A group is just a string. Practically, you should use groups which other people use.
|
||||
|
||||
#### Effect (`effect`)
|
||||
An effect is an current change of a player property (like speed, jump height, and so on). It is the realization of an effect type. All effects are temporary. There are currently two types of effects: Repeating and non-repeating. Non-repeating effects call their `apply` callback once when they are created. Repeating effects call their apply callback multiple times with a specified interval. By default, effects are non-repeating.
|
||||
|
||||
`effect` is a table with the following modding-relevant fields:
|
||||
|
||||
* `playername`: The name of the player to which the effect belongs to.
|
||||
* `effect_id`: A globally unique identifier of the effect. It is a number and assigned automatically by Player Effects.
|
||||
* `effect_type_id`: The identifier of the effect’s effect type. It is a string and assigned by `playereffects.register_effect_type`.
|
||||
* `metadata`: An optional field which may contain a table with additional, modder-defined data to be “remembered” for later. The `apply` callback can set this field.
|
||||
|
||||
Internally, Player Effects also uses these fields:
|
||||
|
||||
* `start_time`: The operating system time (from `os.time()`) of when the effect has been started.
|
||||
* `time_left`: The number of seconds left before the effect runs out. This number is only set when the effect starts or the effect is unfrozen because i.e. a player re-joins. You can’t use this field to blindly get the remaining time of the effect.
|
||||
* `repeat_interval_start_time` and `repeat_interval_time_left`: Same as `start_time` and `time_left`, but for repeating effects.
|
||||
|
||||
You should normally not need to care about these internally used fields.
|
||||
|
||||
|
||||
### Functions
|
||||
#### `playereffects.register_effect_type(effect_type_id, description, icon, groups, apply, cancel, hidden, cancel_on_death, repeat_interval)`
|
||||
Adds a new effect type for the Player Effects mods, so it can be later be applied to players.
|
||||
|
||||
##### Parameters
|
||||
* `effect_type_id` is the identifier (a string) which is internally used by the mod. Later known as `effect_type_id`. You may choose the identifier at will, but please use only alphanumeric ASCII characters. The identifier must be unique along all mods.
|
||||
* `description` is the text which is exposed to the HUD and visible to the player.
|
||||
* `icon`: This is optional an can be `nil`. It can be the file name of a texture. Should have a size of 16px×16px. In this case, this is the icon for the HUD. Basically this is just eye-candy. If this is `nil`, no icon is shown. The icon will be exposed to the HUD, iff `hidden` is `false`.
|
||||
* `groups` is a table of strings to which the effect type is assigned to.
|
||||
* `apply`: See below.
|
||||
* `cancel`: See below.
|
||||
* `hidden` is an optional boolean value. Iff `true`, the effect description and icon will not be exposed to the player HUD. Otherwise, the effect is exposed. Default: `false`
|
||||
* `cancel_on_death` is an optional boolean value. Iff true, the effect will be cancelled automatically when the player dies. Default: `true`.
|
||||
* `repeat_interval` is an optional number. When specified, the effects of this type becomes a repeating effect. Repeating effects call `apply` an arbitrary number of times; non-repeating effects just call it once when the effect is created. The number specifies the interval in seconds between each call. Iff this parameter is `nil`, the effect type is a non-repeating effect.
|
||||
|
||||
|
||||
###### `apply` function
|
||||
The `apply` function is a callback function which is called by Player Effects. Here the modder can put all the gameplay-relevant code.
|
||||
|
||||
`apply` takes a player object as its only argument. This is the player to which the effect is applied to.
|
||||
|
||||
The function may return a table. This table will be added as the field `metadata` to the resulting `effect`.
|
||||
|
||||
The function may return `false`. This is used to tell Player Effects that the effect could, for whatever reason, not be successfully applied. Currently, this feature is experimental and possibly broken.
|
||||
|
||||
The function may also return just `nil` on a normal success without metadata.
|
||||
|
||||
###### `cancel` function
|
||||
The `cancel` function is called by Player Effects when the effect is to be cancelled. Here the modder can do all the code which is needed to revert the changes an earlier `apply` call made.
|
||||
|
||||
`cancel` takes an `effect` as its first argument and a player object as its second argument. Remember, this `effect` may also contain a field called `metadata`, which may have been added by an earlier `apply` call. `player` is the player to which the effect is/was applied. This argument is just there for convenience reasons.
|
||||
|
||||
Player Effects does not care about the return value of this function.
|
||||
|
||||
##### Return value
|
||||
Always `nil`.
|
||||
|
||||
#### `playereffects.apply_effect_type(effect_type_id, duration, player, repeat_interval_time_left)`
|
||||
Attempts to apply a new effect of a certain type for a certain duration to a certain player. This function can fail, although this should rarely happen. This function handles non-repeating effects and repeating effects as well.
|
||||
|
||||
##### Parameters
|
||||
* `effect_type_id`: The identifier of the effect type. This is the name which was used in `playereffects.register_effect_type` and always a string.
|
||||
* `duration`: How long the effect. Please use only positive values and only integers. If a repeating effect type is specified, this number specifies the number of repetitions; for non-repeating effects this number specifies the effect duration in seconds.
|
||||
* `player`: The player object to which the new effect should be applied to.
|
||||
* `repeat_interval_time_left`: This parameter is optional and only for repeating effects. If it is a number, it specifies the time until the first call of the `apply` callback fires. By default, a full repeat interval is waited until the first call.
|
||||
|
||||
##### Return value
|
||||
The function either returns `false` or a number. Iff the function returns `false`, the effect was not successfully applied. The function may return `false` on these occasions:
|
||||
|
||||
* `player` is not a valid player object
|
||||
* The `apply` function of the effect type returned `false`
|
||||
|
||||
On success, the function returns a number. This number is the effect ID of the effect which has been just created. This effect ID can be used later, for `playereffects.cancel_effect`, for example.
|
||||
|
||||
#### `playereffects.cancel_effect(effect_id)`
|
||||
Cancels a single effect.
|
||||
|
||||
##### Parameter
|
||||
* `effect_id`: The effect ID of the effect which shall be cancelled.
|
||||
|
||||
##### Return value
|
||||
Always `nil`.
|
||||
|
||||
#### `playereffects.cancel_effect_group(groupname, playername)`
|
||||
Cancels all a player’s effects which belong to a certain group.
|
||||
|
||||
##### Parameters
|
||||
* `groupname`: The name of the effect group (string) of which all active effects of the player shall be cancelled.
|
||||
* `playername`: The name of the player to which the effects which are about to be cancelled belong to.
|
||||
|
||||
##### Return value
|
||||
Always `nil`.
|
||||
|
||||
#### `playereffects.cancel_effect_type(effect_type_id, cancel_all, playername)`
|
||||
Cancels one or all player effect with a certain effect type
|
||||
Careful! This function has *not* been tested yet!
|
||||
|
||||
##### Parameters
|
||||
* `effect_type_id`: Identifier of the effect type.
|
||||
* `cancel_all`: Iff true, cancels all active effects with this effect type
|
||||
* `playername`: Name of the player to which the effects belong to
|
||||
|
||||
##### Return value
|
||||
Always `nil`.
|
||||
|
||||
#### `playereffects.get_remaining_effect_time(effect_id)`
|
||||
Returns the remaining time of an effect.
|
||||
|
||||
##### Parameter
|
||||
* `effect_id`: The effect identifier of the effect in question
|
||||
|
||||
##### Return value
|
||||
Iff the effect exists, the remaining effect time is returned in full seconds. Iff the effect does not exist, `nil` is returned.
|
||||
|
||||
#### `playereffects.get_player_effects(playername)`
|
||||
Returns all active effects of a player.
|
||||
|
||||
##### Parameter
|
||||
`playername`: The name of the player from which the effects are requested.
|
||||
|
||||
##### Return value
|
||||
A table of all `effect`s which belong to the player. If the player does not exist, this function returns an empty table.
|
||||
|
||||
#### `playereffects.has_effect_type(playername, effect_type_id)`
|
||||
Returns `true` iff the provided player has an effect of the specified effect type, `false` otherwise.
|
||||
|
||||
##### Parameters
|
||||
* `playername`: Name of the player to check the existance of the effect type for
|
||||
* `effect_type_id`: Identifier of the effect type.
|
||||
|
||||
## Examples
|
||||
This mod comes with extensive examples. The examples are disabled by default. Edit `settings.lua` to enable the examples. See `examples.lua` to find out how they are programmed. The examples are only for demonstration purposes. They are not intended to be used in an actual game.
|
||||
|
||||
### Chat commands
|
||||
The examples are mainly accessible with chat commands. Since this is just an example, everyone can use these examples.
|
||||
|
||||
#### Apply effect
|
||||
These commands apply (or try to) apply an effect to you. You will get a response in the chat which give you the `effect_id` on success. On failure, the example will tell you that it failed.
|
||||
|
||||
* `fast`: Makes you faster for 10 seconds.
|
||||
* `slow`: Makes you slower for 120s.
|
||||
* `hfast`: Makes you faster for 10s. This is a hidden effect and is not exposed to the HUD.
|
||||
* `highjump`: Increases your jump height for 20s.
|
||||
* `fly`: Gives you the `fly` privilege for a minute. You keep the privilege even when you die. Better don’t mess around with this privilege manually when you use this.
|
||||
* `regen`: Gives you a half heart per second 10 times (5 hearts overall healing). This is an example of a repeating effect.
|
||||
* `slowregen`: Gives you a half heart every 15 seconds, 10 times (5 hearts overall healing). This is an example of a repeating effect.
|
||||
* `blind`: Tints the whole screen black for 5 seconds. This is highly experimental and will be drawn over many existing HUD elements. In other words, prepare your HUD to be messed up.
|
||||
* `null`: Tries to apply an effect which always fails. This demonstrates the failure of effects.
|
||||
|
||||
#### Cancel effects
|
||||
* `cancelall`: Cancels all your active effects.
|
||||
|
||||
#### Testing
|
||||
* `stresstest [number]`: Applies `number` dummy effects which don’t do anything to you. Iff omitted, `number` is assumed to be 100. This command is there to test the performance of this mod for absurdly large effect numbers.
|
||||
|
||||
|
0
worldmods/playereffects/depends.txt
Normal file
0
worldmods/playereffects/depends.txt
Normal file
1
worldmods/playereffects/description.txt
Normal file
1
worldmods/playereffects/description.txt
Normal file
@ -0,0 +1 @@
|
||||
Framework for temporary effects for players.
|
260
worldmods/playereffects/examples.lua
Normal file
260
worldmods/playereffects/examples.lua
Normal file
@ -0,0 +1,260 @@
|
||||
----- EXAMPLE EFFECT TYPES -----
|
||||
--[[ This is just a helper function to inform the user of the chat command
|
||||
of the result and, if successful, shows the effect ID. ]]
|
||||
local function notify(name, retcode)
|
||||
if(retcode == false) then
|
||||
minetest.chat_send_player(name, "Effect application failed. Effect was NOT applied.")
|
||||
else
|
||||
minetest.chat_send_player(name, "Effect applied. Effect ID: "..tostring(retcode))
|
||||
end
|
||||
end
|
||||
|
||||
--[[ 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
|
||||
)
|
||||
|
||||
|
||||
-- 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",
|
||||
})
|
||||
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
|
||||
end,
|
||||
function(effect, player)
|
||||
player:hud_remove(effect.metadata.hudid)
|
||||
end
|
||||
)
|
||||
|
||||
-- Makes the user faster
|
||||
playereffects.register_effect_type("high_speed", "High speed", nil, {"speed"},
|
||||
function(player)
|
||||
player:set_physics_override(4,nil,nil)
|
||||
end,
|
||||
|
||||
function(effect, player)
|
||||
player:set_physics_override(1,nil,nil)
|
||||
end
|
||||
)
|
||||
|
||||
-- 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, player)
|
||||
player:set_physics_override(1,nil,nil)
|
||||
end,
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
|
||||
-- Slows the user down
|
||||
playereffects.register_effect_type("low_speed", "Low speed", nil, {"speed"},
|
||||
function(player)
|
||||
player:set_physics_override(0.25,nil,nil)
|
||||
end,
|
||||
|
||||
function(effect, player)
|
||||
player:set_physics_override(1,nil,nil)
|
||||
end
|
||||
)
|
||||
|
||||
-- Increases the jump height
|
||||
playereffects.register_effect_type("highjump", "Greater jump height", "playereffects_example_highjump.png", {"jump"},
|
||||
function(player)
|
||||
player:set_physics_override(nil,2,nil)
|
||||
end,
|
||||
function(effect, player)
|
||||
player:set_physics_override(nil,1,nil)
|
||||
end
|
||||
)
|
||||
|
||||
-- Adds the “fly” privilege. Keep the privilege even if the player dies
|
||||
playereffects.register_effect_type("fly", "Fly mode available", "playereffects_example_fly.png", {"fly"},
|
||||
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, player)
|
||||
local privs = minetest.get_player_privs(effect.playername)
|
||||
privs.fly = nil
|
||||
minetest.set_player_privs(effect.playername, privs)
|
||||
end,
|
||||
false, -- not hidden
|
||||
false -- do NOT cancel the effect on death
|
||||
)
|
||||
|
||||
-- Repeating effect type: Adds 1 HP per second
|
||||
playereffects.register_effect_type("regen", "Regeneration", "heart.png", {"health"},
|
||||
function(player)
|
||||
player:set_hp(player:get_hp()+1)
|
||||
end,
|
||||
nil, nil, nil, 1
|
||||
)
|
||||
|
||||
-- Repeating effect type: Adds 1 HP per 3 seconds
|
||||
playereffects.register_effect_type("slowregen", "Slow Regeneration", "heart.png", {"health"},
|
||||
function(player)
|
||||
player:set_hp(player:get_hp()+1)
|
||||
end,
|
||||
nil, nil, nil, 15
|
||||
)
|
||||
|
||||
|
||||
-- Dummy effect for the stree test
|
||||
playereffects.register_effect_type("stress", "Stress Test Effect", nil, {},
|
||||
function(player)
|
||||
end,
|
||||
function(effect, player)
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
|
||||
------ Chat commands for the example effects ------
|
||||
-- Null effect (never succeeds)
|
||||
minetest.register_chatcommand("null", {
|
||||
params = "",
|
||||
description = "Does nothing.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("null", 5, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("blind", {
|
||||
params = "",
|
||||
description = "Makes your screen black for a short time.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("blind", 5, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("fast", {
|
||||
params = "",
|
||||
description = "Makes you fast for a short time.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("high_speed", 10, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("hfast", {
|
||||
params = "",
|
||||
description = "Makes you fast for a short time (hidden effect).",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("high_speed_hidden", 10, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("slow", {
|
||||
params = "",
|
||||
description = "Makes you slow for a long time.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("low_speed", 120, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
minetest.register_chatcommand("highjump", {
|
||||
params = "",
|
||||
description = "Makes you jump higher for a short time.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("highjump", 20, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("fly", {
|
||||
params = "",
|
||||
description = "Grants you the fly privilege for a minute. You keep the effect when you die.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("fly", 60, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("regen", {
|
||||
params = "",
|
||||
description = "Gives you 1 half heart per second 10 times, healing you by 5 hearts in total.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("regen", 10, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("slowregen", {
|
||||
params = "",
|
||||
description = "Gives you 1 half heart every 3 seconds 10 times, healing you by 5 hearts in total.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local ret = playereffects.apply_effect_type("slowregen", 10, minetest.get_player_by_name(name))
|
||||
notify(name, ret)
|
||||
end,
|
||||
})
|
||||
|
||||
--[[
|
||||
Cancel all active effects
|
||||
]]
|
||||
minetest.register_chatcommand("cancelall", {
|
||||
params = "",
|
||||
description = "Cancels all your effects.",
|
||||
privs = {},
|
||||
func = function(name, param)
|
||||
local effects = playereffects.get_player_effects(name)
|
||||
for e=1, #effects do
|
||||
playereffects.cancel_effect(effects[e].effect_id)
|
||||
end
|
||||
minetest.chat_send_player(name, "All effects cancelled.")
|
||||
end,
|
||||
})
|
||||
|
||||
--[[ 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. ]]
|
||||
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)
|
||||
end
|
||||
end
|
||||
minetest.debug("[playereffects] Stress test started for "..name.." with "..max.." effects.")
|
||||
for i=1,max do
|
||||
playereffects.apply_effect_type("stress", math.random(6,60), player)
|
||||
if(i%100==0) then
|
||||
minetest.debug("[playereffects] Effect "..i.." of "..max.." applied.")
|
||||
minetest.chat_send_player(name, "[playereffects] Effect "..i.." of "..max.." applied.")
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
533
worldmods/playereffects/init.lua
Normal file
533
worldmods/playereffects/init.lua
Normal file
@ -0,0 +1,533 @@
|
||||
--[=[ Main tables ]=]
|
||||
|
||||
playereffects = {}
|
||||
|
||||
--[[ table containing the groups (experimental) ]]
|
||||
playereffects.groups = {}
|
||||
|
||||
--[[ table containing all the HUD info tables, indexed by player names.
|
||||
A single HUD info table is formatted like this: { text_id = 1, icon_id=2, pos = 0 }
|
||||
Where: text_id: HUD ID of the textual effect description
|
||||
icon_id: HUD ID of the effect icon (optional)
|
||||
pos: Y offset factor (starts with 0)
|
||||
Example of full table:
|
||||
{ ["player1"] = {{ text_id = 1, icon_id=4, pos = 0 }}, ["player2] = { { text_id = 5, icon_id=6, pos = 0 }, { text_id = 7, icon_id=8, pos = 1 } } }
|
||||
]]
|
||||
playereffects.hudinfos = {}
|
||||
|
||||
--[[ table containing all the effect types ]]
|
||||
playereffects.effect_types = {}
|
||||
|
||||
--[[ table containing all the active effects ]]
|
||||
playereffects.effects = {}
|
||||
|
||||
--[[ table containing all the inactive effects.
|
||||
Effects become inactive if a player leaves an become active again if they join again. ]]
|
||||
playereffects.inactive_effects = {}
|
||||
|
||||
-- Variable for counting the effect_id
|
||||
playereffects.last_effect_id = 0
|
||||
|
||||
--[=[ Include settings ]=]
|
||||
dofile(minetest.get_modpath("playereffects").."/settings.lua")
|
||||
|
||||
-- defaults
|
||||
if(playereffects.use_hud == nil) then
|
||||
playereffects.use_hud = true
|
||||
end
|
||||
if(playereffects.use_autosave == nil) then
|
||||
playereffects.use_autosave = true
|
||||
end
|
||||
if(playereffects.autosave_time == nil) then
|
||||
playereffects.autosave_time = 10
|
||||
end
|
||||
if(playereffects.use_examples == nil) then
|
||||
playereffects.use_examples = false
|
||||
end
|
||||
|
||||
--[=[ Load inactive_effects and last_effect_id from playereffects.mt, if this file exists ]=]
|
||||
do
|
||||
local filepath = minetest.get_worldpath().."/playereffects.mt"
|
||||
local file = io.open(filepath, "r")
|
||||
if file then
|
||||
minetest.log("action", "[playereffects] playereffects.mt opened.")
|
||||
local string = file:read()
|
||||
io.close(file)
|
||||
if(string ~= nil) then
|
||||
local savetable = minetest.deserialize(string)
|
||||
playereffects.inactive_effects = savetable.inactive_effects
|
||||
minetest.debug("[playereffects] playereffects.mt successfully read.")
|
||||
minetest.debug("[playereffects] inactive_effects = "..dump(playereffects.inactive_effects))
|
||||
playereffects.last_effect_id = savetable.last_effect_id
|
||||
minetest.debug("[playereffects] last_effect_id = "..dump(playereffects.last_effect_id))
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.next_effect_id()
|
||||
playereffects.last_effect_id = playereffects.last_effect_id + 1
|
||||
return playereffects.last_effect_id
|
||||
end
|
||||
|
||||
--[=[ API functions ]=]
|
||||
function playereffects.register_effect_type(effect_type_id, description, icon, groups, apply, cancel, hidden, cancel_on_death, repeat_interval)
|
||||
local effect_type = {}
|
||||
effect_type.description = description
|
||||
effect_type.apply = apply
|
||||
effect_type.groups = groups
|
||||
effect_type.icon = icon
|
||||
if cancel ~= nil then
|
||||
effect_type.cancel = cancel
|
||||
else
|
||||
effect_type.cancel = function() end
|
||||
end
|
||||
if hidden ~= nil then
|
||||
effect_type.hidden = hidden
|
||||
else
|
||||
effect_type.hidden = false
|
||||
end
|
||||
if cancel_on_death ~= nil then
|
||||
effect_type.cancel_on_death = cancel_on_death
|
||||
else
|
||||
effect_type.cancel_on_death = true
|
||||
end
|
||||
effect_type.repeat_interval = repeat_interval
|
||||
|
||||
playereffects.effect_types[effect_type_id] = effect_type
|
||||
minetest.log("action", "[playereffects] Effect type "..effect_type_id.." registered!")
|
||||
end
|
||||
|
||||
function playereffects.apply_effect_type(effect_type_id, duration, player, repeat_interval_time_left)
|
||||
local start_time = os.time()
|
||||
local is_player = false
|
||||
if(type(player)=="userdata") then
|
||||
if(player.is_player ~= nil) then
|
||||
if(player:is_player() == true) then
|
||||
is_player = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if(is_player == false) then
|
||||
minetest.log("error", "[playereffects] Attempted to apply effect type "..effect_type_id.." to a non-player!")
|
||||
return false
|
||||
end
|
||||
|
||||
local playername = player:get_player_name()
|
||||
local groups = playereffects.effect_types[effect_type_id].groups
|
||||
for k,v in pairs(groups) do
|
||||
playereffects.cancel_effect_group(v, playername)
|
||||
end
|
||||
|
||||
local metadata
|
||||
if(playereffects.effect_types[effect_type_id].repeat_interval == nil) then
|
||||
local status = playereffects.effect_types[effect_type_id].apply(player)
|
||||
if(status == false) then
|
||||
minetest.log("action", "[playereffects] Attempt to apply effect type "..effect_type_id.." to player "..playername.." failed!")
|
||||
return false
|
||||
else
|
||||
metadata = status
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local effect_id = playereffects.next_effect_id()
|
||||
local smallest_hudpos
|
||||
local biggest_hudpos = -1
|
||||
local free_hudpos
|
||||
if(playereffects.hudinfos[playername] == nil) then
|
||||
playereffects.hudinfos[playername] = {}
|
||||
end
|
||||
local hudinfos = playereffects.hudinfos[playername]
|
||||
for effect_id, hudinfo in pairs(hudinfos) do
|
||||
local hudpos = hudinfo.pos
|
||||
if(hudpos > biggest_hudpos) then
|
||||
biggest_hudpos = hudpos
|
||||
end
|
||||
if(smallest_hudpos == nil) then
|
||||
smallest_hudpos = hudpos
|
||||
elseif(hudpos < smallest_hudpos) then
|
||||
smallest_hudpos = hudpos
|
||||
end
|
||||
end
|
||||
if(smallest_hudpos == nil) then
|
||||
free_hudpos = 0
|
||||
elseif(smallest_hudpos >= 0) then
|
||||
free_hudpos = smallest_hudpos - 1
|
||||
else
|
||||
free_hudpos = biggest_hudpos + 1
|
||||
end
|
||||
|
||||
local repeat_interval = playereffects.effect_types[effect_type_id].repeat_interval
|
||||
if(repeat_interval ~= nil) then
|
||||
if(repeat_interval_time_left == nil) then
|
||||
repeat_interval_time_left = repeat_interval
|
||||
end
|
||||
end
|
||||
|
||||
--[[ show no more than 20 effects on the screen, so that hud_update does not need to be called so often ]]
|
||||
local text_id, icon_id
|
||||
if(free_hudpos <= 20) then
|
||||
text_id, icon_id = playereffects.hud_effect(effect_type_id, player, free_hudpos, duration, repeat_interval_time_left)
|
||||
local hudinfo = {
|
||||
text_id = text_id,
|
||||
icon_id = icon_id,
|
||||
pos = free_hudpos,
|
||||
}
|
||||
playereffects.hudinfos[playername][effect_id] = hudinfo
|
||||
else
|
||||
text_id, icon_id = nil, nil
|
||||
end
|
||||
|
||||
local effect = {
|
||||
playername = playername,
|
||||
effect_id = effect_id,
|
||||
effect_type_id = effect_type_id,
|
||||
start_time = start_time,
|
||||
repeat_interval_start_time = start_time,
|
||||
time_left = duration,
|
||||
repeat_interval_time_left = repeat_interval_time_left,
|
||||
metadata = metadata,
|
||||
}
|
||||
|
||||
playereffects.effects[effect_id] = effect
|
||||
|
||||
if(repeat_interval ~= nil) then
|
||||
minetest.after(repeat_interval_time_left, playereffects.repeater, effect_id, duration, player, playereffects.effect_types[effect_type_id].apply)
|
||||
else
|
||||
minetest.after(duration, function(effect_id) playereffects.cancel_effect(effect_id) end, effect_id)
|
||||
end
|
||||
|
||||
return effect_id
|
||||
end
|
||||
|
||||
function playereffects.repeater(effect_id, repetitions, player, apply)
|
||||
local effect = playereffects.effects[effect_id]
|
||||
if(effect ~= nil) then
|
||||
local repetitions = effect.time_left
|
||||
apply(player)
|
||||
repetitions = repetitions - 1
|
||||
effect.time_left = repetitions
|
||||
if(repetitions <= 0) then
|
||||
playereffects.cancel_effect(effect_id)
|
||||
else
|
||||
local repeat_interval = playereffects.effect_types[effect.effect_type_id].repeat_interval
|
||||
effect.repeat_interval_time_left = repeat_interval
|
||||
effect.repeat_interval_start_time = os.time()
|
||||
minetest.after(
|
||||
repeat_interval,
|
||||
playereffects.repeater,
|
||||
effect_id,
|
||||
repetitions,
|
||||
player,
|
||||
apply
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.cancel_effect_type(effect_type_id, cancel_all, playername)
|
||||
local effects = playereffects.get_player_effects(playername)
|
||||
if(cancel_all==nil) then cancel_all = false end
|
||||
for e=1, #effects do
|
||||
if(effects[e].effect_type_id == effect_type_id) then
|
||||
playereffects.cancel_effect(effects[e].effect_id)
|
||||
if(cancel_all==false) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.cancel_effect_group(groupname, playername)
|
||||
local effects = playereffects.get_player_effects(playername)
|
||||
for e=1,#effects do
|
||||
local effect = effects[e]
|
||||
local thesegroups = playereffects.effect_types[effect.effect_type_id].groups
|
||||
local delete = false
|
||||
for g=1,#thesegroups do
|
||||
if(thesegroups[g] == groupname) then
|
||||
playereffects.cancel_effect(effect.effect_id)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.get_remaining_effect_time(effect_id)
|
||||
local now = os.time()
|
||||
local effect = playereffects.effects[effect_id]
|
||||
if(effect ~= nil) then
|
||||
return (effect.time_left - os.difftime(now, effect.start_time))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.cancel_effect(effect_id)
|
||||
local effect = playereffects.effects[effect_id]
|
||||
if(effect ~= nil) then
|
||||
local player = minetest.get_player_by_name(effect.playername)
|
||||
local hudinfo = playereffects.hudinfos[effect.playername][effect_id]
|
||||
if(hudinfo ~= nil) then
|
||||
if(hudinfo.text_id~=nil) then
|
||||
player:hud_remove(hudinfo.text_id)
|
||||
end
|
||||
if(hudinfo.icon_id~=nil) then
|
||||
player:hud_remove(hudinfo.icon_id)
|
||||
end
|
||||
playereffects.hudinfos[effect.playername][effect_id] = nil
|
||||
end
|
||||
playereffects.effect_types[effect.effect_type_id].cancel(effect, player)
|
||||
playereffects.effects[effect_id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.get_player_effects(playername)
|
||||
if(minetest.get_player_by_name(playername) ~= nil) then
|
||||
local effects = {}
|
||||
for k,v in pairs(playereffects.effects) do
|
||||
if(v.playername == playername) then
|
||||
table.insert(effects, v)
|
||||
end
|
||||
end
|
||||
return effects
|
||||
else
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.has_effect_type(playername, effect_type_id)
|
||||
local pe = playereffects.get_player_effects(playername)
|
||||
for i=1,#pe do
|
||||
if pe[i].effect_type_id == effect_type_id then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--[=[ Saving all data to file ]=]
|
||||
function playereffects.save_to_file()
|
||||
local save_time = os.time()
|
||||
local savetable = {}
|
||||
local inactive_effects = {}
|
||||
for id,effecttable in pairs(playereffects.inactive_effects) do
|
||||
local playername = id
|
||||
if(inactive_effects[playername] == nil) then
|
||||
inactive_effects[playername] = {}
|
||||
end
|
||||
for i=1,#effecttable do
|
||||
table.insert(inactive_effects[playername], effecttable[i])
|
||||
end
|
||||
end
|
||||
for id,effect in pairs(playereffects.effects) do
|
||||
local new_duration, new_repeat_duration
|
||||
if(playereffects.effect_types[effect.effect_type_id].repeat_interval ~= nil) then
|
||||
new_duration = effect.time_left
|
||||
new_repeat_duration = effect.repeat_interval_time_left - os.difftime(save_time, effect.repeat_interval_start_time)
|
||||
else
|
||||
new_duration = effect.time_left - os.difftime(save_time, effect.start_time)
|
||||
end
|
||||
local new_effect = {
|
||||
effect_id = effect.effect_id,
|
||||
effect_type_id = effect.effect_type_id,
|
||||
time_left = new_duration,
|
||||
repeat_interval_time_left = new_repeat_duration,
|
||||
start_time = effect.start_time,
|
||||
repeat_interval_start_time = effect.repeat_interval_start_time,
|
||||
playername = effect.playername,
|
||||
metadata = effect.metadata
|
||||
}
|
||||
if(inactive_effects[effect.playername] == nil) then
|
||||
inactive_effects[effect.playername] = {}
|
||||
end
|
||||
table.insert(inactive_effects[effect.playername], new_effect)
|
||||
end
|
||||
|
||||
savetable.inactive_effects = inactive_effects
|
||||
savetable.last_effect_id = playereffects.last_effect_id
|
||||
|
||||
local savestring = minetest.serialize(savetable)
|
||||
|
||||
local filepath = minetest.get_worldpath().."/playereffects.mt"
|
||||
local file = io.open(filepath, "w")
|
||||
if file then
|
||||
file:write(savestring)
|
||||
io.close(file)
|
||||
minetest.log("action", "[playereffects] Wrote playereffects data into "..filepath..".")
|
||||
else
|
||||
minetest.log("error", "[playereffects] Failed to write playereffects data into "..filepath..".")
|
||||
end
|
||||
end
|
||||
|
||||
--[=[ Callbacks ]=]
|
||||
--[[ Cancel all effects on player death ]]
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local effects = playereffects.get_player_effects(player:get_player_name())
|
||||
for e=1,#effects do
|
||||
if(playereffects.effect_types[effects[e].effect_type_id].cancel_on_death == true) then
|
||||
playereffects.cancel_effect(effects[e].effect_id)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local leave_time = os.time()
|
||||
local playername = player:get_player_name()
|
||||
local effects = playereffects.get_player_effects(playername)
|
||||
|
||||
playereffects.hud_clear(player)
|
||||
|
||||
if(playereffects.inactive_effects[playername] == nil) then
|
||||
playereffects.inactive_effects[playername] = {}
|
||||
end
|
||||
for e=1,#effects do
|
||||
local new_duration = effects[e].time_left - os.difftime(leave_time, effects[e].start_time)
|
||||
local new_effect = effects[e]
|
||||
new_effect.time_left = new_duration
|
||||
table.insert(playereffects.inactive_effects[playername], new_effect)
|
||||
playereffects.cancel_effect(effects[e].effect_id)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
minetest.log("action", "[playereffects] Server shuts down. Rescuing data into playereffects.mt")
|
||||
playereffects.save_to_file()
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local playername = player:get_player_name()
|
||||
|
||||
-- load all the effects again (if any)
|
||||
if(playereffects.inactive_effects[playername] ~= nil) then
|
||||
for i=1,#playereffects.inactive_effects[playername] do
|
||||
local effect = playereffects.inactive_effects[playername][i]
|
||||
playereffects.apply_effect_type(effect.effect_type_id, effect.time_left, player, effect.repeat_interval_time_left)
|
||||
end
|
||||
playereffects.inactive_effects[playername] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
playereffects.globalstep_timer = 0
|
||||
playereffects.autosave_timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
playereffects.globalstep_timer = playereffects.globalstep_timer + dtime
|
||||
playereffects.autosave_timer = playereffects.autosave_timer + dtime
|
||||
-- Update HUDs of all players
|
||||
if(playereffects.globalstep_timer >= 1) then
|
||||
playereffects.globalstep_timer = 0
|
||||
|
||||
local players = minetest.get_connected_players()
|
||||
for p=1,#players do
|
||||
playereffects.hud_update(players[p])
|
||||
end
|
||||
end
|
||||
-- Autosave into file
|
||||
if(playereffects.use_autosave == true and playereffects.autosave_timer >= playereffects.autosave_time) then
|
||||
playereffects.autosave_timer = 0
|
||||
minetest.log("action", "[playereffects] Autosaving mod data to playereffects.mt ...")
|
||||
playereffects.save_to_file()
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
||||
--[=[ HUD ]=]
|
||||
function playereffects.hud_update(player)
|
||||
if(playereffects.use_hud == true) then
|
||||
local now = os.time()
|
||||
local playername = player:get_player_name()
|
||||
local hudinfos = playereffects.hudinfos[playername]
|
||||
if(hudinfos ~= nil) then
|
||||
for effect_id, hudinfo in pairs(hudinfos) do
|
||||
local effect = playereffects.effects[effect_id]
|
||||
if(effect ~= nil and hudinfo.text_id ~= nil) then
|
||||
local description = playereffects.effect_types[effect.effect_type_id].description
|
||||
local repeat_interval = playereffects.effect_types[effect.effect_type_id].repeat_interval
|
||||
if(repeat_interval ~= nil) then
|
||||
local repeat_interval_time_left = os.difftime(effect.repeat_interval_start_time + effect.repeat_interval_time_left, now)
|
||||
player:hud_change(hudinfo.text_id, "text", description .. " ("..tostring(effect.time_left).."/"..tostring(repeat_interval_time_left) .. "s )")
|
||||
else
|
||||
local time_left = os.difftime(effect.start_time + effect.time_left, now)
|
||||
player:hud_change(hudinfo.text_id, "text", description .. " ("..tostring(time_left).." s)")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.hud_clear(player)
|
||||
if(playereffects.use_hud == true) then
|
||||
local playername = player:get_player_name()
|
||||
local hudinfos = playereffects.hudinfos[playername]
|
||||
if(hudinfos ~= nil) then
|
||||
for effect_id, hudinfo in pairs(hudinfos) do
|
||||
local effect = playereffects.effects[effect_id]
|
||||
if(hudinfo.text_id ~= nil) then
|
||||
player:hud_remove(hudinfo.text_id)
|
||||
end
|
||||
if(hudinfo.icon_id ~= nil) then
|
||||
player:hud_remove(hudinfo.icon_id)
|
||||
end
|
||||
playereffects.hudinfos[playername][effect_id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.hud_effect(effect_type_id, player, pos, time_left, repeat_interval_time_left)
|
||||
local text_id, icon_id
|
||||
local effect_type = playereffects.effect_types[effect_type_id]
|
||||
if(playereffects.use_hud == true and effect_type.hidden == false) then
|
||||
local color
|
||||
if(playereffects.effect_types[effect_type_id].cancel_on_death == true) then
|
||||
color = 0xFFFFFF
|
||||
else
|
||||
color = 0xF0BAFF
|
||||
end
|
||||
local description = playereffects.effect_types[effect_type_id].description
|
||||
local text
|
||||
if(repeat_interval_time_left ~= nil) then
|
||||
text = description .. " ("..tostring(time_left).."/"..tostring(repeat_interval_time_left) .. "s )"
|
||||
else
|
||||
text = description .. " ("..tostring(time_left).." s)"
|
||||
end
|
||||
text_id = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = { x = 1, y = 0.3 },
|
||||
name = "effect_"..effect_type_id,
|
||||
text = text,
|
||||
scale = { x = 170, y = 20},
|
||||
alignment = { x = -1, y = 0 },
|
||||
direction = 1,
|
||||
number = color,
|
||||
offset = { x = -5, y = pos*20 }
|
||||
})
|
||||
if(playereffects.effect_types[effect_type_id].icon ~= nil) then
|
||||
icon_id = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
scale = { x = 1, y = 1 },
|
||||
position = { x = 1, y = 0.3 },
|
||||
name = "effect_icon_"..effect_type_id,
|
||||
text = playereffects.effect_types[effect_type_id].icon,
|
||||
alignment = { x = -1, y=0 },
|
||||
direction = 0,
|
||||
offset = { x = -186, y = pos*20 },
|
||||
})
|
||||
end
|
||||
else
|
||||
text_id = nil
|
||||
icon_id = nil
|
||||
end
|
||||
return text_id, icon_id
|
||||
end
|
||||
|
||||
|
||||
-- LOAD EXAMPLES
|
||||
if(playereffects.use_examples == true) then
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/examples.lua")
|
||||
end
|
15
worldmods/playereffects/settings.lua
Normal file
15
worldmods/playereffects/settings.lua
Normal file
@ -0,0 +1,15 @@
|
||||
--[[
|
||||
Settings for Player Effects
|
||||
]]
|
||||
|
||||
-- Wheather to use the HUD to expose the active effects to players (true or false)
|
||||
playereffects.use_hud = true
|
||||
|
||||
-- Wheather to use autosave (true or false)
|
||||
playereffects.use_autosave = true
|
||||
|
||||
-- The time interval between autosaves, in seconds (only used when use_autosave is true)
|
||||
playereffects.autosave_time = 10
|
||||
|
||||
-- If true, this loads some examples from example.lua.
|
||||
playereffects.use_examples = false
|
BIN
worldmods/playereffects/textures/playereffects_example_black.png
Normal file
BIN
worldmods/playereffects/textures/playereffects_example_black.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 B |
BIN
worldmods/playereffects/textures/playereffects_example_fly.png
Normal file
BIN
worldmods/playereffects/textures/playereffects_example_fly.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 B |
Binary file not shown.
After Width: | Height: | Size: 120 B |
121
worldmods/server_essentials/COPYING
Normal file
121
worldmods/server_essentials/COPYING
Normal file
@ -0,0 +1,121 @@
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
79
worldmods/server_essentials/README.md
Normal file
79
worldmods/server_essentials/README.md
Normal file
@ -0,0 +1,79 @@
|
||||
# Server Essentials
|
||||
|
||||
Minetest mod by GunshipPenguin
|
||||
|
||||
A collection of useful commands and features for use by Minetest server administrators.
|
||||
|
||||
### List of commands:
|
||||
|
||||
+ /ping
|
||||
+ Required privileges: None
|
||||
+ Pong!
|
||||
|
||||
+ /clearinv
|
||||
+ Required privileges: None
|
||||
+ Clears your inventory.
|
||||
|
||||
+ /godmode
|
||||
+ Required privileges: godmode
|
||||
+ Toggles godmode for yourself (infinite health and breath).
|
||||
|
||||
+ /kill \< playerName \>
|
||||
+ Required privileges: kill
|
||||
+ Kills specified player.
|
||||
|
||||
+ /killme
|
||||
+ Required Privileges: None
|
||||
+ Kills self.
|
||||
|
||||
+ /heal \[ playerName \]
|
||||
+ Required privileges: heal
|
||||
+ Heals specified player, if no player is specified, heals self.
|
||||
|
||||
+ /motd
|
||||
+ Required privileges: none
|
||||
+ Displays server motd.
|
||||
|
||||
+ /broadcast
|
||||
+ Required privileges: broadcast
|
||||
+ Broadcasts message to entire server.
|
||||
|
||||
+ /top
|
||||
+ Required privileges: top
|
||||
+ Teleports you ontop of the highest non air node directly above you.
|
||||
|
||||
+ /gettime
|
||||
+ Required privileges: none
|
||||
+ Gets current time of day.
|
||||
|
||||
+ /spawn
|
||||
+ Required privileges: spawn
|
||||
+ Only available if static_spawnpoint is set in minetest.conf. Teleports
|
||||
player to static spawnpoint.
|
||||
|
||||
+ /setspeed <speed> \[ playerName \]
|
||||
+ Required privileges: setspeed
|
||||
+ Sets speed of player. One represents normal walking speed, 2 represents
|
||||
twice normal speed, etc. If no player name is specified, sets your own speed.
|
||||
|
||||
+ /whatisthis
|
||||
+ Required privileges: None
|
||||
+ Gets itemstring of currently wielded item.
|
||||
|
||||
+ /whois \< playerName \>
|
||||
+ Required privileges: whois
|
||||
+ Gets network information of specified player.
|
||||
|
||||
### Other features:
|
||||
|
||||
See settings.lua to configure these features.
|
||||
|
||||
+ Auto afk kicking:
|
||||
+ Automatically kick afk players after a set amount of time. Players
|
||||
with the canafk privilege can remain afk indefenetly.
|
||||
|
||||
+ First time join message:
|
||||
+ Shows a message when a player joins the server for the first time.
|
||||
|
||||
+ Chat spam kicking:
|
||||
+ Automatically kick players who send chat messages that are greater than a certian length.
|
370
worldmods/server_essentials/init.lua
Normal file
370
worldmods/server_essentials/init.lua
Normal file
@ -0,0 +1,370 @@
|
||||
--[[
|
||||
Server Essentials mod for Minetest by GunshipPenguin
|
||||
|
||||
To the extent possible under law, the author(s)
|
||||
have dedicated all copyright and related and neighboring rights
|
||||
to this software to the public domain worldwide. This software is
|
||||
distributed without any warranty.
|
||||
--]]
|
||||
|
||||
players = {}
|
||||
check_timer = 0
|
||||
dofile(minetest.get_modpath("serveressentials") .. "/settings.lua")
|
||||
|
||||
minetest.register_privilege("godmode",
|
||||
"Player can use godmode with the /godmode command")
|
||||
minetest.register_privilege("broadcast",
|
||||
"Player can use /broadcast command")
|
||||
minetest.register_privilege("kill",
|
||||
"Player can kill other players with the /kill command")
|
||||
minetest.register_privilege("heal",
|
||||
"Player can heal other players with the /heal command")
|
||||
minetest.register_privilege("top",
|
||||
"Player can use the /top command")
|
||||
--priv not needed.
|
||||
--minetest.register_privilege("setspeed",
|
||||
-- "Player can set player speeds with the /setspeed command")
|
||||
minetest.register_privilege("whois",
|
||||
"Player can view other player's network information with the /whois command")
|
||||
--priv not needed.
|
||||
--minetest.register_privilege("chatspam",
|
||||
-- "Player can send chat messages longer than MAX_CHAT_MSG_LENGTH without being kicked")
|
||||
|
||||
-- Disabled so ALL players will be kicked for AFK.
|
||||
--[[
|
||||
if AFK_CHECK then
|
||||
minetest.register_privilege("canafk",
|
||||
"Player can remain afk without being kicked")
|
||||
end
|
||||
--]]
|
||||
|
||||
if minetest.setting_get("static_spawnpoint") then
|
||||
minetest.register_privilege("spawn",
|
||||
"Player can teleport to static spawnpoint using /spawn command")
|
||||
|
||||
minetest.register_chatcommand("spawn", {
|
||||
params = "",
|
||||
description = "Teleport to static spawnpoint",
|
||||
privs = {spawn = true},
|
||||
func = function(player_name, param)
|
||||
local spawn_func = function(player_name)
|
||||
local spawn_point = minetest.setting_get("static_spawnpoint")
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
player:setpos(minetest.string_to_pos(spawn_point))
|
||||
return
|
||||
end
|
||||
|
||||
if SPAWN_DELAY > 0 then
|
||||
minetest.chat_send_player(player_name,
|
||||
"Teleporting you to spawn in " .. SPAWN_DELAY .. " seconds")
|
||||
minetest.after(SPAWN_DELAY, spawn_func, player_name)
|
||||
else
|
||||
minetest.chat_send_player(player_name, "Teleporting you to spawn")
|
||||
spawn_func(player_name)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("ping", {
|
||||
params = "",
|
||||
description = "Pong!",
|
||||
privs = {},
|
||||
func = function(player_name, text)
|
||||
minetest.chat_send_player(player_name, "Pong!")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("motd", {
|
||||
params = "",
|
||||
description = "Display server motd",
|
||||
privs = {},
|
||||
func = function(player_name, text)
|
||||
local motd = minetest.setting_get("motd")
|
||||
if motd == nil or motd == "" then
|
||||
minetest.chat_send_player(player_name, "Motd has not been set")
|
||||
else
|
||||
minetest.chat_send_player(player_name, motd)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
--Already in default game so disabled here.
|
||||
--[[
|
||||
minetest.register_chatcommand("clearinv", {
|
||||
params = "";
|
||||
description = "Clear your inventory",
|
||||
privs = {},
|
||||
func = function(player_name, text)
|
||||
local inventory = minetest.get_player_by_name(player_name):get_inventory()
|
||||
inventory:set_list("main", {})
|
||||
end,
|
||||
})
|
||||
--]]
|
||||
|
||||
minetest.register_chatcommand("broadcast", {
|
||||
params = "<text>",
|
||||
description = "Broadcast message to server",
|
||||
privs = {broadcast = true},
|
||||
func = function(player_name, text)
|
||||
minetest.chat_send_all(BROADCAST_PREFIX .. " " .. text)
|
||||
return
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("kill", {
|
||||
params = "<player_name>",
|
||||
description = "kill specified player",
|
||||
privs = {kill = true},
|
||||
func = function(player_name, param)
|
||||
|
||||
if #param==0 then
|
||||
minetest.chat_send_player(player_name, "You must supply a player name")
|
||||
elseif players[param] then
|
||||
minetest.chat_send_player(player_name, "Killing player " .. param)
|
||||
minetest.get_player_by_name(param):set_hp(0)
|
||||
else
|
||||
minetest.chat_send_player(player_name, "Player " .. param .. " cannot be found")
|
||||
end
|
||||
return
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("top", {
|
||||
params = "",
|
||||
description = "Teleport to topmost block at your current position",
|
||||
privs = {top = true},
|
||||
func = function(player_name, param)
|
||||
curr_pos = minetest.get_player_by_name(player_name):getpos()
|
||||
curr_pos["y"] = math.ceil(curr_pos["y"]) + 0.5
|
||||
|
||||
while minetest.get_node(curr_pos)["name"] ~= "ignore" do
|
||||
curr_pos["y"] = curr_pos["y"] + 1
|
||||
end
|
||||
|
||||
curr_pos["y"] = curr_pos["y"] - 0.5
|
||||
|
||||
while minetest.get_node(curr_pos)["name"] == "air" do
|
||||
curr_pos["y"] = curr_pos["y"] - 1
|
||||
end
|
||||
curr_pos["y"] = curr_pos["y"] + 0.5
|
||||
|
||||
minetest.get_player_by_name(player_name):setpos(curr_pos)
|
||||
return
|
||||
end
|
||||
})
|
||||
|
||||
--Already in default game so disabled here.
|
||||
--[[
|
||||
minetest.register_chatcommand("killme", {
|
||||
params = "",
|
||||
description = "Kill yourself",
|
||||
func = function(player_name, param)
|
||||
minetest.chat_send_player(player_name, "Killing Player " .. player_name)
|
||||
minetest.get_player_by_name(player_name):set_hp(0)
|
||||
return
|
||||
end
|
||||
})
|
||||
--]]
|
||||
|
||||
minetest.register_chatcommand("heal", {
|
||||
params = "[player_name]",
|
||||
description = "Heal specified player, heals self if run without arguments",
|
||||
privs = {heal = true},
|
||||
func = function(player_name, param)
|
||||
|
||||
if #param == 0 then
|
||||
minetest.chat_send_player(player_name, "Healing player " .. player_name)
|
||||
minetest.get_player_by_name(player_name):set_hp(20)
|
||||
elseif players[player_name] and param and players[param] then
|
||||
minetest.chat_send_player(player_name, "Healing player " .. param)
|
||||
minetest.get_player_by_name(param):set_hp(20)
|
||||
else
|
||||
minetest.chat_send_player(player_name, "Player " .. param .. " cannot not be found")
|
||||
end
|
||||
return
|
||||
end
|
||||
})
|
||||
|
||||
--This simply isn't needed.
|
||||
--[[
|
||||
minetest.register_chatcommand("gettime", {
|
||||
params = "",
|
||||
description = "Get the current time of day",
|
||||
privs = {},
|
||||
func = function(player_name, param)
|
||||
minetest.chat_send_player(player_name, "Current time of day is: " ..
|
||||
tostring(math.ceil(minetest.get_timeofday() * 24000)))
|
||||
return
|
||||
end
|
||||
})
|
||||
--]]
|
||||
|
||||
minetest.register_chatcommand("godmode", {
|
||||
params = "",
|
||||
description = "Toggle godmode",
|
||||
privs = {godmode = true},
|
||||
func = function(player_name, param)
|
||||
players[player_name]["god_mode"] = not players[player_name]["god_mode"];
|
||||
if players[player_name]["god_mode"] then
|
||||
minetest.chat_send_player(player_name, "Godmode is now on")
|
||||
else
|
||||
minetest.chat_send_player(player_name, "Godmode is now off")
|
||||
end
|
||||
return
|
||||
end
|
||||
})
|
||||
|
||||
--We won't be using this.
|
||||
--[[
|
||||
minetest.register_chatcommand("setspeed", {
|
||||
params = "<speed> [player_name]",
|
||||
description = "Set your or somebody else's walking speed",
|
||||
privs = {setspeed = true},
|
||||
func = function(player_name, param)
|
||||
param = string.split(param, " ")
|
||||
|
||||
if #param == 0 or tonumber(param[1]) == nil then
|
||||
minetest.chat_send_player(player_name, "You must supply proper a speed")
|
||||
elseif players[player_name] and players[param[2]] then
|
||||
minetest.chat_send_player(player_name, "Setting player " ..
|
||||
param[2] ..
|
||||
"'s walking speed to " ..
|
||||
tostring(param[1]) ..
|
||||
" times normal speed")
|
||||
minetest.chat_send_player(param[2], "Your walking speed has been set to "
|
||||
.. param[1] ..
|
||||
" times normal speed")
|
||||
minetest.get_player_by_name(param[2]):set_physics_override({
|
||||
speed=tonumber(param[2]),
|
||||
jump=1.0,
|
||||
gravity=1.0
|
||||
})
|
||||
elseif players[player_name] and not param[2] then
|
||||
minetest.chat_send_player(player_name, "Setting player " ..
|
||||
player_name ..
|
||||
"'s walking speed to " ..
|
||||
tostring(param[1]) ..
|
||||
" times normal speed.")
|
||||
minetest.get_player_by_name(player_name):set_physics_override({
|
||||
speed=tonumber(param[1]),
|
||||
jump=1.0,
|
||||
gravity=1.0
|
||||
})
|
||||
else
|
||||
minetest.chat_send_player(player_name, "Player " ..
|
||||
param[2] ..
|
||||
" cannot be found")
|
||||
end
|
||||
return
|
||||
end
|
||||
})
|
||||
--]]
|
||||
|
||||
minetest.register_chatcommand("whatisthis", {
|
||||
params = "",
|
||||
description = "Get itemstring of wielded item",
|
||||
func = function(player_name, param)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
minetest.chat_send_player(player_name, player:get_wielded_item():to_string())
|
||||
return
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("whois", {
|
||||
params = "<player_name>",
|
||||
description = "Get network information of player",
|
||||
privs = {whois = true},
|
||||
func = function(player_name, param)
|
||||
if not param or not players[param] then
|
||||
minetest.chat_send_player(player_name, "Player " .. param .. " was not found")
|
||||
return
|
||||
end
|
||||
playerInfo = minetest.get_player_information(param)
|
||||
minetest.chat_send_player(player_name, param ..
|
||||
" - IP address - " .. playerInfo["address"])
|
||||
minetest.chat_send_player(player_name, param ..
|
||||
" - Avg rtt - " .. playerInfo["avg_rtt"])
|
||||
minetest.chat_send_player(player_name, param ..
|
||||
" - Connection uptime (seconds) - " .. playerInfo["connection_uptime"])
|
||||
return
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
players[player:get_player_name()] = {
|
||||
last_action = minetest.get_gametime(),
|
||||
godmode = false
|
||||
}
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
players[player:get_player_name()] = nil
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
if SHOW_FIRST_TIME_JOIN_MSG then
|
||||
minetest.after(0.1, function()
|
||||
minetest.chat_send_all(player:get_player_name() .. FIRST_TIME_JOIN_MSG)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_chat_message(function(name, message)
|
||||
if KICK_CHATSPAM and not minetest.check_player_privs(name, {chatspam=true}) and
|
||||
string.len(message) > MAX_CHAT_MSG_LENGTH then
|
||||
minetest.kick_player(name,
|
||||
"You were kicked because you sent a chat message longer than " ..
|
||||
MAX_CHAT_MSG_LENGTH ..
|
||||
" characters. This is to prevent chat spamming.")
|
||||
return true
|
||||
end
|
||||
return
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
-- Loop through all connected players
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
-- Only continue if the player has an entry in the players table
|
||||
if players[player_name] then
|
||||
|
||||
-- Check for afk players
|
||||
if AFK_CHECK and not minetest.check_player_privs(player_name, {canafk=true}) then
|
||||
check_timer = check_timer + dtime
|
||||
if check_timer > AFK_CHECK_INTERVAL then
|
||||
check_timer = 0
|
||||
|
||||
-- Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
|
||||
if players[player_name]["last_action"] + MAX_AFK_TIME <
|
||||
minetest.get_gametime() then
|
||||
minetest.kick_player(player_name, "Kicked for inactivity")
|
||||
end
|
||||
|
||||
-- Warn player if he/she has less than WARN_TIME seconds to move or be kicked
|
||||
if players[player_name]["last_action"] + MAX_AFK_TIME - AFK_WARN_TIME <
|
||||
minetest.get_gametime() then
|
||||
minetest.chat_send_player(player_name, "Warning, you have " ..
|
||||
tostring(players[player_name]["last_action"] + MAX_AFK_TIME - minetest.get_gametime())
|
||||
.. " seconds to move or be kicked")
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if this player is doing an action
|
||||
for _,keyPressed in pairs(player:get_player_control()) do
|
||||
if keyPressed then
|
||||
players[player_name]["last_action"] = minetest.get_gametime()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if player has godmode turned on
|
||||
if players[player_name]["god_mode"] then
|
||||
player:set_hp(20)
|
||||
player:set_breath(11)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
23
worldmods/server_essentials/settings.lua
Normal file
23
worldmods/server_essentials/settings.lua
Normal file
@ -0,0 +1,23 @@
|
||||
-- Whether or not to automatically kick afk players
|
||||
AFK_CHECK = true
|
||||
-- Max time allowed afk before kick
|
||||
MAX_AFK_TIME = 2700
|
||||
-- Number of seconds between activity checks
|
||||
AFK_CHECK_INTERVAL = 60
|
||||
-- Number of seconds before being kicked that a player will start to be warned
|
||||
AFK_WARN_TIME = 20
|
||||
|
||||
-- Whether or not to show FIRST_TIME_JOIN_MSG if a new player joins
|
||||
SHOW_FIRST_TIME_JOIN_MSG = false
|
||||
-- Message to broadcast to all players when a new player joins the server, will follow the players name
|
||||
FIRST_TIME_JOIN_MSG = " has joined the server for the first time, Welcome!"
|
||||
|
||||
-- All messages sent with the /broadcast command will be prefixed with this
|
||||
BROADCAST_PREFIX = "[SERVER]"
|
||||
|
||||
-- If true, players who send a chat message longer than MAX_CHAT_MSG_LENGTH will be kicked
|
||||
KICK_CHATSPAM = true
|
||||
MAX_CHAT_MSG_LENGTH = 300
|
||||
|
||||
-- Delay in seconds that will occur between issuing /spawn command and actually being teleported to the static_spawnpoint
|
||||
SPAWN_DELAY = 0
|
Loading…
x
Reference in New Issue
Block a user