Players: Add sprinting
parent
53cb3a0d8f
commit
1862296612
|
@ -0,0 +1 @@
|
||||||
|
movement_speed_walk = 3.7
|
|
@ -2,8 +2,10 @@
|
||||||
-- Adapted from Minetest 0.4 mod: players
|
-- Adapted from Minetest 0.4 mod: players
|
||||||
-- See README.txt for licensing and other information.
|
-- See README.txt for licensing and other information.
|
||||||
|
|
||||||
|
local modpath = minetest.get_modpath("players")
|
||||||
|
|
||||||
-- Load API
|
-- Load API
|
||||||
dofile(minetest.get_modpath("players").."/api.lua")
|
dofile(modpath.."/api.lua")
|
||||||
|
|
||||||
-- [register] Default players appearance
|
-- [register] Default players appearance
|
||||||
players.register_model("character.b3d", {
|
players.register_model("character.b3d", {
|
||||||
|
@ -20,3 +22,10 @@ players.register_model("character.b3d", {
|
||||||
},
|
},
|
||||||
default_model = true,
|
default_model = true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
---
|
||||||
|
--- Load Extra Resources
|
||||||
|
---
|
||||||
|
|
||||||
|
-- Load Sprinting
|
||||||
|
dofile(modpath.."/sprint.lua")
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
-- players/sprint.lua
|
||||||
|
|
||||||
|
local sprinting = {}
|
||||||
|
local secondary = {}
|
||||||
|
local SPEED = minetest.settings:get("sprint_speed") or 1.5
|
||||||
|
local PRIMARY = minetest.settings:get("sprint_primary") or "aux1"
|
||||||
|
local SECOND = minetest.settings:get("sprint_second") or "up"
|
||||||
|
local PARTICLE_NUM = minetest.settings:get("sprint_particle_num") or 1
|
||||||
|
local ALLOW_SEC = minetest.settings:get("sprint_enable_second")
|
||||||
|
local ALLOW_PARTICLES = minetest.settings:get("sprint_particles")
|
||||||
|
|
||||||
|
---
|
||||||
|
--- Functions
|
||||||
|
---
|
||||||
|
|
||||||
|
local function start_sprint(player, name, trigger)
|
||||||
|
player:set_physics_override({speed = SPEED})
|
||||||
|
sprinting[name] = {is = true, trigger = trigger}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function stop_sprint(player, name)
|
||||||
|
player:set_physics_override({speed = 1})
|
||||||
|
sprinting[name] = {is = false}
|
||||||
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
--- Registrations
|
||||||
|
---
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local ctrl = player:get_player_control()
|
||||||
|
|
||||||
|
if not sprinting[name] then
|
||||||
|
sprinting[name] = {is = false}
|
||||||
|
end
|
||||||
|
|
||||||
|
local spr = sprinting[name]
|
||||||
|
|
||||||
|
-- Primary Key
|
||||||
|
if ctrl[PRIMARY] and ctrl.up and not spr.is then
|
||||||
|
start_sprint(player, name, "primary")
|
||||||
|
elseif ((not ctrl[PRIMARY] and spr.is) or
|
||||||
|
(ctrl[PRIMARY] and not ctrl.up and spr.is))
|
||||||
|
and spr.trigger == "primary" then
|
||||||
|
stop_sprint(player, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Secondary Key
|
||||||
|
if ALLOW_SEC ~= "false" and SECOND and SECOND ~= "" and spr.trigger ~= "primary" then
|
||||||
|
if not secondary[name] then
|
||||||
|
secondary[name] = {count = 0, time = 0, last = false}
|
||||||
|
end
|
||||||
|
|
||||||
|
if ctrl[SECOND] ~= secondary[name].last then
|
||||||
|
if secondary[name].time > 0.3 and not spr.is and
|
||||||
|
secondary[name].count > 0 and secondary[name].count < 3 then
|
||||||
|
secondary[name] = {count = 0, time = 0, last = false}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if secondary[name].count < 3 and ctrl[SECOND] ~= secondary[name].last then
|
||||||
|
secondary[name].count = secondary[name].count + 1
|
||||||
|
secondary[name].last = ctrl[SECOND]
|
||||||
|
end
|
||||||
|
|
||||||
|
if (secondary[name].count == 3 and ctrl[SECOND]) and ctrl.up and not spr.is then
|
||||||
|
start_sprint(player, name, "secondary")
|
||||||
|
elseif ((secondary[name].count > 3 or not ctrl[SECOND]) or not ctrl.up) and
|
||||||
|
spr.is then
|
||||||
|
stop_sprint(player, name)
|
||||||
|
secondary[name] = {count = 0, time = 0, last = false}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not spr.is and secondary[name].count ~= 0 then
|
||||||
|
secondary[name].time = secondary[name].time + dtime
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Particles
|
||||||
|
if ALLOW_PARTICLES ~= "false" and spr.is then
|
||||||
|
local pos = player:get_pos()
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
|
||||||
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
if node and node.name ~= "air" and node.name ~= "ignore" then
|
||||||
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
local tile = def.tiles[1] or def.inventory_image or ""
|
||||||
|
if type(tile) == "string" and PARTICLE_NUM ~= 0 then
|
||||||
|
minetest.add_particlespawner({
|
||||||
|
time = 0.5,
|
||||||
|
amount = PARTICLE_NUM,
|
||||||
|
minpos = {x = pos.x - 0.5, y = pos.y + 1.1, z = pos.z - 0.5},
|
||||||
|
maxpos = {x = pos.x + 0.5, y = pos.y + 1.1, z = pos.z + 0.5},
|
||||||
|
minvel = {x = 0, y = 3, z = 0},
|
||||||
|
minvel = {x = 0, y = 5, z = 0},
|
||||||
|
minacc = {x = 0, y = -10, z = 0},
|
||||||
|
maxacc = {x = 0, y = -13, z = 0},
|
||||||
|
minexptime = 0.5,
|
||||||
|
maxexptime = 1,
|
||||||
|
minsize = 0.5,
|
||||||
|
maxsize = 2,
|
||||||
|
collisiondetection = true,
|
||||||
|
vertical = false,
|
||||||
|
texture = tile,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
|
@ -54,7 +54,36 @@
|
||||||
# There shouldn't be too much settings per category; settings that shouldn't be
|
# There shouldn't be too much settings per category; settings that shouldn't be
|
||||||
# modified by the "average user" should be in (sub-)categories called "Advanced".
|
# modified by the "average user" should be in (sub-)categories called "Advanced".
|
||||||
|
|
||||||
|
[Mapgen]
|
||||||
|
|
||||||
# If this is enabled, the top textures of some nodes will be rotated
|
# If this is enabled, the top textures of some nodes will be rotated
|
||||||
# as the map generates and when the node is placed for increased variety.
|
# as the map generates and when the node is placed for increased variety.
|
||||||
# Only nodes in the `rotate.lua` `nodes` table are effected.
|
# Only nodes in the `rotate.lua` `nodes` table are effected.
|
||||||
mapgen_rotate_textures (Mapgen: Randomly rotate textures) bool false
|
mapgen_rotate_textures (Mapgen: Randomly rotate textures) bool false
|
||||||
|
|
||||||
|
[Player Physics]
|
||||||
|
|
||||||
|
# Primary key that triggers a sprint speed multiplier when held.
|
||||||
|
# This defaults to aux1, which is also used if fast_move is enabled.
|
||||||
|
sprint_primary (Primary Sprint Key) string aux1
|
||||||
|
|
||||||
|
# Secondary key that triggers the speed and jump multipliers when double-pressed
|
||||||
|
# and held for the duration. This is most convenient to map to the "up" ("forward")
|
||||||
|
# key, as it allows seemlessly enabling sprint by simply double-tapping forward
|
||||||
|
# without having to move your hand to reach another key.
|
||||||
|
sprint_second (Secondary Sprint Key) string up
|
||||||
|
|
||||||
|
# If disabled, the secondary sprint key (sprint_second) is not allowed.
|
||||||
|
sprint_enable_second (Double-tap Secondary Key to Sprint) bool true
|
||||||
|
|
||||||
|
# Speed multiplier applied when sprinting.
|
||||||
|
# Sprint key configured with the sprint_primary setting.
|
||||||
|
sprint_speed (Speed Multiplier) float 1.5
|
||||||
|
|
||||||
|
# If enabled, particles are shown behind the player when sprinting, taking on
|
||||||
|
# the top texture of the node that the player is walking on.
|
||||||
|
sprint_particles (Enable Particles While Sprinting) bool false
|
||||||
|
|
||||||
|
# Configures the number of particles to be added behind the player as they
|
||||||
|
# sprint. A greater number gives more variety but causes more load on the server.
|
||||||
|
sprint_particle_num (Max Number of Particles to Spawn) int 1 0 10
|
||||||
|
|
Loading…
Reference in New Issue