User File #45830021035144282

Upload All User Files

#45830021035144282 - GB Lion King updated lua script

Lion King, The (USA).lua
813 downloads
Uploaded 3/17/2018 10:48 PM by TASeditor (see all 188)
function Text(index, column)

	if column == "xSpeedCol" and xT[index] ~= nil and xT[index-1] ~= nil
	then return tostring(xT[index]-xT[index-1])
	elseif column == "ySpeedCol" and yT[index] ~= nil and yT[index-1] ~= nil
		then return tostring(yT[index]-yT[index-1])
	end

end

function Color(index, column)

	if column == "xSpeedCol" and xT[index] ~= nil and xT[index-1] ~= nil
	then if math.abs(xT[index]-xT[index-1]) < 5
		 then red = 255
			  green = math.floor((255/5)*math.abs(xT[index]-xT[index-1]))
			  blue = 0
		 else red = math.floor(-(255/5)*math.abs(xT[index]-xT[index-1])+510)
			  green = 255
			  blue = 0
		 end
		 return red*256*256+green*256+blue
	elseif column == "ySpeedCol" and yT[index] ~= nil and yT[index-1] ~= nil
	then if math.abs(yT[index]-yT[index-1]) < 3
		 then red = 255
			  green = math.floor((255/3)*math.abs(yT[index]-yT[index-1]))
			  blue = 0
		 else red = math.floor(-(255/3)*math.abs(yT[index]-yT[index-1])+510)
			  green = 255
			  blue = 0
		 end
		 return red*256*256+green*256+blue
	end

end

function Ungreen(index)

	if ug > index
	then ug = index
	end

end

function BranchLoad(index)

	local file = io.open(movie.filename()..tostring(index)..".txt", "r")
	local num = 0
	
	for i in file:lines(1) do
		local str = {}
		str = bizstring.split(i, ";")
		
		xT[num] = str[1]
		yT[num] = str[2]
		
		num = num + 1
	end
	file:close()
end

function BranchSave(index)

	local file = io.open(movie.filename()..tostring(index)..".txt", "w+")
	
	for i = 0, ug, 1 do
		file:write(tostring(xT[i])..";"..tostring(yT[i]).."\n")
	end
	file:close()
end

xT = {}
yT = {}

ug = 0

memory.usememorydomain("WRAM")

tastudio.addcolumn("xSpeedCol", "xSpd", 40)
tastudio.addcolumn("ySpeedCol", "ySpd", 40)

tastudio.onqueryitemtext(Text)
tastudio.onqueryitembg(Color)
tastudio.onbranchload(BranchLoad)
tastudio.onbranchsave(BranchSave)


while (true) do
	
	f = emu.framecount()
	
	if f > ug
	then ug = f
	end

	local x = memory.read_u16_le(0x0595)
	local y = memory.read_u16_le(0x0597)
	xT[f] = x
	yT[f] = y
	local xc = memory.read_u16_le(0x0524)
	local yc = memory.read_u16_le(0x0528)

	for i = 0, 5, 1 do
	
		local x = memory.read_u8(0x066A+i) + memory.read_u8(0x0670+i)*256
		local y = memory.read_u8(0x0676+i) + memory.read_u8(0x067C+i)*256
		gui.pixelText(x-xc, y-yc, ""..x.."\n"..y)--, "white", "blue", "gens")
		
	end
	
	gui.drawText(0,30, "x:"..x.." ")
	gui.drawText(0,45, "y:"..y.." ")
	
	local lag = memory.read_u8(0x004D)
	
	if lag == 2
	then tastudio.setlag(emu.framecount()-2, false)
	else tastudio.setlag(emu.framecount()-2, true)
	end
	
	emu.frameadvance()
	
end