User File #31373458496044164

Upload All User Files

#31373458496044164 - SM64DS XYZ Speed Lua + velocity change + Y run timer and KtQ speeds

SM64DS XYZ speed.lua
1233 downloads
Uploaded 6/4/2016 9:28 PM by ALAKTORN (see all 34)
Shows XYZ and horizontal real speed, RAM speed, and prints horizontal velocity changes (if you have 100 speed and next frame 50, it will print −50). Added Y run timer and KtQ speeds display. Here’s what a slightly older version looks like: http://i.imgur.com/t5HKpN9.jpg
local base = memory.readdword(0x02097490)
local XAddr = base + 0x5C
local ZAddr = base + 0x64
local YAddr = base + 0xA8
local speedAddr = base + 0x98
local prevX = nil
local prevZ = nil
local prevY = nil
local X = "N/A"
local Z = "N/A"
local Y = "N/A"
local realspeed = "N/A"
local speed = nil
local prevSpeed = nil
local lag = emu.lagcount()

function fn()
	if lag == emu.lagcount() then
		base = memory.readdword(0x02097490)
		XAddr = base + 0x5C
		ZAddr = base + 0x64
		YAddr = base + 0x60
		speedAddr = base + 0x98
		local currentX = memory.readdword(XAddr)
		local currentZ = memory.readdword(ZAddr)
		local currentY = memory.readdword(YAddr)
		local currentSpeed = memory.readdwordsigned(speedAddr)
		if prevX ~= nil and prevZ ~= nil and prevY ~= nil then
			X = currentX - prevX
			Z = currentZ - prevZ
			Y = currentY - prevY
			realspeed = math.sqrt(X^2 + Z^2)
		end
		if prevSpeed ~= nil then
			speed = currentSpeed - prevSpeed
			if speed ~= 0 or lastSpeed ~= 0 then
				print("Speed difference: " .. speed)
			end
		end
		prevX = currentX
		prevZ = currentZ
		prevY = currentY
		prevSpeed = currentSpeed
		lastSpeed = speed
	end
	lag = emu.lagcount()
end

function fm()
	gui.text(0, 2, "Real X Speed: " .. X)
	gui.text(0, 12, "Real Z Speed: " .. Z)
	gui.text(0, 22, "Real Y Speed: " .. Y)
	gui.text(0, 32, "RAM    Speed: " .. memory.readdwordsigned(speedAddr))
	gui.text(0, 42, "Real   Speed: " .. realspeed)
	gui.text(0, 52, "Y Run  Timer: " .. memory.readbyte(base + 0x6ED))
	gui.text(0, 62, "KTQ BoB speed: " .. memory.readdwordsigned(0x02151D14))
	gui.text(0, 72, "KTQ THI speed: " .. memory.readdwordsigned(0x02167F84))
end

emu.registerafter(fn)
gui.register(fm)