forked from minetest-mods/hbsprint
more improvements
This commit is contained in:
parent
49305c18d3
commit
84a2243d12
44
init.lua
44
init.lua
@ -40,6 +40,7 @@ end
|
|||||||
if minetest.settings:get_bool("creative_mode") then
|
if minetest.settings:get_bool("creative_mode") then
|
||||||
starve = false
|
starve = false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Functions
|
-- Functions
|
||||||
|
|
||||||
local function start_sprint(player)
|
local function start_sprint(player)
|
||||||
@ -110,22 +111,28 @@ end
|
|||||||
|
|
||||||
local function drain_breath(player)
|
local function drain_breath(player)
|
||||||
local player_breath = player:get_breath()
|
local player_breath = player:get_breath()
|
||||||
if player_breath < 11 then
|
if player_breath < player:get_properties().breath_max then
|
||||||
player_breath = math.max(0, player_breath - breath_drain)
|
player_breath = math.max(0, player_breath - breath_drain)
|
||||||
player:set_breath(player_breath)
|
player:set_breath(player_breath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_particles(player, name, pos, ground)
|
local function is_walkable(ground)
|
||||||
if not ground or ground.name == "air" or ground.name == "ignore" then
|
local ground_def = minetest.registered_nodes[ground.name]
|
||||||
return
|
return ground_def and (ground_def.walkable and ground_def.liquidtype == "none")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function create_particles(player, name, ground)
|
||||||
local def = minetest.registered_nodes[ground.name]
|
local def = minetest.registered_nodes[ground.name]
|
||||||
local tile = def.tiles[1] or def.inventory_image
|
local tile = def.tiles[1] or def.inventory_image
|
||||||
if type(tile) ~= "string" then
|
if type(tile) == "table" then
|
||||||
|
tile = tile.name
|
||||||
|
end
|
||||||
|
if not tile then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local pos = player:get_pos()
|
||||||
local rand = function() return math.random(-1,1) * math.random() / 2 end
|
local rand = function() return math.random(-1,1) * math.random() / 2 end
|
||||||
for i = 1, particles do
|
for i = 1, particles do
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
@ -169,6 +176,10 @@ end)
|
|||||||
local function sprint_step(player, dtime)
|
local function sprint_step(player, dtime)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
|
if minetest.get_player_privs(name).fast then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if stamina then
|
if stamina then
|
||||||
stamina_timer[name] = (stamina_timer[name] or 0) + dtime
|
stamina_timer[name] = (stamina_timer[name] or 0) + dtime
|
||||||
end
|
end
|
||||||
@ -193,12 +204,17 @@ local function sprint_step(player, dtime)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = player:get_pos()
|
local ground_pos = player:get_pos()
|
||||||
local ground = minetest.get_node_or_nil({x=pos.x, y=pos.y-1, z=pos.z})
|
ground_pos.y = math.floor(ground_pos.y)
|
||||||
local walkable = false
|
-- check if player is reasonably near a walkable node
|
||||||
if ground ~= nil then
|
local ground
|
||||||
local ground_def = minetest.registered_nodes[ground.name]
|
for _, y_off in ipairs({0, -1, -2}) do
|
||||||
walkable = ground_def and (ground_def.walkable or ground_def.liquidtype ~= "none")
|
local testpos = vector.add(ground_pos, {x=0, y=y_off, z=0})
|
||||||
|
local testnode = minetest.get_node_or_nil(testpos)
|
||||||
|
if testnode ~= nil and is_walkable(testnode) then
|
||||||
|
ground = testnode
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_stamina = 1
|
local player_stamina = 1
|
||||||
@ -212,7 +228,7 @@ local function sprint_step(player, dtime)
|
|||||||
hunger = hunger_ng.get_hunger_information(name).hunger.exact
|
hunger = hunger_ng.get_hunger_information(name).hunger.exact
|
||||||
end
|
end
|
||||||
|
|
||||||
if player_stamina > 0 and hunger > starve_limit and walkable then
|
if player_stamina > 0 and hunger > starve_limit and ground 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, name) end
|
if starve then drain_hunger(player, name) end
|
||||||
@ -221,7 +237,7 @@ local function sprint_step(player, dtime)
|
|||||||
breath_timer[name] = 0
|
breath_timer[name] = 0
|
||||||
end
|
end
|
||||||
if particles then
|
if particles then
|
||||||
create_particles(player, name, pos, ground)
|
create_particles(player, name, ground)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
stop_sprint(player)
|
stop_sprint(player)
|
||||||
|
Loading…
Reference in New Issue
Block a user