Prevent sprinting if hunger level <= 6

This commit is contained in:
Wuzzy 2017-02-21 16:44:26 +01:00
parent 2e7ce77985
commit d36beaf64f
5 changed files with 13 additions and 10 deletions

View file

@ -19,6 +19,7 @@ What a player has to do to start sprinting. 0 = double tap w, 1 = press e.
Note that if you have the fast privlige, and have the fast
speed turned on, you will run very, very fast. You can toggle this
by pressing j.
NOTE: Method 0 is UNTESTED!
mcl_sprint.SPEED (default 1.5)

View file

@ -1 +1,2 @@
playerplus
mcl_hunger

View file

@ -61,8 +61,8 @@ minetest.register_globalstep(function(dtime)
--Adjust player states
if players[playerName]["shouldSprint"] == true then --Stopped
local sprinting
-- Prevent sprinting if standing on soul sand
if playerplus[playerName].nod_stand == "mcl_nether:soul_sand" then
-- Prevent sprinting if standing on soul sand or hungry
if playerplus[playerName].nod_stand == "mcl_nether:soul_sand" or mcl_hunger.get_hunger(player) <= 6 then
sprinting = false
else
sprinting = true

View file

@ -15,6 +15,7 @@ mcl_sprint.SPEED = 1.3
mcl_sprint.TIMEOUT = 0.5 --Only used if mcl_sprint.METHOD = 0
if mcl_sprint.METHOD == 0 then
-- UNTESTED
dofile(minetest.get_modpath("mcl_sprint") .. "/wsprint.lua")
elseif mcl_sprint.METHOD == 1 then
dofile(minetest.get_modpath("mcl_sprint") .. "/esprint.lua")

View file

@ -60,6 +60,8 @@ minetest.register_globalstep(function(dtime)
end
end
-- Prevent sprinting if standing on soul sand or hungry
local can_sprint = (playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand") and (mcl_hunger.get_hunger(player) <= 6)
--Adjust player states
if players[playerName]["moving"] == false and playerInfo["state"] == 3 then --Stopped
setState(playerName, 0)
@ -67,18 +69,16 @@ minetest.register_globalstep(function(dtime)
setState(playerName, 1)
elseif players[playerName]["moving"] == false and playerInfo["state"] == 1 then --Primed
local sprinting
-- Prevent sprinting if standing on soul sand
if not playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand" then
setState(playerName, 2)
else
if can_sprint then
setState(playerName, 0)
else
setState(playerName, 2)
end
elseif players[playerName]["moving"] == true and playerInfo["state"] == 2 then --Sprinting
-- Prevent sprinting if standing on soul sand
if not playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand" then
setState(playerName, 3)
else
if can_sprint then
setState(playerName, 1)
else
setState(playerName, 3)
end
end