User File #637878209001595255

Upload All User Files

#637878209001595255 - Beethoven - The Ultimate Canine Caper! (USA) lua script

Beethoven - The Ultimate Canine Caper! (USA).lua
80 downloads
Uploaded 5/10/2022 11:08 PM by TASeditor (see all 188)
Basic output logger. Press Comma and Period to change the branch.
function Logger()

	xc = memory.read_u16_le(0xA48)
	
	player.position.x[frame] = memory.read_u16_le(0x177E)
	player.position.y[frame] = memory.read_u16_le(0x17D8)
	
	player.position.x_[frame] = memory.read_u16_le(0x1F6C)
	player.position.y_[frame] = memory.read_u16_le(0x1F70)
	
	gui.drawText(0, 30, "X:"..player.position.x[frame], 0xFFFFFFFF, 0x99990000)
	gui.drawText(0, 45, "Y:"..player.position.y[frame], 0xFFFFFFFF, 0x99009900)
	
	

end

function LoadFile(index)

	SaveFile(-1)
	
	local file = io.open(movie.filename()..tostring(index)..".txt", "r")
	local i = 0
	
	if file ~= nil
	then for l in file:lines(1) do
			 local str = {}
			 s = bizstring.split(l, ";")
			 
			 player.position.x[i] = tonumber(s[1])
			 player.position.y[i] = tonumber(s[2])
			 player.position.x_[i] = tonumber(s[3])
			 player.position.y_[i] = tonumber(s[4])
			 			 
			 i = i + 1
		 end
		 file:close()
	end

end

function SaveFile(index)

	local file = io.open(movie.filename()..tostring(index)..".txt", "w+")
	
	for i = 0, movie.length(), 1 do
		file:write(tostring(player.position.x[i])..";"..
				   tostring(player.position.y[i])..";"..
				   tostring(player.position.x_[i])..";"..
				   tostring(player.position.y_[i]).."\n")
	end
	file:close()

end

function BranchLoad(index)

	LoadFile(index)

end

function deepcopy(orig)
    local orig_type = type(orig)
    local copy
    if orig_type == 'table' then
        copy = {}
        for orig_key, orig_value in next, orig, nil do
            copy[deepcopy(orig_key)] = deepcopy(orig_value)
        end
        setmetatable(copy, deepcopy(getmetatable(orig)))
    else -- number, string, boolean, etc
        copy = orig
    end
    return copy
end

function BranchSave(index)

	if index >= 0
	then player_ = {position = {x = {}, y = {}, x_ = {}, y_ ={}}}
		 player_ = deepcopy(player)
		 branches[index+1] = player_
	end

	SaveFile(index)

end

function BranchRemove(index)

	table.remove(branches, index+1)

	local branches = tastudio.getbranches()
	
	os.remove(movie.filename()..tostring(index)..".txt")
	
	for i = index, table.getn(branches), 1 do
		os.rename(movie.filename()..tostring(i+1)..".txt", movie.filename()..tostring(i)..".txt")
	end

end

function Exit()

	SaveFile(-2)

end

function FrameEnd()

	Logger()

end

function sgn(x)

	if x > 0
	then return 1
	elseif x < 0
	then return -1
	else return 0
	end
	
end

function TAStudioText(index, column)

	if player.position.x[index] ~= nil and player.position.x_[index] and column == "DX"
	then return tostring(player.position.x[index] - player.position.x_[index])
	elseif player.position.y[index] ~= nil and player.position.y_[index] and column == "DY"
	then return tostring(player.position.y[index] - player.position.y_[index])
	
	elseif branches[selectedbranch] ~= nil and branches[selectedbranch].position.x[index] ~= nil and branches[selectedbranch].position.x_[index] ~= nil and player.position.x[index] ~= nil and player.position.x_[index] and column == "BX"
	then return tostring(player.position.x[index] - branches[selectedbranch].position.x[index])*sgn(branches[selectedbranch].position.x[index] - branches[selectedbranch].position.x_[index])
	elseif branches[selectedbranch] ~= nil and branches[selectedbranch].position.y[index] ~= nil and branches[selectedbranch].position.y_[index] ~= nil and player.position.y[index] ~= nil and player.position.y_[index] and column == "BY"
	then return tostring(player.position.y[index] - branches[selectedbranch].position.y[index])*sgn(branches[selectedbranch].position.y[index] - branches[selectedbranch].position.y_[index])
	end
	
	if column == "DX" or column == "DY" or column == "BX" or column == "BY"
	then return ""
	end
	
