User File #44847733385309806

Upload All User Files

#44847733385309806 - KDL3 unfinished lua script

Kirby's Dream Land 3 (USA).lua
879 downloads
Uploaded 2/1/2018 5:06 PM by TASeditor (see all 188)


function Kirby()

	local xPos = memory.read_u16_le(0x1A22)
	local yPos = memory.read_u16_le(0x1AA2)
	
	local xSub = memory.read_u8(0x1B23)
	local ySub = memory.read_u8(0x1BA3)
	
	xSpd = memory.read_s16_le(0x1D22)
	xAcc = memory.read_s16_le(0x1E22)
	
	local ySpd = memory.read_s16_le(0x1DA2)
	
	xSpdGoal = memory.read_s16_le(0x1F22)
	
	wasMidAir = midAir
	midAir = memory.read_u8(0x09A2)
	ground = memory.read_u8(0x0BA2)
	
	run = memory.read_u8(0x550B)
	
	wasState = state
	state = memory.read_u8(0x0622)
	
	timer = memory.read_u8(0x2C22)
	
	
	tableGround[frame] = ground
	
	gui.drawText(2,50,"wasMidAir: "..wasMidAir.."\nmidAir: "..midAir.."\nground: "..ground.."\nrun: "..run.."\nstate:"..state)
	
	
	gui.pixelText(2, 169, "Kirby:")
	gui.drawText(2, 176, "X: "..xPos..":"..xSub, 0xFFFFFFFF, 0x44FF0000)
	gui.drawText(2, 191, "Y: "..yPos..":"..ySub, 0xFFFFFFFF, 0x4400FF00)
	gui.drawText(2, 206, "Xv: "..xSpd.."+"..xAcc.."="..xSpd+xAcc, 0xFFFFFFFF, 0x44FF0000)
	

end

function AutoInput()
	
	if state == 0 --Standing
	then tastudio.submitinputchange(emu.framecount(), "P1 Right", true)
	elseif state == 1 --Walking
		then if timer == 0 --TODO: Smarter way doing this
			 then tastudio.submitinputchange(emu.framecount(), "P1 Right", false)
			 else tastudio.submitinputchange(emu.framecount(), "P1 Right", true)
			 end
	elseif state == 2 --Running
		then if xSpd+xAcc < 512
			 then tastudio.submitinputchange(emu.framecount(), "P1 Right", true)
				  tastudio.submitinputchange(emu.framecount(), "P1 B", false)
				  
			 else tastudio.submitinputchange(emu.framecount(), "P1 B", true)
			 end
			 
	elseif state == 3 --Jumping --TODO:variable jump heights
		then setBeforeLanding = false
			 if run == 0
			 then if xSpd+xAcc < 256
				  then tastudio.submitinputchange(emu.framecount(), "P1 Right", true)
				  else tastudio.submitinputchange(emu.framecount(), "P1 Right", false)
				  end
			 elseif run == 2
				 then if xSpd+xAcc < 512
					  then tastudio.submitinputchange(emu.framecount(), "P1 Right", true)
					  else tastudio.submitinputchange(emu.framecount(), "P1 Right", false)
					  end
			 end
	elseif state == 5 --Floating
		then
	elseif state == 6 --Ducking
		then
	elseif state == 7 --Sliding
		then 
	elseif state == 8 --Landing
		then if not setBeforeLanding 
			 then tastudio.submitinputchange(emu.framecount()-1, "P1 Right", true)
				  setBeforeLanding = true
			 end
	elseif state == 9 --Falling
		then if run == 0 and not setBeforeLanding
			 then if xSpd+xAcc < 256
				  then tastudio.submitinputchange(emu.framecount(), "P1 Right", true)
				  else tastudio.submitinputchange(emu.framecount(), "P1 Right", false)
				  end
			 elseif run == 2 and not setBeforeLanding
				 then if xSpd+xAcc < 512
					  then tastudio.submitinputchange(emu.framecount(), "P1 Right", true)
					  else tastudio.submitinputchange(emu.framecount(), "P1 Right", false)
					  end
			 end
	end
	
	tastudio.applyinputchanges();

end

function Color(index, column)

	if tableGround[index] == 0 and column == "P1 B"
	then if index >= ug
		 then return 0xAAECFF
		 else return 0x00C8FF
		 end
	end

end

function Ungreen(index)

	if ug > index
	then ug = index
		 setBeforeLanding = false
	end
	
end

ug = 0
tableGround = {}
setBeforeLanding = false
startedRunning = false
tastudio.clearinputchanges()
memory.usememorydomain("CARTRAM")
tastudio.onqueryitembg(Color)
tastudio.ongreenzoneinvalidated(Ungreen)

while (true) do

	frame = emu.framecount()
	if frame > ug
	then ug = frame
	end
	
	gui.drawRectangle(0, 167, 255, 56, 0x88FFFFFF, 0x88000000)
	gui.drawLine(128, 168, 128, 222, 0x88FFFFFF)

	Kirby()
	
	AutoInput()
--gui.drawText(2, 150, "startedRunning: "..tostring(startedRunning))
gui.drawText(2, 150, "setBeforeLanding: "..tostring(setBeforeLanding))
	emu.frameadvance()

end