Minor fixes

This commit is contained in:
MoNTE48 2020-01-21 20:14:10 +01:00
parent fb03b8c049
commit 09fc16db50
5 changed files with 62 additions and 62 deletions

View File

@ -192,7 +192,7 @@ local function on_place_node(place_to, newnode,
type = pointed_thing.type, type = pointed_thing.type,
above = vector.new(pointed_thing.above), above = vector.new(pointed_thing.above),
under = vector.new(pointed_thing.under), under = vector.new(pointed_thing.under),
ref = pointed_thing.ref, ref = pointed_thing.ref
} }
callback(place_to_copy, newnode_copy, placer, callback(place_to_copy, newnode_copy, placer,
oldnode_copy, itemstack, pointed_thing_copy) oldnode_copy, itemstack, pointed_thing_copy)

View File

@ -57,7 +57,7 @@ if playereffects.save then
minetest.log("action", "[playereffects] playereffects opened.") minetest.log("action", "[playereffects] playereffects opened.")
local string = file:read() local string = file:read()
io.close(file) io.close(file)
if(string ~= nil) then if (string ~= nil) then
local savetable = minetest.deserialize(string) local savetable = minetest.deserialize(string)
playereffects.inactive_effects = savetable.inactive_effects playereffects.inactive_effects = savetable.inactive_effects
-- minetest.debug("[playereffects] playereffects successfully read.") -- minetest.debug("[playereffects] playereffects successfully read.")
@ -106,14 +106,14 @@ end
function playereffects.apply_effect_type(effect_type_id, duration, player, repeat_interval_time_left) function playereffects.apply_effect_type(effect_type_id, duration, player, repeat_interval_time_left)
local start_time = os.time() local start_time = os.time()
local is_player = false local is_player = false
if(type(player)=="userdata") then if (type(player)=="userdata") then
if(player.is_player ~= nil) then if (player.is_player ~= nil) then
if(player:is_player() == true) then if (player:is_player() == true) then
is_player = true is_player = true
end end
end end
end end
if(is_player == false) then if (is_player == false) then
minetest.log("error", "[playereffects] Attempted to apply effect type "..effect_type_id.." to a non-player!") minetest.log("error", "[playereffects] Attempted to apply effect type "..effect_type_id.." to a non-player!")
return false return false
end end
@ -125,9 +125,9 @@ function playereffects.apply_effect_type(effect_type_id, duration, player, repea
end end
local metadata local metadata
if(playereffects.effect_types[effect_type_id].repeat_interval == nil) then if (playereffects.effect_types[effect_type_id].repeat_interval == nil) then
local status = playereffects.effect_types[effect_type_id].apply(player) local status = playereffects.effect_types[effect_type_id].apply(player)
if(status == false) then if (status == false) then
minetest.log("action", "[playereffects] Attempt to apply effect type "..effect_type_id.." to player "..playername.." failed!") minetest.log("action", "[playereffects] Attempt to apply effect type "..effect_type_id.." to player "..playername.." failed!")
return false return false
else else
@ -140,39 +140,39 @@ function playereffects.apply_effect_type(effect_type_id, duration, player, repea
local smallest_hudpos local smallest_hudpos
local biggest_hudpos = -1 local biggest_hudpos = -1
local free_hudpos local free_hudpos
if(playereffects.hudinfos[playername] == nil) then if (playereffects.hudinfos[playername] == nil) then
playereffects.hudinfos[playername] = {} playereffects.hudinfos[playername] = {}
end end
local hudinfos = playereffects.hudinfos[playername] local hudinfos = playereffects.hudinfos[playername]
for effect_id, hudinfo in pairs(hudinfos) do for effect_id, hudinfo in pairs(hudinfos) do
local hudpos = hudinfo.pos local hudpos = hudinfo.pos
if(hudpos > biggest_hudpos) then if (hudpos > biggest_hudpos) then
biggest_hudpos = hudpos biggest_hudpos = hudpos
end end
if(smallest_hudpos == nil) then if (smallest_hudpos == nil) then
smallest_hudpos = hudpos smallest_hudpos = hudpos
elseif(hudpos < smallest_hudpos) then elseif (hudpos < smallest_hudpos) then
smallest_hudpos = hudpos smallest_hudpos = hudpos
end end
end end
if(smallest_hudpos == nil) then if (smallest_hudpos == nil) then
free_hudpos = 0 free_hudpos = 0
elseif(smallest_hudpos >= 0) then elseif (smallest_hudpos >= 0) then
free_hudpos = smallest_hudpos - 1 free_hudpos = smallest_hudpos - 1
else else
free_hudpos = biggest_hudpos + 1 free_hudpos = biggest_hudpos + 1
end end
local repeat_interval = playereffects.effect_types[effect_type_id].repeat_interval local repeat_interval = playereffects.effect_types[effect_type_id].repeat_interval
if(repeat_interval ~= nil) then if (repeat_interval ~= nil) then
if(repeat_interval_time_left == nil) then if (repeat_interval_time_left == nil) then
repeat_interval_time_left = repeat_interval repeat_interval_time_left = repeat_interval
end end
end end
--[[ show no more than 10 effects on the screen, so that hud_update does not need to be called so often ]] --[[ show no more than 10 effects on the screen, so that hud_update does not need to be called so often ]]
local text_id, icon_id local text_id, icon_id
if(free_hudpos <= 10) then if (free_hudpos <= 10) then
text_id, icon_id = playereffects.hud_effect(effect_type_id, player, 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 = { local hudinfo = {
text_id = text_id, text_id = text_id,
@ -197,7 +197,7 @@ function playereffects.apply_effect_type(effect_type_id, duration, player, repea
playereffects.effects[effect_id] = effect playereffects.effects[effect_id] = effect
if(repeat_interval ~= nil) then if (repeat_interval ~= nil) then
minetest.after(repeat_interval_time_left, playereffects.repeater, effect_id, duration, player, 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 else
minetest.after(duration, function(effect_id) playereffects.cancel_effect(effect_id) end, effect_id) minetest.after(duration, function(effect_id) playereffects.cancel_effect(effect_id) end, effect_id)
@ -208,12 +208,12 @@ end
function playereffects.repeater(effect_id, repetitions, player, apply) function playereffects.repeater(effect_id, repetitions, player, apply)
local effect = playereffects.effects[effect_id] local effect = playereffects.effects[effect_id]
if(effect ~= nil) then if (effect ~= nil) then
local repetitions = effect.time_left local repetitions = effect.time_left
apply(player) apply(player)
repetitions = repetitions - 1 repetitions = repetitions - 1
effect.time_left = repetitions effect.time_left = repetitions
if(repetitions <= 0) then if (repetitions <= 0) then
playereffects.cancel_effect(effect_id) playereffects.cancel_effect(effect_id)
else else
local repeat_interval = playereffects.effect_types[effect.effect_type_id].repeat_interval local repeat_interval = playereffects.effect_types[effect.effect_type_id].repeat_interval
@ -233,11 +233,11 @@ end
function playereffects.cancel_effect_type(effect_type_id, cancel_all, playername) function playereffects.cancel_effect_type(effect_type_id, cancel_all, playername)
local effects = playereffects.get_player_effects(playername) local effects = playereffects.get_player_effects(playername)
if(cancel_all==nil) then cancel_all = false end if (cancel_all==nil) then cancel_all = false end
for e=1, #effects do for e=1, #effects do
if(effects[e].effect_type_id == effect_type_id) then if (effects[e].effect_type_id == effect_type_id) then
playereffects.cancel_effect(effects[e].effect_id) playereffects.cancel_effect(effects[e].effect_id)
if(cancel_all==false) then if (cancel_all==false) then
return return
end end
end end
@ -251,7 +251,7 @@ function playereffects.cancel_effect_group(groupname, playername)
local thesegroups = playereffects.effect_types[effect.effect_type_id].groups local thesegroups = playereffects.effect_types[effect.effect_type_id].groups
local delete = false local delete = false
for g=1,#thesegroups do for g=1,#thesegroups do
if(thesegroups[g] == groupname) then if (thesegroups[g] == groupname) then
playereffects.cancel_effect(effect.effect_id) playereffects.cancel_effect(effect.effect_id)
break break
end end
@ -262,7 +262,7 @@ end
function playereffects.get_remaining_effect_time(effect_id) function playereffects.get_remaining_effect_time(effect_id)
local now = os.time() local now = os.time()
local effect = playereffects.effects[effect_id] local effect = playereffects.effects[effect_id]
if(effect ~= nil) then if (effect ~= nil) then
return (effect.time_left - os.difftime(now, effect.start_time)) return (effect.time_left - os.difftime(now, effect.start_time))
else else
return nil return nil
@ -271,14 +271,14 @@ 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
local player = minetest.get_player_by_name(effect.playername) local player = minetest.get_player_by_name(effect.playername)
local hudinfo = playereffects.hudinfos[effect.playername][effect_id] local hudinfo = playereffects.hudinfos[effect.playername][effect_id]
if(hudinfo ~= nil) then if (hudinfo ~= nil) then
if(hudinfo.text_id~=nil) then if (hudinfo.text_id~=nil) then
player:hud_remove(hudinfo.text_id) player:hud_remove(hudinfo.text_id)
end end
if(hudinfo.icon_id~=nil) then if (hudinfo.icon_id~=nil) then
player:hud_remove(hudinfo.icon_id) player:hud_remove(hudinfo.icon_id)
end end
playereffects.hudinfos[effect.playername][effect_id] = nil playereffects.hudinfos[effect.playername][effect_id] = nil
@ -289,10 +289,10 @@ function playereffects.cancel_effect(effect_id)
end end
function playereffects.get_player_effects(playername) function playereffects.get_player_effects(playername)
if(minetest.get_player_by_name(playername) ~= nil) then if (minetest.get_player_by_name(playername) ~= nil) then
local effects = {} local effects = {}
for k,v in pairs(playereffects.effects) do for k,v in pairs(playereffects.effects) do
if(v.playername == playername) then if (v.playername == playername) then
table.insert(effects, v) table.insert(effects, v)
end end
end end
@ -319,7 +319,7 @@ function playereffects.save_to_file()
local inactive_effects = {} local inactive_effects = {}
for id,effecttable in pairs(playereffects.inactive_effects) do for id,effecttable in pairs(playereffects.inactive_effects) do
local playername = id local playername = id
if(inactive_effects[playername] == nil) then if (inactive_effects[playername] == nil) then
inactive_effects[playername] = {} inactive_effects[playername] = {}
end end
for i=1,#effecttable do for i=1,#effecttable do
@ -328,7 +328,7 @@ function playereffects.save_to_file()
end end
for id,effect in pairs(playereffects.effects) do for id,effect in pairs(playereffects.effects) do
local new_duration, new_repeat_duration local new_duration, new_repeat_duration
if(playereffects.effect_types[effect.effect_type_id].repeat_interval ~= nil) then if (playereffects.effect_types[effect.effect_type_id].repeat_interval ~= nil) then
new_duration = effect.time_left new_duration = effect.time_left
new_repeat_duration = effect.repeat_interval_time_left - os.difftime(save_time, effect.repeat_interval_start_time) new_repeat_duration = effect.repeat_interval_time_left - os.difftime(save_time, effect.repeat_interval_start_time)
else else
@ -344,7 +344,7 @@ function playereffects.save_to_file()
playername = effect.playername, playername = effect.playername,
metadata = effect.metadata metadata = effect.metadata
} }
if(inactive_effects[effect.playername] == nil) then if (inactive_effects[effect.playername] == nil) then
inactive_effects[effect.playername] = {} inactive_effects[effect.playername] = {}
end end
table.insert(inactive_effects[effect.playername], new_effect) table.insert(inactive_effects[effect.playername], new_effect)
@ -370,8 +370,8 @@ end
--[[ Cancel all effects on player death ]] --[[ Cancel all effects on player death ]]
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
local effects = playereffects.get_player_effects(player:get_player_name()) local effects = playereffects.get_player_effects(player:get_player_name())
for e=1,#effects do for e = 1, #effects do
if(playereffects.effect_types[effects[e].effect_type_id].cancel_on_death == true) then if (playereffects.effect_types[effects[e].effect_type_id].cancel_on_death == true) then
playereffects.cancel_effect(effects[e].effect_id) playereffects.cancel_effect(effects[e].effect_id)
end end
end end
@ -385,7 +385,7 @@ minetest.register_on_leaveplayer(function(player)
playereffects.hud_clear(player) playereffects.hud_clear(player)
if(playereffects.inactive_effects[playername] == nil) then if (playereffects.inactive_effects[playername] == nil) then
playereffects.inactive_effects[playername] = {} playereffects.inactive_effects[playername] = {}
end end
for e=1,#effects do for e=1,#effects do
@ -408,7 +408,7 @@ minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name() local playername = player:get_player_name()
-- load all the effects again (if any) -- load all the effects again (if any)
if(playereffects.inactive_effects[playername] ~= nil) then if (playereffects.inactive_effects[playername] ~= nil) then
for i=1,#playereffects.inactive_effects[playername] do for i=1,#playereffects.inactive_effects[playername] do
local effect = playereffects.inactive_effects[playername][i] local effect = playereffects.inactive_effects[playername][i]
playereffects.apply_effect_type(effect.effect_type_id, effect.time_left, player, effect.repeat_interval_time_left) playereffects.apply_effect_type(effect.effect_type_id, effect.time_left, player, effect.repeat_interval_time_left)
@ -442,17 +442,17 @@ end)
--[=[ HUD ]=] --[=[ HUD ]=]
function playereffects.hud_update(player) function playereffects.hud_update(player)
if(playereffects.use_hud == true) then if (playereffects.use_hud == true) then
local now = os.time() local now = os.time()
local playername = player:get_player_name() local playername = player:get_player_name()
local hudinfos = playereffects.hudinfos[playername] local hudinfos = playereffects.hudinfos[playername]
if(hudinfos ~= nil) then if (hudinfos ~= nil) then
for effect_id, hudinfo in pairs(hudinfos) do for effect_id, hudinfo in pairs(hudinfos) do
local effect = playereffects.effects[effect_id] local effect = playereffects.effects[effect_id]
if(effect ~= nil and hudinfo.text_id ~= nil) then if (effect ~= nil and hudinfo.text_id ~= nil) then
local description = playereffects.effect_types[effect.effect_type_id].description local description = playereffects.effect_types[effect.effect_type_id].description
local repeat_interval = playereffects.effect_types[effect.effect_type_id].repeat_interval local repeat_interval = playereffects.effect_types[effect.effect_type_id].repeat_interval
if(repeat_interval ~= nil) then if (repeat_interval ~= nil) then
local repeat_interval_time_left = os.difftime(effect.repeat_interval_start_time + effect.repeat_interval_time_left, now) 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("s") .. ")") player:hud_change(hudinfo.text_id, "text", description .. " ("..tostring(effect.time_left).."/"..tostring(repeat_interval_time_left) .. " " .. S("s") .. ")")
else else
@ -466,16 +466,16 @@ function playereffects.hud_update(player)
end end
function playereffects.hud_clear(player) function playereffects.hud_clear(player)
if(playereffects.use_hud == true) then if (playereffects.use_hud == true) then
local playername = player:get_player_name() local playername = player:get_player_name()
local hudinfos = playereffects.hudinfos[playername] local hudinfos = playereffects.hudinfos[playername]
if(hudinfos ~= nil) then if (hudinfos ~= nil) then
for effect_id, hudinfo in pairs(hudinfos) do for effect_id, hudinfo in pairs(hudinfos) do
local effect = playereffects.effects[effect_id] local effect = playereffects.effects[effect_id]
if(hudinfo.text_id ~= nil) then if (hudinfo.text_id ~= nil) then
player:hud_remove(hudinfo.text_id) player:hud_remove(hudinfo.text_id)
end end
if(hudinfo.icon_id ~= nil) then if (hudinfo.icon_id ~= nil) then
player:hud_remove(hudinfo.icon_id) player:hud_remove(hudinfo.icon_id)
end end
playereffects.hudinfos[playername][effect_id] = nil playereffects.hudinfos[playername][effect_id] = nil
@ -487,41 +487,41 @@ end
function playereffects.hud_effect(effect_type_id, player, pos, time_left, repeat_interval_time_left) function playereffects.hud_effect(effect_type_id, player, pos, time_left, repeat_interval_time_left)
local text_id, icon_id local text_id, icon_id
local effect_type = playereffects.effect_types[effect_type_id] local effect_type = playereffects.effect_types[effect_type_id]
if(playereffects.use_hud == true and effect_type.hidden == false) then if (playereffects.use_hud == true and effect_type.hidden == false) then
local color local color
if(playereffects.effect_types[effect_type_id].cancel_on_death == true) then if (playereffects.effect_types[effect_type_id].cancel_on_death == true) then
color = 0xFFFFFF color = 0xFFFFFF
else else
color = 0xF0BAFF color = 0xF0BAFF
end end
local description = playereffects.effect_types[effect_type_id].description local description = playereffects.effect_types[effect_type_id].description
local text local text
if(repeat_interval_time_left ~= nil) then if (repeat_interval_time_left ~= nil) then
text = description .. " ("..tostring(time_left).."/"..tostring(repeat_interval_time_left) .. " " .. S("s") .. ")" text = description .. " ("..tostring(time_left).."/"..tostring(repeat_interval_time_left) .. " " .. S("s") .. ")"
else else
text = description .. " ("..tostring(time_left).." " .. S("s") .. ")" text = description .. " ("..tostring(time_left).." " .. S("s") .. ")"
end end
text_id = player:hud_add({ text_id = player:hud_add({
hud_elem_type = "text", hud_elem_type = "text",
position = { x = 1, y = 0.3 }, position = {x = 1, y = 0.3},
name = "effect_"..effect_type_id, name = "effect_"..effect_type_id,
text = text, text = text,
scale = { x = 170, y = 20}, scale = {x = 170, y = 20},
alignment = { x = -1, y = 0 }, alignment = {x = -1, y = 0},
direction = 1, direction = 1,
number = color, number = color,
offset = { x = -5, y = pos*30 } offset = {x = -5, y = pos * 30}
}) })
if(playereffects.effect_types[effect_type_id].icon ~= nil) then if (playereffects.effect_types[effect_type_id].icon ~= nil) then
icon_id = player:hud_add({ icon_id = player:hud_add({
hud_elem_type = "image", hud_elem_type = "image",
scale = { x = 1, y = 1 }, scale = {x = 1, y = 1},
position = { x = 1, y = 0.3 }, position = { x = 1, y = 0.3 },
name = "effect_icon_"..effect_type_id, name = "effect_icon_"..effect_type_id,
text = playereffects.effect_types[effect_type_id].icon, text = playereffects.effect_types[effect_type_id].icon,
alignment = { x = -1, y=0 }, alignment = {x = -1, y = 0},
direction = 0, direction = 0,
offset = { x = -230, y = pos*30 }, offset = {x = -230, y = pos * 30},
}) })
end end
else else