forked from minetest-mods/hbsprint
Compare commits
9 Commits
nalc-1.2.0
...
master
Author | SHA1 | Date | |
---|---|---|---|
b9cb4871a8 | |||
|
92a1e0cddb | ||
b8943369c6 | |||
|
f566d0ff26 | ||
7b8b37a061 | |||
|
1fe580a210 | ||
dc766c1336 | |||
b3773c0470 | |||
|
899d246832 |
11
.github/workflows/build.yml
vendored
Normal file
11
.github/workflows/build.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
on: [push, pull_request]
|
||||||
|
name: build
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: lint
|
||||||
|
uses: Roang-zero1/factorio-mod-luacheck@master
|
||||||
|
with:
|
||||||
|
luacheckrc_url: ""
|
19
.luacheckrc
Normal file
19
.luacheckrc
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
allow_defined_top = true
|
||||||
|
unused_args = false
|
||||||
|
max_line_length = false
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
string = {fields = {"split", "trim"}},
|
||||||
|
table = {fields = {"copy", "getn"}},
|
||||||
|
|
||||||
|
"player_monoids",
|
||||||
|
"playerphysics",
|
||||||
|
"hb",
|
||||||
|
"vector",
|
||||||
|
"hunger_ng",
|
||||||
|
}
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"minetest",
|
||||||
|
"hbhunger"
|
||||||
|
}
|
48
init.lua
48
init.lua
|
@ -84,25 +84,28 @@ local function drain_stamina(player)
|
||||||
player:get_meta():set_float("hbsprint:stamina", player_stamina)
|
player:get_meta():set_float("hbsprint:stamina", player_stamina)
|
||||||
end
|
end
|
||||||
if mod_hudbars then
|
if mod_hudbars then
|
||||||
if autohide and player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end
|
if autohide and
|
||||||
|
player_stamina < hb.get_hudtable("stamina").hudstate[player:get_player_name()].max
|
||||||
|
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 = player:get_meta():get_float("hbsprint:stamina")
|
local player_stamina = player:get_meta():get_float("hbsprint:stamina")
|
||||||
|
local max_stamina = hb.get_hudtable("stamina").hudstate[player:get_player_name()].max
|
||||||
local ctrl = player:get_player_control()
|
local ctrl = player:get_player_control()
|
||||||
if player_stamina < 20 and not ctrl.jump then
|
if player_stamina < max_stamina and not ctrl.jump then
|
||||||
if not ctrl.right and not ctrl.left and not ctrl.down and not ctrl.up and not ctrl.LMB and not ctrl.RMB then
|
if not ctrl.right and not ctrl.left and not ctrl.down and not ctrl.up and not ctrl.LMB and not ctrl.RMB then
|
||||||
player_stamina = math.min(20, player_stamina + standing)
|
player_stamina = math.min(max_stamina, player_stamina + standing)
|
||||||
else
|
else
|
||||||
player_stamina = math.min(20, player_stamina + stamina_heal)
|
player_stamina = math.min(max_stamina, player_stamina + stamina_heal)
|
||||||
end
|
end
|
||||||
player:get_meta():set_float("hbsprint:stamina", player_stamina)
|
player:get_meta():set_float("hbsprint:stamina", player_stamina)
|
||||||
end
|
end
|
||||||
if mod_hudbars then
|
if mod_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 >= max_stamina then hb.hide_hudbar(player, "stamina") end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,8 +133,8 @@ local function is_walkable(ground)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_particles(player, name, ground)
|
local function create_particles(player, name, ground)
|
||||||
local def = minetest.registered_nodes[ground.name]
|
local def = minetest.registered_nodes[ground.name] or {}
|
||||||
local tile = def.tiles[1] or def.inventory_image
|
local tile = def.tiles and def.tiles[1] or def.inventory_image
|
||||||
if type(tile) == "table" then
|
if type(tile) == "table" then
|
||||||
tile = tile.name
|
tile = tile.name
|
||||||
end
|
end
|
||||||
|
@ -182,16 +185,15 @@ 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()
|
||||||
|
local fast = minetest.get_player_privs(name).fast
|
||||||
|
|
||||||
if minetest.get_player_privs(name).fast then
|
if not fast then
|
||||||
return
|
if stamina then
|
||||||
end
|
stamina_timer[name] = (stamina_timer[name] or 0) + dtime
|
||||||
|
end
|
||||||
if stamina then
|
if breath then
|
||||||
stamina_timer[name] = (stamina_timer[name] or 0) + dtime
|
breath_timer[name] = (breath_timer[name] or 0) + dtime
|
||||||
end
|
end
|
||||||
if breath then
|
|
||||||
breath_timer[name] = (breath_timer[name] or 0) + dtime
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local ctrl = player:get_player_control()
|
local ctrl = player:get_player_control()
|
||||||
|
@ -204,7 +206,7 @@ local function sprint_step(player, dtime)
|
||||||
|
|
||||||
if not key_press then
|
if not key_press then
|
||||||
stop_sprint(player)
|
stop_sprint(player)
|
||||||
if stamina and stamina_timer[name] >= replenish then
|
if stamina and not fast and stamina_timer[name] >= replenish then
|
||||||
replenish_stamina(player)
|
replenish_stamina(player)
|
||||||
stamina_timer[name] = 0
|
stamina_timer[name] = 0
|
||||||
end
|
end
|
||||||
|
@ -235,15 +237,15 @@ 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 ground then
|
if (player_stamina > 0 and hunger > starve_limit and ground) or fast then
|
||||||
start_sprint(player)
|
start_sprint(player)
|
||||||
if stamina then drain_stamina(player) end
|
if stamina and not fast then drain_stamina(player) end
|
||||||
if starve then drain_hunger(player, name) end
|
if starve and not fast then drain_hunger(player, name) end
|
||||||
if breath and breath_timer[name] >= 2 then
|
if breath and not fast and breath_timer[name] >= 2 then
|
||||||
drain_breath(player)
|
drain_breath(player)
|
||||||
breath_timer[name] = 0
|
breath_timer[name] = 0
|
||||||
end
|
end
|
||||||
if particles then
|
if particles and ground then
|
||||||
create_particles(player, name, ground)
|
create_particles(player, name, ground)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user