1
0
Fork 0

Dump unused code in mcl_sprint mod

This commit is contained in:
Wuzzy 2017-05-20 19:18:37 +02:00
parent d13546246e
commit 8114ecf263
4 changed files with 104 additions and 268 deletions

View File

@ -1,54 +1,17 @@
Sprint Mod for MineClone 2
# Sprint Mod for MineClone 2
Forked from [sprint] by GunshipPenguin
Allows the player to sprint by either double tapping w or pressing e.
## Description
Allows the player to sprint by pressing the “Use” key (default: E).
By default, sprinting will make the player travel 80% faster and
allow him/her to jump 10% higher.
Licence: CC0 (see COPYING file)
---
This mod can be configured by changing the variables declared in
the start of init.lua. The following is a brief explanation of each
one.
mcl_sprint.METHOD (default 1)
What a player has to do to start sprinting. 0 = double tap w, 1 = press e.
Note that if you have the fast privlige, and have the fast
speed turned on, you will run very, very fast. You can toggle this
by pressing j.
NOTE: Method 0 is UNTESTED!
mcl_sprint.SPEED (default 1.5)
## Mod developer settings (`init.lua`)
### `mcl_sprint.SPEED`
How fast the player will move when sprinting as opposed to normal
movement speed. 1.0 represents normal speed so 1.5 would mean that a
sprinting player would travel 50% faster than a walking player and
2.4 would mean that a sprinting player would travel 140% faster than
a walking player.
mcl_sprint.JUMP (default 1.1)
How high the player will jump when sprinting as opposed to normal
jump height. Same as mcl_sprint.SPEED, just controls jump height while
sprinting rather than speed.
mcl_sprint.STAMINA (default 20)
How long the player can sprint for in seconds. Each player has a
stamina variable assigned to them, it is initially set to
mcl_sprint.STAMINA and can go no higher. When the player is sprinting,
this variable ticks down once each second, and when it reaches 0,
the player stops sprinting. It ticks back up when the player isn't
sprinting and stops at mcl_sprint.STAMINA. Set this to a huge value if
you want unlimited sprinting.
mcl_sprint.TIMEOUT (default 0.5)
Only used if mcl_sprint.METHOD = 0.
How much time the player has after releasing w, to press w again and
start sprinting. Setting this too high will result in unwanted
sprinting and setting it too low will result in it being
difficult/impossible to sprint.

View File

@ -1,109 +0,0 @@
--[[
Sprint mod for Minetest by GunshipPenguin
To the extent possible under law, the author(s)
have dedicated all copyright and related and neighboring rights
to this software to the public domain worldwide. This software is
distributed without any warranty.
]]
local players = {}
minetest.register_on_joinplayer(function(player)
local playerName = player:get_player_name()
players[playerName] = {
sprinting = false,
timeOut = 0,
shouldSprint = false,
lastPos = player:getpos(),
sprintDistance = 0,
}
end)
minetest.register_on_leaveplayer(function(player)
local playerName = player:get_player_name()
players[playerName] = nil
end)
minetest.register_globalstep(function(dtime)
--Get the gametime
local gameTime = minetest.get_gametime()
--Loop through all connected players
for playerName,playerInfo in pairs(players) do
local player = minetest.get_player_by_name(playerName)
if player ~= nil then
--Check if the player should be sprinting
if player:get_player_control()["aux1"] and player:get_player_control()["up"] then
players[playerName]["shouldSprint"] = true
else
players[playerName]["shouldSprint"] = false
end
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
-- 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 playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
if playerNode["name"] ~= "air" then
for i=1, numParticles, 1 do
minetest.add_particle({
pos = {x=playerPos["x"]+math.random(-1,1)*math.random()/2,y=playerPos["y"]+0.1,z=playerPos["z"]+math.random(-1,1)*math.random()/2},
vel = {x=0, y=5, z=0},
acc = {x=0, y=-13, z=0},
expirationtime = math.random(),
size = math.random()+0.5,
collisiondetection = true,
vertical = false,
texture = "default_dirt.png",
})
end
end
end
--Adjust player states
players[playerName].lastPos = playerPos
if players[playerName]["shouldSprint"] == true then --Stopped
local sprinting
-- Prevent sprinting if standing on soul sand or hungry
if playerplus[playerName].nod_stand == "mcl_nether:soul_sand" or (mcl_hunger and mcl_hunger.get_hunger(player) <= 6) then
sprinting = false
else
sprinting = true
end
setSprinting(playerName, sprinting)
elseif players[playerName]["shouldSprint"] == false then
setSprinting(playerName, false)
end
end
end
end)
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
players[playerName]["sprinting"] = sprinting
-- Don't overwrite physics when standing on soul sand
if playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand" then
if sprinting == true then
player:set_physics_override({speed=mcl_sprint.SPEED})
elseif sprinting == false then
player:set_physics_override({speed=1.0})
end
return true
end
end
return false
end

View File

@ -10,16 +10,105 @@ distributed without any warranty.
--Configuration variables, these are all explained in README.md
mcl_sprint = {}
mcl_sprint.METHOD = 1
mcl_sprint.SPEED = 1.3
mcl_sprint.TIMEOUT = 0.5 --Only used if mcl_sprint.METHOD = 0
if mcl_sprint.METHOD == 0 then
-- UNTESTED
dofile(minetest.get_modpath("mcl_sprint") .. "/wsprint.lua")
elseif mcl_sprint.METHOD == 1 then
dofile(minetest.get_modpath("mcl_sprint") .. "/esprint.lua")
else
minetest.log("error", "[mcl_sprint] mcl_sprint.METHOD is not set properly, using [E] to sprint.")
dofile(minetest.get_modpath("mcl_sprint") .. "/esprint.lua")
local players = {}
minetest.register_on_joinplayer(function(player)
local playerName = player:get_player_name()
players[playerName] = {
sprinting = false,
timeOut = 0,
shouldSprint = false,
lastPos = player:getpos(),
sprintDistance = 0,
}
end)
minetest.register_on_leaveplayer(function(player)
local playerName = player:get_player_name()
players[playerName] = nil
end)
minetest.register_globalstep(function(dtime)
--Get the gametime
local gameTime = minetest.get_gametime()
--Loop through all connected players
for playerName,playerInfo in pairs(players) do
local player = minetest.get_player_by_name(playerName)
if player ~= nil then
--Check if the player should be sprinting
if player:get_player_control()["aux1"] and player:get_player_control()["up"] then
players[playerName]["shouldSprint"] = true
else
players[playerName]["shouldSprint"] = false
end
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
-- 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 playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
if playerNode["name"] ~= "air" then
for i=1, numParticles, 1 do
minetest.add_particle({
pos = {x=playerPos["x"]+math.random(-1,1)*math.random()/2,y=playerPos["y"]+0.1,z=playerPos["z"]+math.random(-1,1)*math.random()/2},
vel = {x=0, y=5, z=0},
acc = {x=0, y=-13, z=0},
expirationtime = math.random(),
size = math.random()+0.5,
collisiondetection = true,
vertical = false,
texture = "default_dirt.png",
})
end
end
end
--Adjust player states
players[playerName].lastPos = playerPos
if players[playerName]["shouldSprint"] == true then --Stopped
local sprinting
-- Prevent sprinting if standing on soul sand or hungry
if playerplus[playerName].nod_stand == "mcl_nether:soul_sand" or (mcl_hunger and mcl_hunger.get_hunger(player) <= 6) then
sprinting = false
else
sprinting = true
end
setSprinting(playerName, sprinting)
elseif players[playerName]["shouldSprint"] == false then
setSprinting(playerName, false)
end
end
end
end)
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
players[playerName]["sprinting"] = sprinting
-- Don't overwrite physics when standing on soul sand
if playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand" then
if sprinting == true then
player:set_physics_override({speed=mcl_sprint.SPEED})
elseif sprinting == false then
player:set_physics_override({speed=1.0})
end
return true
end
end
return false
end

View File

@ -1,107 +0,0 @@
--[[
Sprint mod for Minetest by GunshipPenguin
To the extent possible under law, the author(s)
have dedicated all copyright and related and neighboring rights
to this software to the public domain worldwide. This software is
distributed without any warranty.
]]
local players = {}
minetest.register_on_joinplayer(function(player)
local playerName = player:get_player_name()
players[playerName] = {
state = 0,
timeOut = 0,
moving = false,
}
end)
minetest.register_on_leaveplayer(function(player)
local playerName = player:get_player_name()
players[playerName] = nil
end)
minetest.register_globalstep(function(dtime)
--Get the gametime
local gameTime = minetest.get_gametime()
--Loop through all connected players
for playerName,playerInfo in pairs(players) do
local player = minetest.get_player_by_name(playerName)
if player ~= nil then
--Check if they are moving or not
players[playerName]["moving"] = player:get_player_control()["up"]
--If the player has tapped w longer than mcl_sprint.TIMEOUT ago, set his/her state to 0
if playerInfo["state"] == 2 then
if playerInfo["timeOut"] + mcl_sprint.TIMEOUT < gameTime then
players[playerName]["timeOut"] = nil
setState(playerName, 0)
end
--If the player is sprinting, create particles behind him/her
elseif playerInfo["state"] == 3 and gameTime % 0.1 == 0 then
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"]})
if playerNode["name"] ~= "air" then
for i=1, numParticles, 1 do
minetest.add_particle({
pos = {x=playerPos["x"]+math.random(-1,1)*math.random()/2,y=playerPos["y"]+0.1,z=playerPos["z"]+math.random(-1,1)*math.random()/2},
vel = {x=0, y=5, z=0},
acc = {x=0, y=-13, z=0},
expirationtime = math.random(),
size = math.random()+0.5,
collisiondetection = true,
vertical = false,
texture = "default_dirt.png",
})
end
end
end
-- Prevent sprinting if standing on soul sand or hungry
local can_sprint = (playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand") or (mcl_hunger and mcl_hunger.get_hunger(player) <= 6)
--Adjust player states
if players[playerName]["moving"] == false and playerInfo["state"] == 3 then --Stopped
setState(playerName, 0)
elseif players[playerName]["moving"] == true and playerInfo["state"] == 0 then --Moving
setState(playerName, 1)
elseif players[playerName]["moving"] == false and playerInfo["state"] == 1 then --Primed
local sprinting
if can_sprint then
setState(playerName, 0)
else
setState(playerName, 2)
end
elseif players[playerName]["moving"] == true and playerInfo["state"] == 2 then --Sprinting
if can_sprint then
setState(playerName, 1)
else
setState(playerName, 3)
end
end
end
end
end)
function setState(playerName, state) --Sets the state of a player (0=stopped, 1=moving, 2=primed, 3=sprinting)
local player = minetest.get_player_by_name(playerName)
local gameTime = minetest.get_gametime()
if players[playerName] then
players[playerName]["state"] = state
-- Don't overwrite physics when standing on soul sand
if playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand" then
if state == 0 then--Stopped
player:set_physics_override({speed=1.0})
elseif state == 2 then --Primed
players[playerName]["timeOut"] = gameTime
elseif state == 3 then --Sprinting
player:set_physics_override({speed=mcl_sprint.SPEED})
end
return true
end
end
return false
end