mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-25 18:20:36 +01:00
add hudbars support and optimize
add new hudbars support optimize fonction cactus Active sprint only when we move
This commit is contained in:
parent
d73a89f25d
commit
e849f33780
@ -6,6 +6,14 @@ allow him/her to jump 10% higher. Also adds a stamina bar that goes
|
|||||||
down when the player sprints and goes up when he/she isn't
|
down when the player sprints and goes up when he/she isn't
|
||||||
sprinting.
|
sprinting.
|
||||||
|
|
||||||
|
This mod is compatible with the HUD bars [hudbars] mod, but does
|
||||||
|
not depend on it. In this care, a green HUD bar will be displayed,
|
||||||
|
also showing a number.
|
||||||
|
If this mod is not present, a standard statbar with 0-20
|
||||||
|
“half-arrows” is shown, which is a bit more coarse than the HUD
|
||||||
|
bar version.
|
||||||
|
|
||||||
|
|
||||||
Licence: CC0 (see COPYING file)
|
Licence: CC0 (see COPYING file)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
1
mods/sprint/depends.txt
Normal file
1
mods/sprint/depends.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
hudbars?
|
@ -12,12 +12,17 @@ local staminaHud = {}
|
|||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
players[playerName] = {
|
players[playerName] = {
|
||||||
sprinting = false,
|
sprinting = false,
|
||||||
timeOut = 0,
|
timeOut = 0,
|
||||||
stamina = SPRINT_STAMINA,
|
stamina = SPRINT_STAMINA,
|
||||||
epressed = false,
|
epressed = false,
|
||||||
hud = player:hud_add({
|
}
|
||||||
|
if SPRINT_HUDBARS_USED then
|
||||||
|
hb.init_hudbar(player, "sprint")
|
||||||
|
else
|
||||||
|
players[playerName].hud = player:hud_add({
|
||||||
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},
|
||||||
@ -26,63 +31,69 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
alignment = {x=0,y=1},
|
alignment = {x=0,y=1},
|
||||||
offset = {x=-320, y=-186},
|
offset = {x=-320, y=-186},
|
||||||
}
|
}
|
||||||
),
|
)
|
||||||
}
|
end
|
||||||
end)
|
end)
|
||||||
minetest.register_on_leaveplayer(function(player)
|
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
|
||||||
local player = minetest.get_player_by_name(playerName)
|
local player = minetest.get_player_by_name(playerName)
|
||||||
if player ~= nil then
|
if player ~= nil then
|
||||||
local pos = player:getpos()
|
--no sprint if stand (if in keybinding setting menu, checkbox ["Use" = climb down] is checked , climb down use sprint)
|
||||||
-- From playerplus :
|
|
||||||
-- am I near a cactus?
|
|
||||||
pos.y = pos.y + 0.1
|
|
||||||
local near = minetest.find_node_near(pos, 1, "default:cactus")
|
|
||||||
if near then
|
|
||||||
pos = near
|
|
||||||
|
|
||||||
-- am I touching the cactus? if so it hurts
|
|
||||||
for _,player in ipairs(minetest.get_objects_inside_radius(pos, 1.0)) do
|
|
||||||
if player:get_hp() > 0 then
|
|
||||||
player:set_hp(player:get_hp()-1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Check if they are pressing the e key
|
--Check if they are pressing the e key
|
||||||
players[playerName]["epressed"] = player:get_player_control()["aux1"]
|
local pressed = player:get_player_control()["aux1"]
|
||||||
|
if pressed and (player:get_player_control()["up"] or player:get_player_control()["down"] or player:get_player_control()["left"] or player:get_player_control()["right"]) then
|
||||||
|
players[playerName]["epressed"] = true
|
||||||
|
else
|
||||||
|
players[playerName]["epressed"] = false
|
||||||
|
end
|
||||||
--Stop sprinting if the player is pressing the LMB or RMB
|
--Stop sprinting if the player is pressing the LMB or RMB
|
||||||
if player:get_player_control()["LMB"] or player:get_player_control()["RMB"] then
|
if player:get_player_control()["LMB"] or player:get_player_control()["RMB"] then
|
||||||
setSprinting(playerName, false)
|
setSprinting(playerName, false)
|
||||||
playerInfo["timeOut"] = 3
|
playerInfo["timeOut"] = 3
|
||||||
end
|
end
|
||||||
|
|
||||||
--If the player is sprinting, create particles behind him/her
|
|
||||||
if playerInfo["sprinting"] == true and gameTime % 0.1 == 0 then
|
if gameTime > 0.4 then
|
||||||
local numParticles = math.random(1, 2)
|
gameTime = 0
|
||||||
local playerPos = player:getpos()
|
local pos = player:getpos()
|
||||||
local playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
|
-- From playerplus :
|
||||||
if playerNode["name"] ~= "air" then
|
-- am I near a cactus?
|
||||||
for i=1, numParticles, 1 do
|
pos.y = pos.y + 0.1
|
||||||
minetest.add_particle({
|
local near = minetest.find_node_near(pos, 1, "default:cactus")
|
||||||
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},
|
if near then
|
||||||
vel = {x=0, y=5, z=0},
|
if player:get_hp() > 0 then
|
||||||
acc = {x=0, y=-13, z=0},
|
player:set_hp(player:get_hp()-1)
|
||||||
expirationtime = math.random(),
|
end
|
||||||
size = math.random()+0.5,
|
end
|
||||||
collisiondetection = true,
|
|
||||||
vertical = false,
|
--If the player is sprinting, create particles behind him/her
|
||||||
texture = "default_dirt.png",
|
if playerInfo["sprinting"] == true 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 = "sprint_particle.png",
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -116,10 +127,19 @@ minetest.register_globalstep(function(dtime)
|
|||||||
if 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
|
||||||
|
if playerInfo["stamina"] > SPRINT_STAMINA then
|
||||||
|
playerInfo["stamina"] = SPRINT_STAMINA
|
||||||
|
end
|
||||||
|
|
||||||
--Update the players's hud sprint stamina bar
|
--Update the players's hud sprint stamina bar
|
||||||
local numBars = (playerInfo["stamina"]/SPRINT_STAMINA)*20
|
|
||||||
player:hud_change(playerInfo["hud"], "number", numBars)
|
if SPRINT_HUDBARS_USED then
|
||||||
|
hb.change_hudbar(player, "sprint", playerInfo["stamina"])
|
||||||
|
else
|
||||||
|
local numBars = (playerInfo["stamina"]/SPRINT_STAMINA)*20
|
||||||
|
player:hud_change(playerInfo["hud"], "number", numBars)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -14,6 +14,16 @@ SPRINT_JUMP = 1.1
|
|||||||
SPRINT_STAMINA = 10
|
SPRINT_STAMINA = 10
|
||||||
SPRINT_TIMEOUT = 0.5 --Only used if SPRINT_METHOD = 0
|
SPRINT_TIMEOUT = 0.5 --Only used if SPRINT_METHOD = 0
|
||||||
|
|
||||||
|
if minetest.get_modpath("hudbars") ~= nil then
|
||||||
|
hb.register_hudbar("sprint", 0xFFFFFF, "Stamina",
|
||||||
|
{ bar = "sprint_stamina_bar.png", icon = "stamina.png" },
|
||||||
|
SPRINT_STAMINA, SPRINT_STAMINA,
|
||||||
|
false, "%s: %.1f/%.1f")
|
||||||
|
SPRINT_HUDBARS_USED = true
|
||||||
|
else
|
||||||
|
SPRINT_HUDBARS_USED = false
|
||||||
|
end
|
||||||
|
|
||||||
if SPRINT_METHOD == 0 then
|
if SPRINT_METHOD == 0 then
|
||||||
dofile(minetest.get_modpath("sprint") .. "/wsprint.lua")
|
dofile(minetest.get_modpath("sprint") .. "/wsprint.lua")
|
||||||
elseif SPRINT_METHOD == 1 then
|
elseif SPRINT_METHOD == 1 then
|
||||||
|
BIN
mods/sprint/textures/sprint_particle.png
Normal file
BIN
mods/sprint/textures/sprint_particle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 791 B |
BIN
mods/sprint/textures/sprint_stamina_bar.png
Normal file
BIN
mods/sprint/textures/sprint_stamina_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 B |
@ -11,13 +11,18 @@ local players = {}
|
|||||||
local staminaHud = {}
|
local staminaHud = {}
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
players[playerName] = {
|
players[playerName] = {
|
||||||
state = 0,
|
state = 0,
|
||||||
timeOut = 0,
|
timeOut = 0,
|
||||||
stamina = SPRINT_STAMINA,
|
stamina = SPRINT_STAMINA,
|
||||||
moving = false,
|
moving = false,
|
||||||
hud = player:hud_add({
|
}
|
||||||
|
|
||||||
|
if SPRINT_HUDBARS_USED then
|
||||||
|
hb.init_hudbar(player, "sprint")
|
||||||
|
else
|
||||||
|
players[playerName].hud = player:hud_add({
|
||||||
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},
|
||||||
@ -26,11 +31,11 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
alignment = {x=0,y=1},
|
alignment = {x=0,y=1},
|
||||||
offset = {x=-320, y=-186},
|
offset = {x=-320, y=-186},
|
||||||
}
|
}
|
||||||
),
|
)
|
||||||
}
|
end
|
||||||
end)
|
end)
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
players[playerName] = nil
|
players[playerName] = nil
|
||||||
end)
|
end)
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
@ -82,7 +87,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
size = math.random()+0.5,
|
size = math.random()+0.5,
|
||||||
collisiondetection = true,
|
collisiondetection = true,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
texture = "default_dirt.png",
|
texture = "sprint_particle.png",
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -112,10 +117,19 @@ minetest.register_globalstep(function(dtime)
|
|||||||
elseif playerInfo["state"] ~= 3 and playerInfo["stamina"] < SPRINT_STAMINA then
|
elseif playerInfo["state"] ~= 3 and playerInfo["stamina"] < SPRINT_STAMINA then
|
||||||
playerInfo["stamina"] = playerInfo["stamina"] + dtime
|
playerInfo["stamina"] = playerInfo["stamina"] + dtime
|
||||||
end
|
end
|
||||||
|
-- Cap stamina at SPRINT_STAMINA
|
||||||
|
if playerInfo["stamina"] > SPRINT_STAMINA then
|
||||||
|
playerInfo["stamina"] = SPRINT_STAMINA
|
||||||
|
end
|
||||||
|
|
||||||
--Update the players's hud sprint stamina bar
|
--Update the players's hud sprint stamina bar
|
||||||
local numBars = (playerInfo["stamina"]/SPRINT_STAMINA)*20
|
|
||||||
player:hud_change(playerInfo["hud"], "number", numBars)
|
if SPRINT_HUDBARS_USED then
|
||||||
|
hb.change_hudbar(player, "sprint", playerInfo["stamina"])
|
||||||
|
else
|
||||||
|
local numBars = (playerInfo["stamina"]/SPRINT_STAMINA)*20
|
||||||
|
player:hud_change(playerInfo["hud"], "number", numBars)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user