User File #638518154749816055

Upload All User Files

#638518154749816055 - Speed Calc for SSASR with other stuff

speed_ASR.lua
30 downloads
Uploaded 5/20/2024 3:24 PM by TheBlazingmo (see all 10)
Edited by inconsistent_dg and Myself
Original made by inconsistent:
local prevX = 0
local prevY = 0
local prevZ = 0
local prevFrameCount = emu.framecount()

while true do
    memory.usememorydomain("Main RAM")
    xPointer = memory.read_s32_le(0x236238) + 0x6C
    local currentX = memory.read_s32_le(xPointer & 0xFFFFFF)
    local currentY = memory.read_s32_le(xPointer + 4 & 0xFFFFFF) 
    local currentZ = memory.read_s32_le(xPointer + 8 & 0xFFFFFF) 
    local VelX = memory.read_s32_le(xPointer + 2576 & 0xFFFFFF)
	local VelY = memory.read_s32_le(xPointer + 2580 & 0xFFFFFF)
	local VelZ = memory.read_s32_le(xPointer + 2584 & 0xFFFFFF)
    local rotationY = memory.read_s32_le(xPointer - 60 & 0xFFFFFF) 
	local Boost = memory.read_s32_le(xPointer + 1836 & 0xFFFFFF)
	
	
	
    local currentFrameCount = emu.framecount()
    local frameDifference = currentFrameCount - prevFrameCount
    
    -- calculate horizontal speed
    local speed = 0
    if frameDifference ~= 0 then
        local deltaX = currentX - prevX   -- delta means change in value
        local deltaZ = currentZ - prevZ   -- delta means change in value
        local distance = math.sqrt(deltaX * deltaX + deltaZ * deltaZ)
                                                  -- pythagorean theorem
        speed = math.floor(distance / frameDifference + 0.5)
           -- if you don't want it to round down, then remove math.floor
                                   -- speed = distance / frameDifference
    end
    
    -- calculate vertical speed
    local speedY = 0
    if frameDifference ~= 0 then
        local deltaY = currentY - prevY
        speedY = math.floor(deltaY / frameDifference + 0.5)
                          -- no pythagorean theorem because Y = one axis
    end

    -- calculate horizontal speed
    local velocity = 0
    if frameDifference ~= 0 then
        local deltaXvel = VelX - prevX   -- delta means change in value
        local deltaZvel = VelZ - prevZ   -- delta means change in value
        local Veldistance = math.sqrt(deltaXvel * deltaXvel + deltaZvel * deltaZvel)
                                                  -- pythagorean theorem
        velocity = math.floor(Veldistance / frameDifference + 0.5)
           -- if you don't want it to round down, then remove math.floor
                                   -- speed = distance / frameDifference
    end
	
    -- displays
    gui.drawText(1, 0, "Horizontal Speed: " .. speed, "white", "black", 12)
    gui.drawText(1, 15, "Vertical Speed: " .. speedY, "white", "black", 12)
    gui.drawText(1, 30, "Positions", "white", "black", 12)
	gui.drawText(1, 45, "X: " .. currentX, "white", "black", 12)
    gui.drawText(1, 60, "Y: " .. currentY, "white", "black", 12)
	gui.drawText(1, 75, "Z: " .. currentZ, "white", "black", 12)
	gui.drawText(1, 90, "Velocities", "white", "black", 12)
	gui.drawText(1, 105, "xVel: " .. VelX, "white", "black", 12)
	gui.drawText(1, 120, "yVel: " .. VelY, "white", "black", 12)
	gui.drawText(1, 135, "zVel: " .. VelZ, "white", "black", 12)
	gui.drawText(1, 150, "Facing Angle: " .. rotationY, "white", "black", 12)
	
    -- update previous
    prevX = currentX
    prevY = currentY
    prevZ = currentZ
    prevFrameCount = currentFrameCount
    
    clampedSpeed = math.min(math.max(Boost, 0), 85000)

    gui.drawRectangle(1, 180, clampedSpeed * 0.0028, 10, 0xC0FFFFFF, 0xC0FF0000)

    emu.frameadvance() -- needed to not crash
end