License: WTFPL
Depends: whoison ( https://github.com/bremaweb/whoison )
Download: https://github.com/Bremaweb/affects/archive/master.zip
Github: https://github.com/bremaweb/affects
This mod depends on my whoison mod because it times how long a player is online, the length of an affect stage is based on the player's time online.
This mod adds an API that makes it easy to affect players in various ways. These effects can be anything from adjusting their physics, giving temporary permissions, and even simulating poisons or diseases.
This is only an API, it doesn't have any predefined effects that are setup by default. There is a affect_examples.lua file which includes a few examples, but this file isn't loaded when the mod runs.
Functions
affects.registerAffect( {affect definition} )
affects.affectPlayer(name,affectid)
affects.removeAffect(name,affectid)
Effect Definition
- Code: Select all
affect = {
affectid = <unique string id for this affect>,
name = <string name for this affect>,
stages = { {stage definition}, {stage definition}, .. },
onremove = function(name,player,affectid) -- optional function that is ran when the affect is removed
}
Stage Definition
This is where the magic happens. You can define as many stages for an effect as you want. This can be used to gradually decrease the effect or make the effect change over time. The sky is the limit
- Code: Select all
{
time = <number of seconds this stage lasts>,
physics = { ... },
-- optional this is a table as used by set_physics_override ( https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1787 ) to change the physics for a player during this stage
emote = { chance = <Number 1-100>, action = <string> }
-- optional chance is the chance out of 100 that action will be displayed in chat as if the affected player had used /me <action>
place = { chance = <number 1-100>, node = <string node that will be placed> },
-- optional, chance is the chance out of 100 the player with place the node defined at their current position, node would be a string like "default:dirt"
damage = { chance = <number 1-100>, amount = <number> }
-- optional, chance the player will be dealt the amount defined in damage, this could be a negative number and actually result in healing instead of damage
custom { func = function(name, player, affectid), chance = <number 1-100>, runonce = <true/false> }
-- optional, a function that you can write to do whatever you want. runonce tells whether this function should only be ran once or not
}
When a player is affected they start at the first stage. The function to apply the effects runs every 30 seconds. Each time it runs it uses what you defined as a chance to determine if it should execute the items in the stage, excluding physics. Physics are re-applied every run to ensure the physics changes are applied even after the player logs off and logs back on.
The custom function has a runonce variable, if true the custom function will only run one time for the whole time that stage is in affect. After the player has been online longer than the time in your stage definition they are moved to the next stage, and the effect is applied. After they pass the last stage of the affect the onremove function is called, the physics are reset, and the affect is removed.