end

function Color(color1, color2, index)

	if index >= ug
	then return color1
	else return color2
	end

end

function ColorGradient(value, maxvalue, index)

	if value < 0
	then red = 255
		 green = 0
		 blue = 0
	elseif value  < maxvalue/2
		then red = 255	
		 green = math.floor((255/(maxvalue-maxvalue/2))*math.abs(value))
		 blue = 0
	elseif math.abs(value) < maxvalue
		then red = math.floor(-(255/(maxvalue-maxvalue/2))*math.abs(value)+510)
			 green = 255
			 blue = 0
		else red = 0
			 green = 255
			 blue = 0
	end
	
	if (index >= ug)
	then red = math.floor((255-red)/120*(200-240)+255)
		 green = math.floor((255-green)/120*(200-240)+255)
		 blue = math.floor((255-blue)/120*(200-240)+255)
	end

	alpha = 255
	
	return alpha*256*256*256+red*256*256+green*256+blue
	
end

function TAStudioColor(index, column)

	if player.position.x[index] ~= nil and player.position.x_[index] and column == "DX"
	then return ColorGradient(math.abs(player.position.x[index] - player.position.x_[index]), 5, index)
	elseif player.position.y[index] ~= nil and player.position.y_[index] and column == "DY"
	then return ColorGradient(math.abs(player.position.y[index] - player.position.y_[index]), 8, index)
	
	elseif column == "BX" and branches[selectedbranch] ~= nil and branches[selectedbranch].position.x[index] ~= nil and branches[selectedbranch].position.x_[index] ~= nil and player.position.x[index] ~= nil and player.position.x_[index] 
	then return ColorGradient((player.position.x[index] - branches[selectedbranch].position.x[index])*sgn(branches[selectedbranch].position.x[index] - branches[selectedbranch].position.x_[index]), 10, index)
	elseif column == "BY" and branches[selectedbranch] ~= nil and branches[selectedbranch].position.y[index] ~= nil and branches[selectedbranch].position.y_[index] ~= nil and player.position.y[index] ~= nil and player.position.y_[index]
	then return ColorGradient((player.position.y[index] - branches[selectedbranch].position.y[index])*sgn(branches[selectedbranch].position.y[index] - branches[selectedbranch].position.y_[index]), 10, index)
	end
		 
end

function Ungreen(index)

	if ug > index
	then ug = index
	end

end

memory.usememorydomain("WRAM")

player = {position = {x = {}, y = {}, x_ = {}, y_ ={}}}
branches = {}

tastudio.addcolumn("DX", "dx", 30)
tastudio.addcolumn("DY", "dy", 30)
tastudio.addcolumn("BX", "bx", 30)
tastudio.addcolumn("BY", "by", 30)

ug = 0
selectedbranch = 1

tastudio.onqueryitemtext(TAStudioText)
tastudio.onqueryitembg(TAStudioColor)
tastudio.ongreenzoneinvalidated(Ungreen)

tastudio.onbranchsave(BranchSave)
tastudio.onbranchload(BranchLoad)
tastudio.onbranchremove(BranchRemove)

event.onexit(Exit)
--event.onframeend(FrameEnd)

LoadFile(-2)

for index = 1, table.getn(tastudio.getbranches())+1, 1 do

	player_ = {position = {x = {}, y = {}, x_ = {}, y_ ={}}}

	local file = io.open(movie.filename()..tostring(index-1)..".txt", "r")
	local i = 0
	
	if file ~= nil
	then for l in file:lines(1) do
			 local str = {}
			 s = bizstring.split(l, ";")
			 
			 player_.position.x[i] = tonumber(s[1])
			 player_.position.y[i] = tonumber(s[2])
			 player_.position.x_[i] = tonumber(s[3])
			 player_.position.y_[i] = tonumber(s[4])
			 			 
			 i = i + 1
		 end
		 branches[index] = player_
		 file:close()
	end
	
end

while true do
	
	frame = emu.framecount()
	
	if frame > ug
	then ug = frame
	end
	
	wasinp = inp
	inp = input.get()
	
	if inp["Period"] and wasinp["Period"] == nil and selectedbranch <= table.getn(tastudio.getbranches())
	then selectedbranch = selectedbranch + 1
	elseif inp["Comma"] and wasinp["Comma"] == nil and selectedbranch > 1
	then selectedbranch = selectedbranch - 1
	end

	gui.pixelText(0, 160, "B:"..selectedbranch)

	Logger()
	
	emu.yield()
	
end