mirror of
https://github.com/minetest-mods/hbsprint.git
synced 2025-01-09 17:40:40 +01:00
Do not run monoids call unnecessarily
This commit is contained in:
parent
2294ddb62d
commit
42fa7addbb
17
init.lua
17
init.lua
@ -15,6 +15,7 @@ local sprint_timer_step = 0.5
|
|||||||
local sprint_timer = 0
|
local sprint_timer = 0
|
||||||
local player_stamina = 20
|
local player_stamina = 20
|
||||||
local stamina_timer = 0
|
local stamina_timer = 0
|
||||||
|
local sprinting = false
|
||||||
|
|
||||||
if dir == nil then dir = true end
|
if dir == nil then dir = true end
|
||||||
if stamina ~= false then stamina = true end
|
if stamina ~= false then stamina = true end
|
||||||
@ -26,22 +27,26 @@ if not minetest.get_modpath("player_monoids") then monoids = false end
|
|||||||
-- Functions
|
-- Functions
|
||||||
|
|
||||||
local function start_sprint(player)
|
local function start_sprint(player)
|
||||||
|
if not sprinting then
|
||||||
if monoids then
|
if monoids then
|
||||||
player_monoids.speed:add_change(player, speed, "sprint:sprint")
|
player_monoids.speed:add_change(player, speed, "hbsprint:speed")
|
||||||
player_monoids.jump:add_change(player, jump, "sprint:jump")
|
player_monoids.jump:add_change(player, jump, "hbsprint:jump")
|
||||||
else
|
else
|
||||||
player:set_physics_override({speed = speed, jump = jump})
|
player:set_physics_override({speed = speed, jump = jump})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function stop_sprint(player)
|
local function stop_sprint(player)
|
||||||
|
if sprinting then
|
||||||
if monoids then
|
if monoids then
|
||||||
player_monoids.speed:del_change(player, "sprint:sprint")
|
player_monoids.speed:del_change(player, "hbsprint:speed")
|
||||||
player_monoids.jump:del_change(player, "sprint:jump")
|
player_monoids.jump:del_change(player, "hbsprint:jump")
|
||||||
else
|
else
|
||||||
player:set_physics_override({speed = 1, jump = 1})
|
player:set_physics_override({speed = 1, jump = 1})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function drain_stamina(player)
|
local function drain_stamina(player)
|
||||||
player_stamina = tonumber(player:get_attribute("stamina"))
|
player_stamina = tonumber(player:get_attribute("stamina"))
|
||||||
@ -141,18 +146,20 @@ minetest.register_globalstep(function(dtime)
|
|||||||
if ground ~= nil then
|
if ground ~= nil then
|
||||||
walkable = minetest.registered_nodes[ground.name].walkable
|
walkable = minetest.registered_nodes[ground.name].walkable
|
||||||
end
|
end
|
||||||
if player_stamina > 0 and hunger > 9 and walkable then --AND IF NOT WATER!
|
if player_stamina > 0 and hunger > 9 and walkable then
|
||||||
start_sprint(player)
|
start_sprint(player)
|
||||||
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 particles then create_particles(player, name, pos, ground) end
|
if particles then create_particles(player, name, pos, ground) end
|
||||||
end
|
end
|
||||||
|
sprinting = true
|
||||||
else
|
else
|
||||||
stop_sprint(player)
|
stop_sprint(player)
|
||||||
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
|
||||||
end
|
end
|
||||||
|
sprinting = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sprint_timer = 0
|
sprint_timer = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user