Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Written By Eumeus14
- -- Simple swimming script for smw TASing (speed values in this script apply to Mario Game by Draconif)
- -- Things to fix:
- -- gui.drawtext does nothing
- -- Could set it up so that the console only outputs the swimming direction one time when it is changed.
- -- The address of Mario's speed
- local speed = 0x00007B
- -- Mario's maximum left/right swimming speeds
- local maxSwimSpeedL = -20
- local maxSwimSpeedR = 20
- -- Mario's maximum left/right swimming speeds with an item
- local maxItemSwimSpeedL = -34
- local maxItemSwimSpeedR = 34
- -- The direction the script will make mario swim
- local swimDirection = 'Stopped'
- -- EmulatorHeight is just used for ui stuff
- local EmulatorHeight = client.bufferheight()
- -- Boolean to track if Mario is holding an item or not. defaults to false.
- local holdingItem = false
- -- Functions
- -- Checks for a water current and adjusts max swimming values accordingly
- function CheckForWaterCurrent()
- -- Set speed to 0 and wait for a current to push Mario
- mainmemory.write_s8(speed, 0)
- -- Set carried item to 0. Otherwise, the current cannot overpower Mario.
- mainmemory.writebyte(0x00148F, 0)
- AdvanceFrames(2)
- if(mainmemory.read_s8(speed) < 0) then
- -- Current pushes all speed values 8 units left
- maxSwimSpeedL = maxSwimSpeedL - 8
- maxSwimSpeedR = maxSwimSpeedR - 8
- maxItemSwimSpeedL = maxItemSwimSpeedL - 8
- maxItemSwimSpeedR = maxItemSwimSpeedR - 8
- console.writeline('Leftward current detected. Adjusting speed values...')
- elseif(mainmemory.read_s8(speed) > 0) then
- -- Current pushes all speed values 8 units right
- maxSwimSpeedL = maxSwimSpeedL + 8
- maxSwimSpeedR = maxSwimSpeedR + 8
- maxItemSwimSpeedL = maxItemSwimSpeedL + 8
- maxItemSwimSpeedR = maxItemSwimSpeedR + 8
- console.writeline('Rightward current detected. Adjusting speed values...')
- else
- -- no adjustment needed
- console.writeline('No current detected.')
- end
- end
- -- Advance some number of frames
- function AdvanceFrames(numFrames)
- client.unpause()
- for i = 1, numFrames do
- emu.frameadvance()
- end
- client.pause()
- end
- -- Determines which direction to swim
- function DetermineSwimmingDirection()
- -- Get keyboard input for swimming direction
- local Keypresses = input.get()
- -- Check the keyboard inputs and adjust swimming direction accordingly
- if(Keypresses.A == true) then
- swimDirection = 'Left'
- console.writeline('Setting swim direction to left.')
- elseif(Keypresses.D == true) then
- swimDirection = 'Right'
- console.writeline('Setting swim direction to right.')
- elseif(Keypresses.S == true) then
- swimDirection = 'Stopped'
- console.writeline('Stopping swim.')
- end
- end
- -- Checks if Mario is currently holding an item
- function CheckForHeldItem()
- if(mainmemory.readbyte(0x00148F) == 1) then
- holdingItem = true
- else
- holdingItem = false
- end
- end
- -- Swims
- function DoSwimming()
- CheckForHeldItem()
- -- Not holding an item
- if(holdingItem == false) then
- -- Left
- if(swimDirection == 'Left') then
- if(mainmemory.read_s8(speed) ~= maxSwimSpeedL) then
- joypad.set({['Right']=false}, 1)
- joypad.set({['Left']=true}, 1)
- else
- joypad.set({['Right']=true}, 1)
- joypad.set({['Left']=false}, 1)
- end
- -- Right
- elseif(swimDirection == 'Right') then
- if(mainmemory.read_s8(speed) ~= maxSwimSpeedR) then
- joypad.set({['Right']=true}, 1)
- joypad.set({['Left']=false}, 1)
- else
- joypad.set({['Right']=false}, 1)
- joypad.set({['Left']=true}, 1)
- end
- end
- -- Holding an item
- else
- -- Left
- if(swimDirection == 'Left') then
- if(mainmemory.read_s8(speed) ~= maxItemSwimSpeedL) then
- joypad.set({['Right']=false}, 1)
- joypad.set({['Left']=true}, 1)
- else
- joypad.set({['Right']=true}, 1)
- joypad.set({['Left']=false}, 1)
- end
- -- Right
- elseif(swimDirection == 'Right') then
- if(mainmemory.read_s8(speed) ~= maxItemSwimSpeedR) then
- joypad.set({['Right']=true}, 1)
- joypad.set({['Left']=false}, 1)
- else
- joypad.set({['Right']=false}, 1)
- joypad.set({['Left']=true}, 1)
- end
- end
- end
- end
- -- main
- savestate.save('MarioSwim')
- CheckForWaterCurrent()
- savestate.load('MarioSwim')
- while( true ) do
- -- instructions for user
- gui.drawText(1, (EmulatorHeight - 65), 'Press A on the keyboard to swim left.')
- gui.drawText(1, (EmulatorHeight - 50), 'Press D on the keyboard to swim right.')
- gui.drawText(1, (EmulatorHeight - 35), 'Press S on the keyboard to stop swimming.')
- DetermineSwimmingDirection()
- DoSwimming()
- emu.yield()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement