Delete Sprint-old and add Sprint mod

Update Sprint mod
(Clique gauche et droit l’arrête, 10secondes de sprint, appuie de
double Z avec 0.5sec d’intervalle, message disant que le sprint ce
termine, etc…)
This commit is contained in:
Ombridride 2014-11-13 02:16:46 +01:00
parent 3c0b7157ac
commit e16cba098c
5 changed files with 160 additions and 54 deletions

View File

@ -1,3 +0,0 @@
Sprint mod v1 by GunshipPenguin
Allows the player to sprint by double tapping w. By default, sprinting will make the player travel 50% faster and allow him/her to jump 10% higher. This can be changed however, by adjusting the SPRINT_SPEED and SPRINT_JUMP variables in the init.lua file.

View File

@ -1,51 +0,0 @@
--Sprint mod for minetest by GunshipPenguin
--CHANGE THESE VARIABLES TO ADJUST SPRINT SPEED/JUMP HEIGHT
--1 represents normal speed/jump height so 1.5 would mean 50% more and 2.0 would be 100% more
SPRINT_SPEED = 1.30 --Speed while sprinting
SPRINT_JUMP = 1.10 --Jump height while sprinting
STOP_ON_CLICK = true --If true, sprinting will stop when either the left mouse button or the right mouse button is pressed
players = {}
minetest.register_on_joinplayer(function(player)
players[player:get_player_name()] = {state = 0, timeOut = 0}
end)
minetest.register_on_leaveplayer(function(player)
playerName = player:get_player_name()
players[playerName] = nil
end)
minetest.register_globalstep(function(dtime)
--Loop through all connected players
for playerName,playerInfo in pairs(players) do
player = minetest.get_player_by_name(playerName)
if player ~= nil then
playerMovement = player:get_player_control()["up"]
if player:get_player_control()["RMB"] or player:get_player_control()["LMB"] and STOP_ON_CLICK == true then
players[playerName]["state"] = 0
player:set_physics_override({speed=1.0, jump=1.0})
end
if playerInfo["state"] == 2 then
players[playerName]["timeOut"] = players[playerName]["timeOut"] + 1
if playerInfo["timeOut"] == 10 then
players[playerName]["timeOut"] = 0
players[playerName]["state"] = 0
end
end
if playerMovement == false and playerInfo["state"] == 3 then --Stopped
players[playerName]["state"] = 0
player:set_physics_override({speed=1.0,jump=1.0})
elseif playerMovement == true and playerInfo["state"] == 0 then --Moving
players[playerName]["state"] = 1
elseif playerMovement == false and playerInfo["state"] == 1 then --Primed
players[playerName]["state"] = 2
elseif playerMovement == true and playerInfo["state"] == 2 then --Sprinting
players[playerName]["state"] = 3
player:set_physics_override({speed=SPRINT_SPEED,jump=SPRINT_JUMP})
end
end
end
end)

0
mods/sprint-old/LICENSE → mods/sprint/LICENSE Executable file → Normal file
View File

52
mods/sprint/README.md Normal file
View File

@ -0,0 +1,52 @@
Sprint Mod For Minetest by GunshipPenguin
Allows the player to sprint by double tapping w. By default,
sprinting will make the player travel 50% faster and allow him/her
to jump 10% higher.
Licence: WTFPL (see LICENCE 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.
SPRINT_SPEED (default 1.5)
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.
SPRINT_JUMP (default 1.1)
How high the player will jump when sprinting as opposed to normal
jump height. Same as SPRINT_SPEED, just controls jump height while
sprinting rather than speed.
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
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 and may be sent a warning depending on
the value of SPRINT_WARN. It ticks back up when the player isn't
sprinting and stops at SPRINT_STAMINA. Set this to a huge value if
you want unlimited sprinting.
SPRINT_TIMEOUT (default 0.5)
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.
SPRINT_WARN (default true)
If the player should be warned that his/her stamina has run out via
the in game chat system. You may want to set this to false if the
notifications get annoying.

108
mods/sprint/init.lua Normal file
View File

@ -0,0 +1,108 @@
--Sprint mod for Minetest by GunshipPenguin
--Configuration variables, these are all explained in README.md
local SPRINT_SPEED = 1.35
local SPRINT_JUMP = 1.1
local SPRINT_STAMINA = 10
local SPRINT_TIMEOUT = 0.5
local SPRINT_WARN = true
STOP_ON_CLICK = true --If true, sprinting will stop when either the left mouse button or the right mouse button is pressed
local players = {}
minetest.register_on_joinplayer(function(player)
players[player:get_player_name()] = {state = 0, timeOut = 0, stamina = SPRINT_STAMINA, moving = false}
end)
minetest.register_on_leaveplayer(function(player)
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"]
-- s'arrete si le joueur fait un clique gauche ou droit
if player:get_player_control()["RMB"] or player:get_player_control()["LMB"] and STOP_ON_CLICK == true then
players[playerName]["state"] = 0
player:set_physics_override({speed=1.0, jump=1.0})
end
--If the player has tapped w longer than SPRINT_TIMEOUT ago, set his/her state to 0
if playerInfo["state"] == 2 then
if playerInfo["timeOut"] + 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
--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
setState(playerName, 2)
elseif players[playerName]["moving"] == true and playerInfo["state"] == 2 then --Sprinting
setState(playerName, 3)
end
--Lower the player's stamina by dtime if he/she is sprinting and set his/her state to 0 if stamina is zero
if playerInfo["state"] == 3 then
playerInfo["stamina"] = playerInfo["stamina"] - dtime
if playerInfo["stamina"] <= 0 then
playerInfo["stamina"] = 0
setState(playerName, 0)
if SPRINT_WARN then
minetest.chat_send_player(playerName, "Your sprint stamina has run out!")
end
end
--Increase player's stamina if he/she is not sprinting and his/her stamina is less than SPRINT_STAMINA
elseif playerInfo["state"] ~= 3 and playerInfo["stamina"] < SPRINT_STAMINA then
playerInfo["stamina"] = playerInfo["stamina"] + dtime
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
if state == 0 then--Stopped
player:set_physics_override({speed=1.0,jump=1.0})
elseif state == 2 then --Primed
players[playerName]["timeOut"] = gameTime
elseif state == 3 then --Sprinting
player:set_physics_override({speed=SPRINT_SPEED,jump=SPRINT_JUMP})
end
return true
end
return false
end