mirror of
https://repo.or.cz/minetest_playereffects.git
synced 2025-06-29 14:50:48 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
5fe79310b3 | |||
1ef5d93ffc | |||
397286e12f | |||
e058592e3a | |||
22324f3a6c | |||
e1bc0e23c8 |
2
.mailmap
Normal file
2
.mailmap
Normal file
@ -0,0 +1,2 @@
|
||||
Wuzzy <Wuzzy@disroot.org> <Wuzzy2@mail.ru>
|
||||
Wuzzy <Wuzzy@disroot.org> <almikes@aol.com>
|
@ -14,9 +14,7 @@ This is an framework for assigning temporary status effects to players. This mod
|
||||
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`]
|
||||
You only have to install this mod iff you have a mod which implements Player Effects.
|
||||
|
||||
## 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.
|
||||
|
94
init.lua
94
init.lua
@ -56,10 +56,10 @@ do
|
||||
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))
|
||||
minetest.log("action", "[playereffects] playereffects.mt successfully read.")
|
||||
minetest.log("verbose", "[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))
|
||||
minetest.log("verbose", "[playereffects] last_effect_id = "..dump(playereffects.last_effect_id))
|
||||
|
||||
end
|
||||
end
|
||||
@ -98,30 +98,32 @@ function playereffects.register_effect_type(effect_type_id, description, icon, g
|
||||
minetest.log("action", "[playereffects] Effect type "..effect_type_id.." registered!")
|
||||
end
|
||||
|
||||
function playereffects.apply_effect_type(effect_type_id, duration, entity, repeat_interval_time_left)
|
||||
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(entity)=="userdata") then
|
||||
if(entity.is_player ~= nil) then
|
||||
if(entity:is_player() == true) then
|
||||
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 = entity:get_player_name()
|
||||
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, entity)
|
||||
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(entity)
|
||||
local status = playereffects.effect_types[effect_type_id].apply(player)
|
||||
if(status == false) then
|
||||
if is_player then
|
||||
minetest.log("action", "[playereffects] Attempt to apply effect type "..effect_type_id.." to player "..playername.." failed!")
|
||||
end
|
||||
return false
|
||||
else
|
||||
metadata = status
|
||||
@ -130,17 +132,6 @@ function playereffects.apply_effect_type(effect_type_id, duration, entity, repea
|
||||
|
||||
|
||||
local effect_id = playereffects.next_effect_id()
|
||||
|
||||
-- repeat stuff
|
||||
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
|
||||
|
||||
-- Handle HUD
|
||||
if is_player then
|
||||
local smallest_hudpos
|
||||
local biggest_hudpos = -1
|
||||
local free_hudpos
|
||||
@ -167,10 +158,17 @@ function playereffects.apply_effect_type(effect_type_id, duration, entity, repea
|
||||
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, entity, free_hudpos, duration, repeat_interval_time_left)
|
||||
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,
|
||||
@ -180,7 +178,6 @@ function playereffects.apply_effect_type(effect_type_id, duration, entity, repea
|
||||
else
|
||||
text_id, icon_id = nil, nil
|
||||
end
|
||||
end
|
||||
|
||||
local effect = {
|
||||
playername = playername,
|
||||
@ -196,7 +193,7 @@ function playereffects.apply_effect_type(effect_type_id, duration, entity, repea
|
||||
playereffects.effects[effect_id] = effect
|
||||
|
||||
if(repeat_interval ~= nil) then
|
||||
minetest.after(repeat_interval_time_left, playereffects.repeater, effect_id, duration, entity, playereffects.effect_types[effect_type_id].apply)
|
||||
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
|
||||
@ -204,11 +201,11 @@ function playereffects.apply_effect_type(effect_type_id, duration, entity, repea
|
||||
return effect_id
|
||||
end
|
||||
|
||||
function playereffects.repeater(effect_id, repetitions, entity, apply)
|
||||
function playereffects.repeater(effect_id, repetitions, player, apply)
|
||||
local effect = playereffects.effects[effect_id]
|
||||
if(effect ~= nil and entity ~= nil and entity:get_luaentity() ~= nil) then
|
||||
if(effect ~= nil) then
|
||||
local repetitions = effect.time_left
|
||||
apply(entity)
|
||||
apply(player)
|
||||
repetitions = repetitions - 1
|
||||
effect.time_left = repetitions
|
||||
if(repetitions <= 0) then
|
||||
@ -222,15 +219,15 @@ function playereffects.repeater(effect_id, repetitions, entity, apply)
|
||||
playereffects.repeater,
|
||||
effect_id,
|
||||
repetitions,
|
||||
entity,
|
||||
player,
|
||||
apply
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.cancel_effect_type(effect_type_id, cancel_all, entity_or_playername)
|
||||
local effects = playereffects.get_player_effects(entity_or_playername)
|
||||
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
|
||||
@ -242,8 +239,8 @@ function playereffects.cancel_effect_type(effect_type_id, cancel_all, entity_or_
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.cancel_effect_group(groupname, entity_or_playername)
|
||||
local effects = playereffects.get_player_effects(entity_or_playername)
|
||||
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
|
||||
@ -271,7 +268,6 @@ 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)
|
||||
if player then
|
||||
local hudinfo = playereffects.hudinfos[effect.playername][effect_id]
|
||||
if(hudinfo ~= nil) then
|
||||
if(hudinfo.text_id~=nil) then
|
||||
@ -282,24 +278,12 @@ function playereffects.cancel_effect(effect_id)
|
||||
end
|
||||
playereffects.hudinfos[effect.playername][effect_id] = nil
|
||||
end
|
||||
|
||||
-- TODO: Implement cancellation for non-players
|
||||
playereffects.effect_types[effect.effect_type_id].cancel(effect, player)
|
||||
end
|
||||
playereffects.effects[effect_id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.get_player_effects(entity_or_playername)
|
||||
-- TODO: support entity
|
||||
local playername = ""
|
||||
if type(entity_or_playername) == "string" then
|
||||
playername = entity_or_playername
|
||||
elseif type(entity_or_playername) == "userdata" and entity_or_playername:is_player() then
|
||||
playername = entity_or_playername:get_player_name()
|
||||
else
|
||||
return {}
|
||||
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
|
||||
@ -313,8 +297,8 @@ function playereffects.get_player_effects(entity_or_playername)
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.has_effect_type(entity_or_playername, effect_type_id)
|
||||
local pe = playereffects.get_player_effects(entity_or_playername)
|
||||
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
|
||||
@ -330,7 +314,6 @@ function playereffects.save_to_file()
|
||||
local inactive_effects = {}
|
||||
for id,effecttable in pairs(playereffects.inactive_effects) do
|
||||
local playername = id
|
||||
if playername ~= "" then
|
||||
if(inactive_effects[playername] == nil) then
|
||||
inactive_effects[playername] = {}
|
||||
end
|
||||
@ -338,7 +321,6 @@ function playereffects.save_to_file()
|
||||
table.insert(inactive_effects[playername], effecttable[i])
|
||||
end
|
||||
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
|
||||
@ -360,10 +342,8 @@ function playereffects.save_to_file()
|
||||
if(inactive_effects[effect.playername] == nil) then
|
||||
inactive_effects[effect.playername] = {}
|
||||
end
|
||||
if effect.playername ~= "" then
|
||||
table.insert(inactive_effects[effect.playername], new_effect)
|
||||
end
|
||||
end
|
||||
|
||||
savetable.inactive_effects = inactive_effects
|
||||
savetable.last_effect_id = playereffects.last_effect_id
|
||||
@ -375,7 +355,7 @@ function playereffects.save_to_file()
|
||||
if file then
|
||||
file:write(savestring)
|
||||
io.close(file)
|
||||
minetest.log("action", "[playereffects] Wrote playereffects data into "..filepath..".")
|
||||
minetest.log("info", "[playereffects] Wrote playereffects data into "..filepath..".")
|
||||
else
|
||||
minetest.log("error", "[playereffects] Failed to write playereffects data into "..filepath..".")
|
||||
end
|
||||
@ -413,7 +393,7 @@ minetest.register_on_leaveplayer(function(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
minetest.log("action", "[playereffects] Server shuts down. Rescuing data into playereffects.mt")
|
||||
minetest.log("info", "[playereffects] Server shuts down. Rescuing data into playereffects.mt")
|
||||
playereffects.save_to_file()
|
||||
end)
|
||||
|
||||
@ -447,7 +427,7 @@ minetest.register_globalstep(function(dtime)
|
||||
-- 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 ...")
|
||||
minetest.log("info", "[playereffects] Autosaving mod data to playereffects.mt ...")
|
||||
playereffects.save_to_file()
|
||||
end
|
||||
end)
|
||||
|
Reference in New Issue
Block a user