mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-22 16:09:33 +01:00
Cause exhaustion by sprinting
This commit is contained in:
parent
2b484d8da3
commit
d13546246e
1 changed files with 17 additions and 2 deletions
|
@ -16,6 +16,8 @@ minetest.register_on_joinplayer(function(player)
|
||||||
sprinting = false,
|
sprinting = false,
|
||||||
timeOut = 0,
|
timeOut = 0,
|
||||||
shouldSprint = false,
|
shouldSprint = false,
|
||||||
|
lastPos = player:getpos(),
|
||||||
|
sprintDistance = 0,
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
@ -37,10 +39,22 @@ minetest.register_globalstep(function(dtime)
|
||||||
players[playerName]["shouldSprint"] = false
|
players[playerName]["shouldSprint"] = false
|
||||||
end
|
end
|
||||||
|
|
||||||
--If the player is sprinting, create particles behind him/her
|
local playerPos = player:getpos()
|
||||||
|
--If the player is sprinting, create particles behind and cause exhaustion
|
||||||
if playerInfo["sprinting"] == true and gameTime % 0.1 == 0 then
|
if playerInfo["sprinting"] == true and gameTime % 0.1 == 0 then
|
||||||
|
|
||||||
|
-- Exhaust player for sprinting
|
||||||
|
local lastPos = players[playerName].lastPos
|
||||||
|
local dist = vector.distance({x=lastPos.x, y=0, z=lastPos.z}, {x=playerPos.x, y=0, z=playerPos.z})
|
||||||
|
players[playerName].sprintDistance = players[playerName].sprintDistance + dist
|
||||||
|
if players[playerName].sprintDistance >= 1 then
|
||||||
|
local superficial = math.floor(players[playerName].sprintDistance)
|
||||||
|
mcl_hunger.exhaust(playerName, mcl_hunger.EXHAUST_SPRINT * superficial)
|
||||||
|
players[playerName].sprintDistance = players[playerName].sprintDistance - superficial
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Sprint dirt particles
|
||||||
local numParticles = math.random(1, 2)
|
local numParticles = math.random(1, 2)
|
||||||
local playerPos = player:getpos()
|
|
||||||
local playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
|
local playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
|
||||||
if playerNode["name"] ~= "air" then
|
if playerNode["name"] ~= "air" then
|
||||||
for i=1, numParticles, 1 do
|
for i=1, numParticles, 1 do
|
||||||
|
@ -59,6 +73,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
--Adjust player states
|
--Adjust player states
|
||||||
|
players[playerName].lastPos = playerPos
|
||||||
if players[playerName]["shouldSprint"] == true then --Stopped
|
if players[playerName]["shouldSprint"] == true then --Stopped
|
||||||
local sprinting
|
local sprinting
|
||||||
-- Prevent sprinting if standing on soul sand or hungry
|
-- Prevent sprinting if standing on soul sand or hungry
|
||||||
|
|
Loading…
Reference in a new issue