mirror of
https://github.com/minetest-mods/hbsprint.git
synced 2025-01-03 11:07:29 +01:00
Spaces instead of tabs
This commit is contained in:
parent
678f005149
commit
d3254916c2
258
init.lua
258
init.lua
@ -33,164 +33,164 @@ 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 player:get_attribute("sprinting") == "false" 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")
|
||||||
else
|
else
|
||||||
player:set_physics_override({speed = speed, jump = jump})
|
player:set_physics_override({speed = speed, jump = jump})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_sprint(player)
|
local function stop_sprint(player)
|
||||||
if player:get_attribute("sprinting") == "true" 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")
|
||||||
else
|
else
|
||||||
player:set_physics_override({speed = 1, jump = 1})
|
player:set_physics_override({speed = 1, jump = 1})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drain_stamina(player)
|
local function drain_stamina(player)
|
||||||
local 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
|
||||||
if hudbars then
|
if hudbars then
|
||||||
if autohide and player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end
|
if autohide and player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end
|
||||||
hb.change_hudbar(player, "stamina", player_stamina)
|
hb.change_hudbar(player, "stamina", player_stamina)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function replenish_stamina(player)
|
local function replenish_stamina(player)
|
||||||
local 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
|
||||||
if hudbars then
|
if hudbars then
|
||||||
hb.change_hudbar(player, "stamina", player_stamina)
|
hb.change_hudbar(player, "stamina", player_stamina)
|
||||||
if autohide and player_stamina == 20 then hb.hide_hudbar(player, "stamina") end
|
if autohide and player_stamina == 20 then hb.hide_hudbar(player, "stamina") end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drain_hunger(player, hunger, name)
|
local function drain_hunger(player, hunger, name)
|
||||||
if hunger > 0 then
|
if hunger > 0 then
|
||||||
hbhunger.hunger[name] = hunger - starve_drain
|
hbhunger.hunger[name] = hunger - starve_drain
|
||||||
hbhunger.set_hunger_raw(player)
|
hbhunger.set_hunger_raw(player)
|
||||||
end
|
end
|
||||||
end
|
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 < 11 then
|
||||||
player_breath = player_breath - breath_drain
|
player_breath = player_breath - breath_drain
|
||||||
if player_breath > 0 then
|
if player_breath > 0 then
|
||||||
player:set_breath(player_breath)
|
player:set_breath(player_breath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_particles(player, name, pos, ground)
|
local function create_particles(player, name, pos, ground)
|
||||||
if ground and ground.name ~= "air" and ground.name ~= "ignore" then
|
if ground and ground.name ~= "air" and ground.name ~= "ignore" then
|
||||||
local def = minetest.registered_nodes[ground.name]
|
local def = minetest.registered_nodes[ground.name]
|
||||||
local tile = def.tiles[1] or def.inventory_image or ""
|
local tile = def.tiles[1] or def.inventory_image or ""
|
||||||
if type(tile) == "string" then
|
if type(tile) == "string" then
|
||||||
for i = 1, particles do
|
for i = 1, particles do
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = {x = pos.x + math.random(-1,1) * math.random() / 2, y = pos.y + 0.1, z = pos.z + math.random(-1,1) * math.random() / 2},
|
pos = {x = pos.x + math.random(-1,1) * math.random() / 2, y = pos.y + 0.1, z = pos.z + math.random(-1,1) * math.random() / 2},
|
||||||
velocity = {x = 0, y = 5, z = 0},
|
velocity = {x = 0, y = 5, z = 0},
|
||||||
acceleration = {x = 0, y = -13, z = 0},
|
acceleration = {x = 0, y = -13, z = 0},
|
||||||
expirationtime = math.random(),
|
expirationtime = math.random(),
|
||||||
size = math.random() + 0.5,
|
size = math.random() + 0.5,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
texture = tile,
|
texture = tile,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Registrations
|
-- Registrations
|
||||||
|
|
||||||
if minetest.get_modpath("hudbars") ~= nil and stamina then
|
if minetest.get_modpath("hudbars") ~= nil and stamina then
|
||||||
hb.register_hudbar("stamina",
|
hb.register_hudbar("stamina",
|
||||||
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" },
|
||||||
20, 20,
|
20, 20,
|
||||||
false, "%s: %.1f/%.1f")
|
false, "%s: %.1f/%.1f")
|
||||||
hudbars = true
|
hudbars = true
|
||||||
if autohide then
|
if autohide then
|
||||||
hb.hide_hudbar(player, "stamina")
|
hb.hide_hudbar(player, "stamina")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
if hudbars and stamina then hb.init_hudbar(player, "stamina") end
|
if hudbars and stamina then hb.init_hudbar(player, "stamina") end
|
||||||
player:set_attribute("stamina", 20)
|
player:set_attribute("stamina", 20)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
sprint_timer = sprint_timer + dtime
|
sprint_timer = sprint_timer + dtime
|
||||||
stamina_timer = stamina_timer + dtime
|
stamina_timer = stamina_timer + dtime
|
||||||
breath_timer = breath_timer + dtime
|
breath_timer = breath_timer + dtime
|
||||||
if sprint_timer >= sprint_timer_step then
|
if sprint_timer >= sprint_timer_step then
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
local ctrl = player:get_player_control()
|
local ctrl = player:get_player_control()
|
||||||
local key_press = false
|
local key_press = false
|
||||||
if key == "Use" and dir then
|
if key == "Use" and dir then
|
||||||
key_press = ctrl.aux1 and ctrl.up and not ctrl.left and not ctrl.right
|
key_press = ctrl.aux1 and ctrl.up and not ctrl.left and not ctrl.right
|
||||||
elseif key == "Use" and not dir then
|
elseif key == "Use" and not dir then
|
||||||
key_press = ctrl.aux1
|
key_press = ctrl.aux1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if key == "W" and dir then
|
-- if key == "W" and dir then
|
||||||
-- key_press = ctrl.aux1 and ctrl.up or key_press and ctrl.up
|
-- key_press = ctrl.aux1 and ctrl.up or key_press and ctrl.up
|
||||||
-- elseif key == "W" then
|
-- elseif key == "W" then
|
||||||
-- key_press = ctrl.aux1 or key_press and key_tap
|
-- key_press = ctrl.aux1 or key_press and key_tap
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
if key_press then
|
if key_press then
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local hunger = 30
|
local hunger = 30
|
||||||
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"))
|
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
|
||||||
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
|
if player_stamina > 0 and hunger > 9 and walkable then
|
||||||
start_sprint(player)
|
start_sprint(player)
|
||||||
player:set_attribute("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
|
||||||
if breath_timer >= 2 then
|
if breath_timer >= 2 then
|
||||||
drain_breath(player)
|
drain_breath(player)
|
||||||
breath_timer = 0
|
breath_timer = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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)
|
||||||
player:set_attribute("sprinting", "false")
|
player:set_attribute("sprinting", "false")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
stop_sprint(player)
|
stop_sprint(player)
|
||||||
player:set_attribute("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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sprint_timer = 0
|
sprint_timer = 0
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user