Fix multiplayer bug, supposedly

This commit is contained in:
tacotexmex 2017-08-24 08:01:33 +02:00
parent fd5df30755
commit e48bcbd411

View File

@ -19,10 +19,8 @@ if breath ~= false then breath = true end
local sprint_timer_step = 0.5 local sprint_timer_step = 0.5
local sprint_timer = 0 local sprint_timer = 0
local player_stamina = 20
local stamina_timer = 0 local stamina_timer = 0
local breath_timer = 0 local breath_timer = 0
local sprinting = false
local hudbars = false local hudbars = false
local starve = false local starve = false
local monoids = false local monoids = false
@ -34,7 +32,7 @@ if minetest.get_modpath("player_monoids") ~= nil then monoids = true else monoid
-- Functions -- Functions
local function start_sprint(player) local function start_sprint(player)
if not sprinting then if player:get_attribute("sprinting") == "false" then
if monoids then if monoids then
player_monoids.speed:add_change(player, speed, "hbsprint:speed") player_monoids.speed:add_change(player, speed, "hbsprint:speed")
player_monoids.jump:add_change(player, jump, "hbsprint:jump") player_monoids.jump:add_change(player, jump, "hbsprint:jump")
@ -45,7 +43,7 @@ local function start_sprint(player)
end end
local function stop_sprint(player) local function stop_sprint(player)
if sprinting then if player:get_attribute("sprinting") == "true" then
if monoids then if monoids then
player_monoids.speed:del_change(player, "hbsprint:speed") player_monoids.speed:del_change(player, "hbsprint:speed")
player_monoids.jump:del_change(player, "hbsprint:jump") player_monoids.jump:del_change(player, "hbsprint:jump")
@ -56,7 +54,7 @@ local function stop_sprint(player)
end end
local function drain_stamina(player) local function drain_stamina(player)
player_stamina = tonumber(player:get_attribute("stamina")) local player_stamina = tonumber(player:get_attribute("stamina"))
if player_stamina > 0 then if player_stamina > 0 then
player:set_attribute("stamina", player_stamina - stamina_drain) player:set_attribute("stamina", player_stamina - stamina_drain)
end end
@ -67,7 +65,7 @@ local function drain_stamina(player)
end end
local function replenish_stamina(player) local function replenish_stamina(player)
player_stamina = tonumber(player:get_attribute("stamina")) local player_stamina = tonumber(player:get_attribute("stamina"))
if player_stamina < 20 then if player_stamina < 20 then
player:set_attribute("stamina", player_stamina + stamina_drain) player:set_attribute("stamina", player_stamina + stamina_drain)
end end
@ -121,7 +119,7 @@ if minetest.get_modpath("hudbars") ~= nil and stamina then
0xFFFFFF, 0xFFFFFF,
"Stamina", "Stamina",
{ bar = "sprint_stamina_bar.png", icon = "sprint_stamina_icon.png", bgicon = "sprint_stamina_bgicon.png" }, { bar = "sprint_stamina_bar.png", icon = "sprint_stamina_icon.png", bgicon = "sprint_stamina_bgicon.png" },
player_stamina, player_stamina, 20, 20,
false, "%s: %.1f/%.1f") false, "%s: %.1f/%.1f")
hudbars = true hudbars = true
hb.hide_hudbar(player, "stamina") hb.hide_hudbar(player, "stamina")
@ -158,6 +156,7 @@ minetest.register_globalstep(function(dtime)
local pos = player:get_pos() local pos = player:get_pos()
local ground = minetest.get_node_or_nil({x=pos.x, y=pos.y-1, z=pos.z}) local ground = minetest.get_node_or_nil({x=pos.x, y=pos.y-1, z=pos.z})
local walkable = false local walkable = false
local player_stamina = tonumber(player:get_attribute("stamina"))
if starve then if starve then
hunger = tonumber(hbhunger.hunger[name]) hunger = tonumber(hbhunger.hunger[name])
end end
@ -166,7 +165,7 @@ minetest.register_globalstep(function(dtime)
end end
if player_stamina > 0 and hunger > 9 and walkable then if player_stamina > 0 and hunger > 9 and walkable then
start_sprint(player) start_sprint(player)
sprinting = true player:set_attribute("sprinting", "true")
if stamina then drain_stamina(player) end if stamina then drain_stamina(player) end
if starve then drain_hunger(player, hunger, name) end if starve then drain_hunger(player, hunger, name) end
if breath then if breath then
@ -178,11 +177,11 @@ minetest.register_globalstep(function(dtime)
if particles then create_particles(player, name, pos, ground) end if particles then create_particles(player, name, pos, ground) end
else else
stop_sprint(player) stop_sprint(player)
sprinting = false player:set_attribute("sprinting", "false")
end end
else else
stop_sprint(player) stop_sprint(player)
sprinting = false player:set_attribute("sprinting", "false")
if stamina_timer >= replenish then if stamina_timer >= replenish then
if stamina then replenish_stamina(player) end if stamina then replenish_stamina(player) end
stamina_timer = 0 stamina_timer = 0