1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-16 23:40:31 +01:00

Fixed variable error gametime

re-added missing sound and timeout
re-added MFF icon stamina
This commit is contained in:
crabman77 2015-06-19 21:17:23 +02:00
parent 037ed16c87
commit 962fb7b64a
2 changed files with 56 additions and 40 deletions

View File

@ -26,7 +26,7 @@ minetest.register_on_joinplayer(function(player)
hud_elem_type = "statbar", hud_elem_type = "statbar",
position = {x=0.5,y=1}, position = {x=0.5,y=1},
size = {x=24, y=24}, size = {x=24, y=24},
text = "sprint_stamina_icon.png", text = "stamina.png",
number = 20, number = 20,
alignment = {x=0,y=1}, alignment = {x=0,y=1},
offset = {x=-320, y=-186}, offset = {x=-320, y=-186},
@ -38,9 +38,10 @@ minetest.register_on_leaveplayer(function(player)
local playerName = player:get_player_name() local playerName = player:get_player_name()
players[playerName] = nil players[playerName] = nil
end) end)
local gameTime = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
--Get the gametime --Get the gametime
local gameTime = minetest.get_gametime() gameTime = gameTime + dtime
--Loop through all connected players --Loop through all connected players
for playerName,playerInfo in pairs(players) do for playerName,playerInfo in pairs(players) do
@ -52,57 +53,69 @@ minetest.register_globalstep(function(dtime)
else else
players[playerName]["shouldSprint"] = false players[playerName]["shouldSprint"] = false
end end
--Stop sprinting if the player is pressing the LMB or RMB
gameTime = 0 if player:get_player_control()["LMB"] or player:get_player_control()["RMB"] then
local pos = player:getpos() setSprinting(playerName, false)
-- From playerplus : playerInfo["timeOut"] = 3
-- am I near a cactus?
pos.y = pos.y + 0.1
local near = minetest.find_node_near(pos, 1, "default:cactus")
if near then
if player:get_hp() > 0 then
player:set_hp(player:get_hp()-1)
end
end end
--If the player is sprinting, create particles behind him/her if gameTime > 0.4 then
if playerInfo["sprinting"] == true and gameTime % 0.1 == 0 then local pos = player:getpos()
local numParticles = math.random(1, 2) -- From playerplus :
local playerPos = player:getpos() -- am I near a cactus?
local playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]}) pos.y = pos.y + 0.1
if playerNode["name"] ~= "air" then if minetest.find_node_near(pos, 1, "default:cactus") and player:get_hp() > 0 then
for i=1, numParticles, 1 do player:set_hp(player:get_hp()-1)
minetest.add_particle({ end
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}, --If the player is sprinting, create particles behind him/her
acc = {x=0, y=-13, z=0}, if playerInfo["sprinting"] == true then
expirationtime = math.random(), local numParticles = math.random(1, 2)
size = math.random()+0.5, local playerPos = player:getpos()
collisiondetection = true, local playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
vertical = false, if playerNode["name"] ~= "air" then
texture = "sprint_particle.png", 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 = "sprint_particle.png",
})
end
end end
end end
end end
--Adjust player states --Adjust player states
if players[playerName]["shouldSprint"] == true then --Stopped if players[playerName]["shouldSprint"] == true and playerInfo["timeOut"] == 0 then --Stopped
setSprinting(playerName, true) setSprinting(playerName, true)
elseif players[playerName]["shouldSprint"] == false then elseif players[playerName]["shouldSprint"] == false then
setSprinting(playerName, false) setSprinting(playerName, false)
end 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["timeOut"] > 0 then
if playerInfo["sprinting"] == true then playerInfo["timeOut"] = playerInfo["timeOut"] - dtime
playerInfo["stamina"] = playerInfo["stamina"] - dtime if playerInfo["timeOut"] < 0 then
if playerInfo["stamina"] <= 0 then playerInfo["timeOut"] = 0
playerInfo["stamina"] = 0
setSprinting(playerName, false)
end end
else
--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["sprinting"] == true then
playerInfo["stamina"] = playerInfo["stamina"] - dtime
if playerInfo["stamina"] <= 0 then
playerInfo["stamina"] = 0
setSprinting(playerName, false)
playerInfo["timeOut"] = 1
minetest.sound_play("default_breathless",{object=player})
end
end
end
--Increase player's stamina if he/she is not sprinting and his/her stamina is less than SPRINT_STAMINA --Increase player's stamina if he/she is not sprinting and his/her stamina is less than SPRINT_STAMINA
elseif playerInfo["sprinting"] == false and playerInfo["stamina"] < SPRINT_STAMINA then if playerInfo["sprinting"] == false and playerInfo["stamina"] < SPRINT_STAMINA then
playerInfo["stamina"] = playerInfo["stamina"] + dtime playerInfo["stamina"] = playerInfo["stamina"] + dtime
end end
-- Cap stamina at SPRINT_STAMINA -- Cap stamina at SPRINT_STAMINA
@ -120,6 +133,9 @@ minetest.register_globalstep(function(dtime)
end end
end end
end end
if gameTime > 0.4 then
gameTime = 0
end
end) end)
function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting) function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting)

View File

@ -16,7 +16,7 @@ SPRINT_TIMEOUT = 0.5 --Only used if SPRINT_METHOD = 0
if minetest.get_modpath("hudbars") ~= nil then if minetest.get_modpath("hudbars") ~= nil then
hb.register_hudbar("sprint", 0xFFFFFF, "Stamina", hb.register_hudbar("sprint", 0xFFFFFF, "Stamina",
{ bar = "sprint_stamina_bar.png", icon = "sprint_stamina_icon.png" }, { bar = "sprint_stamina_bar.png", icon = "stamina.png" },
SPRINT_STAMINA, SPRINT_STAMINA, SPRINT_STAMINA, SPRINT_STAMINA,
false, "%s: %.1f/%.1f") false, "%s: %.1f/%.1f")
SPRINT_HUDBARS_USED = true SPRINT_HUDBARS_USED = true