1
0
Fork 0

Move timing functions out to globalstep

This commit is contained in:
Brandon 2020-06-20 15:50:58 -04:00
parent 3dbaac7549
commit 12d0c3019e
2 changed files with 212 additions and 55 deletions

View File

@ -3,19 +3,35 @@ local is_poisoned = {}
local is_regenerating = {}
local is_strong = {}
local is_weak = {}
local is_water_breathing = {}
local is_leaping = {}
local is_swift = {}
local timer = 0
minetest.register_globalstep(function(dtime)
-- Check for invisible players
for player, bool in pairs(is_invisible) do
for player, vals in pairs(is_invisible) do
if is_invisible[player] then
mcl_potions._add_spawner(player, "#B0B0B0")
player = player or player:get_luaentity()
is_invisible[player].timer = is_invisible[player].timer + dtime
if player:get_pos() then mcl_potions._add_spawner(player, "#B0B0B0") end
if is_invisible[player].timer >= is_invisible[player].dur then
mcl_potions.make_invisible(player, false)
is_invisible[player] = nil
end
end
end
-- Check for poisoned players
for player, bool in pairs(is_poisoned) do
for player, vals in pairs(is_poisoned) do
if is_poisoned[player] then
@ -24,7 +40,7 @@ minetest.register_globalstep(function(dtime)
is_poisoned[player].timer = is_poisoned[player].timer + dtime
is_poisoned[player].hit_timer = (is_poisoned[player].hit_timer or 0) + dtime
mcl_potions._add_spawner(player, "#225533")
if player:get_pos() then mcl_potions._add_spawner(player, "#225533") end
if is_poisoned[player].hit_timer >= is_poisoned[player].step then
player:set_hp( math.max(player:get_hp() - 1, 1) )
@ -36,6 +52,95 @@ minetest.register_globalstep(function(dtime)
end
end
end
-- Check for regnerating players
for player, vals in pairs(is_regenerating) do
if is_regenerating[player] then
player = player or player:get_luaentity()
is_regenerating[player].timer = is_regenerating[player].timer + dtime
is_regenerating[player].heal_timer = (is_regenerating[player].heal_timer or 0) + dtime
if player:get_pos() then mcl_potions._add_spawner(player, "#A52BB2") end
if is_regenerating[player].heal_timer >= is_regenerating[player].step then
player:set_hp(math.min(player:get_properties().hp_max or 20, player:get_hp() + 1))
is_regenerating[player].heal_timer = 0
end
if is_regenerating[player].timer >= is_regenerating[player].dur then
is_regenerating[player] = nil
end
end
end
-- Check for water breathing players
for player, vals in pairs(is_water_breathing) do
if is_water_breathing[player] then
player = player or player:get_luaentity()
is_water_breathing[player].timer = is_water_breathing[player].timer + dtime
if player:get_pos() then mcl_potions._add_spawner(player, "#0000AA") end
if player:get_breath() then
if player:get_breath() < 10 then player:set_breath(10) end
end
if is_water_breathing[player].timer >= is_water_breathing[player].dur then
is_water_breathing[player] = nil
end
end
end
-- Check for leaping players
for player, vals in pairs(is_leaping) do
if is_leaping[player] then
player = player or player:get_luaentity()
is_leaping[player].timer = is_leaping[player].timer + dtime
if player:get_pos() then mcl_potions._add_spawner(player, "#00CC33") end
if is_leaping[player].timer >= is_leaping[player].dur then
playerphysics.remove_physics_factor(player, "jump", "leaping")
is_leaping[player] = nil
end
end
end
-- Check for swift players
for player, vals in pairs(is_swift) do
if is_swift[player] then
player = player or player:get_luaentity()
is_swift[player].timer = is_swift[player].timer + dtime
if player:get_pos() then mcl_potions._add_spawner(player, "#009999") end
if is_swift[player].timer >= is_swift[player].dur then
playerphysics.remove_physics_factor(player, "speed", "swiftness")
is_swift[player] = nil
end
end
end
end )
@ -43,41 +148,52 @@ end )
-- reset player is_invisible/poison if they go offline
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
player = player or player:get_luaentity()
if is_invisible[name] then
is_invisible[name] = nil
if is_invisible[player] then
is_invisible[player] = nil
end
if is_poisoned[name] then
is_poisoned[name] = nil
if is_poisoned[player] then
is_poisoned[player] = nil
end
if is_regenerating[name] then
is_regenerating[name] = nil
if is_regenerating[player] then
is_regenerating[player] = nil
end
if is_strong[name] then
is_strong[name] = nil
if is_strong[player] then
is_strong[player] = nil
end
if is_weak[name] then
is_weak[name] = nil
if is_weak[player] then
is_weak[player] = nil
end
if is_water_breathing[player] then
is_water_breathing[player] = nil
end
if is_leaping[player] then
is_leaping[player] = nil
end
if is_swift[player] then
is_swift[player] = nil
end
end)
function mcl_potions.invisible(player, toggle)
function mcl_potions.make_invisible(player, toggle)
if not player then return false end
is_invisible[player:get_player_name()] = toggle
if toggle then -- hide player
is_invisible[player].old_size = player:get_properties().visual_size
player:set_properties({visual_size = {x = 0, y = 0}})
player:set_nametag_attributes({color = {a = 0}})
else -- show player
player:set_properties({visual_size = {x = 1, y = 1}})
player:set_properties({visual_size = is_invisible[player].old_size})
player:set_nametag_attributes({color = {a = 255}})
end
@ -165,23 +281,48 @@ function mcl_potions.healing_func(player, hp)
end
function mcl_potions.swiftness_func(player, factor, duration)
if not player:get_meta() then return false end
if not is_swift[player] then
is_swift[player] = {dur = duration, timer = 0}
playerphysics.add_physics_factor(player, "speed", "swiftness", factor)
minetest.after(duration, function() playerphysics.remove_physics_factor(player, "speed", "swiftness") end )
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#009999") end)
else
local victim = is_swift[player]
playerphysics.add_physics_factor(player, "speed", "swiftness", factor)
victim.dur = math.max(duration, victim.dur - victim.timer)
victim.timer = 0
end
end
function mcl_potions.leaping_func(player, factor, duration)
if player:get_meta() then return false end
if not player:get_meta() then return false end
if not is_leaping[player] then
is_leaping[player] = {dur = duration, timer = 0}
playerphysics.add_physics_factor(player, "jump", "leaping", factor)
minetest.after(duration, function() playerphysics.remove_physics_factor(player, "jump", "leaping") end )
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#00CC33") end)
else
local victim = is_leaping[player]
playerphysics.add_physics_factor(player, "jump", "leaping", factor)
victim.dur = math.max(duration, victim.dur - victim.timer)
victim.timer = 0
end
end
function mcl_potions.weakness_func(player, factor, duration)
player:set_attribute("weakness", tostring(factor))
-- print(player:get_player_name().." ".."weakness = "..player:get_attribute("weakness"))
@ -191,6 +332,7 @@ function mcl_potions.weakness_func(player, factor, duration)
end
end
function mcl_potions.poison_func(player, factor, duration)
if not is_poisoned[player] then
@ -208,40 +350,55 @@ function mcl_potions.poison_func(player, factor, duration)
end
end
function mcl_potions.regeneration_func(player, factor, duration)
if not is_regenerating[player:get_player_name()] then
mcl_potions.regenerate(player, true)
for i=1,math.floor(duration/factor) do
minetest.after(i*factor, function()
if player:get_hp() < 20 then
player:set_hp(player:get_hp() + 1)
end
end )
end
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end)
end
minetest.after(duration, function() mcl_potions.regenerate(player, false) end)
if not is_regenerating[player] then
is_regenerating[player] = {step = factor, dur = duration, timer = 0}
else
local victim = is_regenerating[player]
victim.step = math.min(victim.step, factor)
victim.dur = math.max(duration, victim.dur - victim.timer)
victim.timer = 0
end
end
function mcl_potions.invisiblility_func(player, duration)
mcl_potions.invisible(player, true)
minetest.after(duration, function() mcl_potions.invisible(player, false) end )
if not is_invisible[player] then
is_invisible[player] = {dur = duration, timer = 0}
mcl_potions.make_invisible(player, true)
else
local victim = is_invisible[player]
victim.dur = math.max(duration, victim.dur - victim.timer)
victim.timer = 0
end
end
function mcl_potions.water_breathing_func(player, duration)
if minetest.is_player(player) then
for i=1,math.floor(duration) do
minetest.after(i, function()
if player:get_breath() < 10 then
player:set_breath(10)
end
mcl_potions._add_spawner(player, "#0000AA")
end )
end
if not is_water_breathing[player] then
is_water_breathing[player] = {dur = duration, timer = 0}
else
local victim = is_water_breathing[player]
victim.dur = math.max(duration, victim.dur - victim.timer)
victim.timer = 0
end

View File

@ -61,7 +61,7 @@ local function register_splash(name, descr, color, def)
if minetest.is_player(obj) or obj:get_entity_name() then
pos2 = obj:get_pos()
local pos2 = obj:get_pos()
local rad = math.floor(math.sqrt((pos2.x-pos.x)^2 + (pos2.y-pos.y)^2 + (pos2.z-pos.z)^2))
if rad > 0 then def.potion_fun(obj, redux_map[rad]) else def.potion_fun(obj, 1) end