Some changes in the code I forgot of
parent
ded521653b
commit
ff190ad1c6
|
@ -1,4 +1,4 @@
|
|||
-- Common config values
|
||||
-- Common config values.
|
||||
minetest_wadsprint.STAMINA_MAX_VALUE = 100
|
||||
minetest_wadsprint.DYSPNEA_THRESHOLD_VALUE = 3
|
||||
minetest_wadsprint.SAVE_PLAYERS_STATS_TO_FILE = true
|
||||
|
@ -7,8 +7,8 @@ minetest_wadsprint.PLAYER_STATS_UPDATE_PERIOD_SECONDS = 1
|
|||
minetest_wadsprint.PLAYER_CONTROLS_CHECK_PERIOD_SECONDS = 0.2
|
||||
minetest_wadsprint.SPRINT_SPEED_MODIFIER_COEFFICIENT = 3.8
|
||||
minetest_wadsprint.SPRINT_JUMP_HEIGHT_MODIFIER_COEFFICIENT = 1.1
|
||||
minetest_wadsprint.SPRINT_STAMINA_DECREASE_PER_UPDATE_PERIOD_COEFFICIENT = 0.005 -- 1 means 100% decrease
|
||||
minetest_wadsprint.SPRINT_STAMINA_INCREASE_PER_UPDATE_PERIOD_COEFFICIENT = 0.001 -- 1 means 100% increase
|
||||
minetest_wadsprint.SPRINT_STAMINA_DECREASE_PER_UPDATE_PERIOD_COEFFICIENT = 0.0005 -- 1 means 100% decrease
|
||||
minetest_wadsprint.SPRINT_STAMINA_INCREASE_PER_UPDATE_PERIOD_COEFFICIENT = 0.0001 -- 1 means 100% increase
|
||||
-- Config values for `hudbars` mod (totally optional, applied only if installed).
|
||||
-- @see http://repo.or.cz/minetest_hudbars.git/blob_plain/HEAD:/API.md
|
||||
minetest_wadsprint.HUDBARS_IDENTIFIER = "sprint"
|
||||
|
|
36
init.lua
36
init.lua
|
@ -1,19 +1,26 @@
|
|||
-- WAD SPRINTING minetest (https://minetest.net) mod (https://dev.minetest.net/Intro)
|
||||
-- @link https://github.com/aa6/minetest_wadsprint
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/lib_savetable.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/lib_file_exists.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/lib_eventemitter.lua")
|
||||
minetest_wadsprint =
|
||||
{
|
||||
api = {},
|
||||
players = {},
|
||||
api = { events = EventEmitter:new() },
|
||||
players =
|
||||
{
|
||||
-- playername:
|
||||
-- name: playername
|
||||
-- stamina:
|
||||
-- is_sprinting:
|
||||
-- is_ready_to_sprint:
|
||||
-- is_sprinting_physics_on:
|
||||
},
|
||||
version = io.open(minetest.get_modpath(minetest.get_current_modname()).."/VERSION","r"):read("*all"),
|
||||
savedstats = { index = {} },
|
||||
savetablepath = minetest.get_modpath(minetest.get_current_modname()).."/saved_players_stats.dat",
|
||||
}
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/config.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/init_hudbars.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/lib_savetable.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/lib_file_exists.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/lib_eventemitter.lua")
|
||||
minetest_wadsprint.api.events = EventEmitter:new()
|
||||
|
||||
function minetest_wadsprint.api.stats(player_name)
|
||||
local player = minetest_wadsprint.players[player_name]
|
||||
|
@ -26,9 +33,11 @@ function minetest_wadsprint.api.stats(player_name)
|
|||
is_ready_to_sprint = player.is_ready_to_sprint,
|
||||
is_sprinting_physics_on = player.is_sprinting_physics_on,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- minetest_wadsprint.api.stamina(player_name) to get stamina
|
||||
-- minetest_wadsprint.api.stamina(player_name, 0.5) to set stamina to half of STAMINA_MAX_VALUE
|
||||
function minetest_wadsprint.api.stamina(player_name,stamina_rate)
|
||||
local player = minetest_wadsprint.players[player_name]
|
||||
if player ~= nil then
|
||||
|
@ -40,6 +49,7 @@ function minetest_wadsprint.api.stamina(player_name,stamina_rate)
|
|||
end
|
||||
end
|
||||
|
||||
-- minetest_wadsprint.api.addstamina(player_name, 0.1) to add 10% of STAMINA_MAX_VALUE
|
||||
function minetest_wadsprint.api.addstamina(player_name,stamina_rate_change)
|
||||
local player = minetest_wadsprint.players[player_name]
|
||||
if player ~= nil then
|
||||
|
@ -70,18 +80,18 @@ function minetest_wadsprint.set_stamina(player,stamina_value)
|
|||
minetest_wadsprint.api.events:emit(
|
||||
"dyspnea",
|
||||
{
|
||||
player = player,
|
||||
value = true,
|
||||
name = "dyspnea",
|
||||
value = true,
|
||||
player = player,
|
||||
}
|
||||
)
|
||||
elseif old_stamina_value < minetest_wadsprint.DYSPNEA_THRESHOLD_VALUE and player.stamina >= minetest_wadsprint.DYSPNEA_THRESHOLD_VALUE then
|
||||
minetest_wadsprint.api.events:emit(
|
||||
"dyspnea",
|
||||
{
|
||||
player = player,
|
||||
value = false,
|
||||
name = "dyspnea",
|
||||
value = false,
|
||||
player = player,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
@ -222,9 +232,9 @@ minetest.register_on_joinplayer(function(player_obj)
|
|||
minetest_wadsprint.api.events:emit(
|
||||
"dyspnea",
|
||||
{
|
||||
player = player,
|
||||
value = true,
|
||||
name = "dyspnea",
|
||||
value = true,
|
||||
player = player,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in New Issue