Add CSM sprinting with double tap forward

This commit is contained in:
Elias Fleckenstein 2021-03-05 09:26:13 +01:00
parent d57db0444f
commit 31441a02e5
2 changed files with 25 additions and 2 deletions

View File

@ -33,3 +33,8 @@ mgvalleys_spflags = noaltitude_chill,noaltitude_dry,nohumid_rivers,vary_river_de
keepInventory = false
dedicated_server_step = 0.001
# Clientmodding to support official client
enable_client_modding = true
csm_restriction_flags = 0
enable_mod_channels = true

View File

@ -31,9 +31,11 @@ minetest.register_on_joinplayer(function(player)
sprinting = false,
timeOut = 0,
shouldSprint = false,
clientSprint = false,
lastPos = player:get_pos(),
sprintDistance = 0,
fov = 1.0
fov = 1.0,
channel = minetest.mod_channel_join("mcl_sprint:" .. playerName),
}
end)
minetest.register_on_leaveplayer(function(player)
@ -41,6 +43,11 @@ minetest.register_on_leaveplayer(function(player)
players[playerName] = nil
end)
local function cancelClientSprinting(name)
players[name].channel:send_all("")
players[name].clientSprint = false
end
local function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting)
local player = minetest.get_player_by_name(playerName)
if players[playerName] then
@ -97,6 +104,16 @@ local function get_top_node_tile(param2, paramtype2)
end
end
minetest.register_on_modchannel_message(function(channel_name, sender, message)
if channel_name == "mcl_sprint:" .. sender then
players[sender].clientSprint = minetest.is_yes(message)
end
end)
minetest.register_on_respawnplayer(function(player)
cancelClientSprinting(player:get_player_name())
end)
minetest.register_globalstep(function(dtime)
--Get the gametime
local gameTime = minetest.get_gametime()
@ -107,7 +124,7 @@ minetest.register_globalstep(function(dtime)
if player ~= nil then
local ctrl = player:get_player_control()
--Check if the player should be sprinting
if ctrl.aux1 and ctrl.up and not ctrl.sneak then
if players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then
players[playerName]["shouldSprint"] = true
else
players[playerName]["shouldSprint"] = false
@ -160,6 +177,7 @@ minetest.register_globalstep(function(dtime)
-- Prevent sprinting if hungry or sleeping
if (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) or (player:get_meta():get_string("mcl_beds:sleeping") == "true") then
sprinting = false
cancelClientSprinting(playerName)
else
sprinting = true
end