mirror of
https://repo.or.cz/minetest_playereffects.git
synced 2025-01-23 08:40:16 +01:00
Add API functions to get the current effect time
This commit is contained in:
parent
7bfd30ce39
commit
a97ddfd942
18
README.md
18
README.md
@ -170,6 +170,24 @@ Careful! This function has *not* been tested yet!
|
|||||||
##### Return value
|
##### Return value
|
||||||
Always `nil`.
|
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_passed_effect_time(effect_id)`
|
||||||
|
Returns the time an effect was in place.
|
||||||
|
|
||||||
|
##### Parameter
|
||||||
|
* `effect_id`: The effect identifier of the effect in question
|
||||||
|
|
||||||
|
##### Return value
|
||||||
|
Iff the effect exists, the number of seconds the effect is in place is returned. Iff the effect does not exist, `nil` is returned.
|
||||||
|
|
||||||
#### `playereffects.get_player_effects(playername)`
|
#### `playereffects.get_player_effects(playername)`
|
||||||
Returns all active effects of a player.
|
Returns all active effects of a player.
|
||||||
|
|
||||||
|
20
init.lua
20
init.lua
@ -199,6 +199,26 @@ function playereffects.cancel_effect_group(groupname, playername)
|
|||||||
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.get_passed_effect_time(effect_id)
|
||||||
|
local now = os.time()
|
||||||
|
local effect = playereffects.effects[effect_id]
|
||||||
|
if(effect ~= nil) then
|
||||||
|
return os.difftime(now, effect.start_time)
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function playereffects.cancel_effect(effect_id)
|
function playereffects.cancel_effect(effect_id)
|
||||||
local effect = playereffects.effects[effect_id]
|
local effect = playereffects.effects[effect_id]
|
||||||
if(effect ~= nil) then
|
if(effect ~= nil) then
|
||||||
|
Loading…
Reference in New Issue
Block a user