[Mod] SuperSprint! [supersprint]

Post Reply
User avatar
jas
Member
Posts: 507
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas
Contact:

[Mod] SuperSprint! [supersprint]

by jas » Post

license: lgpl v2.1+
video: https://www.youtube.com/watch?v=eL5WfOsgiU8
video2: https://www.youtube.com/watch?v=yW5UHaqOrbA

Movement in Minetest is very important to me.

If I had only one mod to use, it would be this one.

TODO:
I may remove the player_api dependency, not sure if it's needed.

Ps. It's AUX1 or "Special" to sprint, and then you can sneak jump. For example, by default if you hold [E] and move around*, you'll be sprinting, and it is in this state only that you may sneak jump.

Code: Select all

local sprinting = {}
local players = {}
local accelerating = {}

local function control(player, field)
	local controls = player:get_player_control()
	if field then
		return controls[field]
	else
		return controls
	end
end

local function physics(player, enabled)
	if enabled then
		player:set_physics_override({
			speed = 2,
			jump = 1.5,
			gravity = 0.96,
			new_move = false,
			sneak_glitch = true,
			sneak = true,
		})
	else
		player:set_physics_override({
			speed = 1,
			jump = 1,
			gravity = 1,
			new_move = true,
			sneak_glitch = false,
			sneak = true,
		})
	end
end

local function boost(player, old_pos)
	local name = player:get_player_name()
	local vel = player:get_player_velocity()
	local sneak = player:get_player_control().sneak 
	if vel.y >= 6.5 and players[name] < 1 and
			sneak and accelerating[name] then
		players[name] = players[name] + 1
		local boost = vector.multiply(vel, 0.35)
		player:add_player_velocity(boost)
	elseif vel.y <= 0 and not sneak then
		players[name] = 0
	end
end

local function sprint(player)
	if not player then
		return
	end

	local name = player:get_player_name()
	local attached = player_api.player_attached[name]

	if not attached then
		local pos = player:get_pos()
		local c = control(player)
		local s = sprinting[name]
		local vel = player:get_player_velocity()
		local y = vel.y < -10 

		if vel.x > 5 or vel.z > 5 or
				vel.x < -5 or vel.z < -5 then
			accelerating[name] = true
		else
			accelerating[name] = false
		end

		if not s and c.aux1 and
				not y then
			sprinting[name] = true
			physics(player, true)
		elseif s and (not c.aux1 or y) then
			sprinting[name] = false
			physics(player, false)
		end

		if sprinting[name] and
				(c.up or c.down or c.left or
				c.right or c.jump) then
			if players[name] <= 1 then
				boost(player, pos)
			end
		end
	end

	minetest.after(0, function()
		sprint(player)
	end)
end

minetest.register_on_joinplayer(function(player)
	local name = player:get_player_name()

	sprinting[name] = false
	players[name] = 0
	accelerating[name] = false

	player:set_physics_override({
		sneak_glitch = false,
		sneak = true,
		new_move = true,
	})

	sprint(player)
end)

minetest.register_on_leaveplayer(function(player)
	local name = player:get_player_name()

	sprinting[name] = nil
	players[name] = nil
	accelerating[name] = nil
end)
https://github.com/jastevenson303/supersprint

* Any positional change will put you in a "sprinting" state, simply holding AUX1 will not do!
Attachments
supersprint.zip
(11.01 KiB) Downloaded 14 times
2009-10-7 02:04:55: ACTION[Server]: jastest activates

Post Reply

Who is online

Users browsing this forum: jas and 2 guests