forked from minetest-mods/hbsprint
Delimit player attribute to mod namespace
This commit is contained in:
parent
e42e12df3e
commit
577e1a330b
22
init.lua
22
init.lua
@ -34,7 +34,7 @@ end
|
||||
-- Functions
|
||||
|
||||
local function start_sprint(player)
|
||||
if player:get_attribute("sprinting") == "false" then
|
||||
if player:get_attribute("hbsprint:sprinting") == "false" then
|
||||
if monoids then
|
||||
player_monoids.speed:add_change(player, speed, "hbsprint:speed")
|
||||
player_monoids.jump:add_change(player, jump, "hbsprint:jump")
|
||||
@ -45,7 +45,7 @@ local function start_sprint(player)
|
||||
end
|
||||
|
||||
local function stop_sprint(player)
|
||||
if player:get_attribute("sprinting") == "true" then
|
||||
if player:get_attribute("hbsprint:sprinting") == "true" then
|
||||
if monoids then
|
||||
player_monoids.speed:del_change(player, "hbsprint:speed")
|
||||
player_monoids.jump:del_change(player, "hbsprint:jump")
|
||||
@ -56,9 +56,9 @@ local function stop_sprint(player)
|
||||
end
|
||||
|
||||
local function drain_stamina(player)
|
||||
local player_stamina = tonumber(player:get_attribute("stamina"))
|
||||
local player_stamina = tonumber(player:get_attribute("hbsprint:stamina"))
|
||||
if player_stamina > 0 then
|
||||
player:set_attribute("stamina", player_stamina - stamina_drain)
|
||||
player:set_attribute("hbsprint:stamina", player_stamina - stamina_drain)
|
||||
end
|
||||
if hudbars then
|
||||
if autohide and player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end
|
||||
@ -67,9 +67,9 @@ local function drain_stamina(player)
|
||||
end
|
||||
|
||||
local function replenish_stamina(player)
|
||||
local player_stamina = tonumber(player:get_attribute("stamina"))
|
||||
local player_stamina = tonumber(player:get_attribute("hbsprint:stamina"))
|
||||
if player_stamina < 20 then
|
||||
player:set_attribute("stamina", player_stamina + stamina_drain)
|
||||
player:set_attribute("hbsprint:stamina", player_stamina + stamina_drain)
|
||||
end
|
||||
if hudbars then
|
||||
hb.change_hudbar(player, "stamina", player_stamina)
|
||||
@ -138,7 +138,7 @@ end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if hudbars and stamina then hb.init_hudbar(player, "stamina", 20, 20, autohide) end
|
||||
player:set_attribute("stamina", 20)
|
||||
player:set_attribute("hbsprint:stamina", 20)
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
@ -166,7 +166,7 @@ minetest.register_globalstep(function(dtime)
|
||||
local pos = player:get_pos()
|
||||
local ground = minetest.get_node_or_nil({x=pos.x, y=pos.y-1, z=pos.z})
|
||||
local walkable = false
|
||||
local player_stamina = tonumber(player:get_attribute("stamina"))
|
||||
local player_stamina = tonumber(player:get_attribute("hbsprint:stamina"))
|
||||
if starve == "hbhunger" then
|
||||
hunger = tonumber(hbhunger.hunger[name])
|
||||
elseif starve == "hunger_ng" then
|
||||
@ -177,7 +177,7 @@ minetest.register_globalstep(function(dtime)
|
||||
end
|
||||
if player_stamina > 0 and hunger > 6 and walkable then
|
||||
start_sprint(player)
|
||||
player:set_attribute("sprinting", "true")
|
||||
player:set_attribute("hbsprint:sprinting", "true")
|
||||
if stamina then drain_stamina(player) end
|
||||
if starve then drain_hunger(player, hunger, name) end
|
||||
if breath then
|
||||
@ -189,11 +189,11 @@ minetest.register_globalstep(function(dtime)
|
||||
if particles then create_particles(player, name, pos, ground) end
|
||||
else
|
||||
stop_sprint(player)
|
||||
player:set_attribute("sprinting", "false")
|
||||
player:set_attribute("hbsprint:sprinting", "false")
|
||||
end
|
||||
else
|
||||
stop_sprint(player)
|
||||
player:set_attribute("sprinting", "false")
|
||||
player:set_attribute("hbsprint:sprinting", "false")
|
||||
if stamina_timer >= replenish then
|
||||
if stamina then replenish_stamina(player) end
|
||||
stamina_timer = 0
|
||||
|
Loading…
Reference in New Issue
Block a user