Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key = 0
- aLimit = 0
- coProg = 1
- maxVel = 0
- simulating = false
- opt = 1
- prevAng = 50
- deadConstant = 0.1124
- firstTime = false
- origX = 0
- origZ = 0
- function getVelocity() -- Calculated VXZ
- local vX = mainmemory.readfloat(0x37C4B8, true);
- local vZ = mainmemory.readfloat(0x37C4C0, true);
- return math.sqrt(vX*vX + vZ*vZ);
- end
- function angleFix(angle)
- if angle < -1*math.pi+deadConstant then
- return 50
- elseif angle < (-1*math.pi)/2-deadConstant then
- return 2*math.pi+angle-4*deadConstant
- elseif angle < (-1*math.pi)/2+deadConstant then
- return 50
- elseif angle < 0-deadConstant then
- return 2*math.pi+angle-6*deadConstant
- elseif angle < deadConstant then
- return 50
- elseif angle < math.pi / 2 - deadConstant then
- return angle - deadConstant
- elseif angle < math.pi / 2 + deadConstant then
- return 50
- elseif angle < math.pi - deadConstant then
- return angle - 2*deadConstant
- else
- return 50
- end
- end
- function line(fr,alim,endfr)
- co = {}
- co[1] = {}
- co[1].x = 0
- co[1].y = 0
- co[1].angle = 1
- key = fr
- endFrame = endfr
- aLimit = alim
- tempInputs = movie.getinput(key-4)
- tempX = math.min(62,tempInputs["P1 X Axis"])
- tempY = math.min(62,tempInputs["P1 Y Axis"])
- prevAng = angleFix(math.atan2(tempY,tempX))
- --print(prevAngle)
- for x=-62,62 do
- for y = -62,62 do
- if math.sqrt(x*x+y*y) >= 62 then
- endco = #co+1
- co[endco] = {}
- co[endco].x = x
- co[endco].y = y
- co[endco].angle = angleFix(math.atan2(y,x))
- end
- end
- end
- --for i = 1,#co do
- -- print(co[i].x,co[i].y,co[i].angle)
- --end
- simulating = true
- firstTime = true
- client.unpause()
- tastudio.setplayback(key-2)
- tastudio.setmarker(key-2)
- tastudio.setrecording(true)
- simulate()
- end
- function cancel()
- tastudio.setrecording(false)
- tastudio.removemarker(key-2)
- simulating = false
- client.pause()
- tastudio.setrecording(false)
- key = 0
- aLimit = 0
- coProg = 1
- maxVel = 0
- opt = 1
- prevAng = 50
- end
- function simulate()
- if simulating == true then
- frame = emu.framecount()
- if (firstTime == true) then
- if frame < key-2 then
- tempInputs = movie.getinput(frame)
- joypad.setanalog({["P1 X Axis"] = tempInputs["P1 X Axis"]})
- joypad.setanalog({["P1 Y Axis"] = tempInputs["P1 Y Axis"]})
- if frame <= aLimit then
- joypad.set(({["P1 A"] = true}))
- else
- joypad.set(({["P1 A"] = false}))
- end
- end
- if frame == key-2 or frame == key-1 then
- tempInputs = movie.getinput(frame)
- joypad.setanalog({["P1 X Axis"] = tempInputs["P1 X Axis"]})
- joypad.setanalog({["P1 Y Axis"] = tempInputs["P1 Y Axis"]})
- if frame <= aLimit then
- joypad.set(({["P1 A"] = true}))
- else
- joypad.set(({["P1 A"] = false}))
- end
- --For detecting if my input didn't move me
- origX = mainmemory.readfloat(0x37C5A0, true);
- origZ = mainmemory.readfloat(0x37C5A8, true);
- end
- if frame == key then
- local newX = mainmemory.readfloat(0x37C5A0, true);
- local newZ = mainmemory.readfloat(0x37C5A8, true);
- if (origX == newX and origZ == newZ) then
- tastudio.removemarker(key-2)
- key = key+1
- tastudio.setmarker(key-2)
- coProg = 1
- maxVel = 0
- --prevAng = co[opt].angle
- opt = 1
- tastudio.setplayback(key-2)
- else
- firstTime = false
- tastudio.setplayback(key-2)
- end
- end
- elseif coProg <= #co then
- if frame < key-2 then
- tempInputs = movie.getinput(frame)
- joypad.setanalog({["P1 X Axis"] = tempInputs["P1 X Axis"]})
- joypad.setanalog({["P1 Y Axis"] = tempInputs["P1 Y Axis"]})
- if frame <= aLimit then
- joypad.set(({["P1 A"] = true}))
- else
- joypad.set(({["P1 A"] = false}))
- end
- end
- if frame == key-2 or frame == key-1 then
- joypad.setanalog({["P1 X Axis"] = co[coProg].x})
- joypad.setanalog({["P1 Y Axis"] = co[coProg].y})
- if frame <= aLimit then
- joypad.set(({["P1 A"] = true}))
- else
- joypad.set(({["P1 A"] = false}))
- end
- end
- if frame == key then
- vel = getVelocity()
- if vel >= maxVel then
- maxVel = vel
- opt = coProg
- end
- coProg = coProg+1
- if coProg <= #co then
- angle = tonumber(co[coProg].angle)
- while math.abs(angle-prevAng) > 0.1 and math.abs(math.abs(angle-prevAng)-(2*math.pi-7*deadConstant)) > 0.1 do
- coProg = coProg+1
- --print(frame,coProg, angle, prevAng, math.abs(angle-prevAng))
- if coProg > #co then
- break
- end
- angle = tonumber(co[coProg].angle)
- end
- end
- if coProg <= #co then
- joypad.setanalog({["P1 X Axis"] = co[coProg].x})
- joypad.setanalog({["P1 Y Axis"] = co[coProg].y})
- else
- joypad.setanalog({["P1 X Axis"] = co[opt].x})
- joypad.setanalog({["P1 Y Axis"] = co[opt].y})
- end
- if frame <= aLimit then
- joypad.set(({["P1 A"] = true}))
- else
- joypad.set(({["P1 A"] = false}))
- end
- tastudio.setplayback(key-2)
- movie.setrerecordcount(movie.getrerecordcount()+1)
- end
- else
- if frame < key-2 then
- tempInputs = movie.getinput(frame-1)
- joypad.setanalog({["P1 X Axis"] = tempInputs["P1 X Axis"]})
- joypad.setanalog({["P1 Y Axis"] = tempInputs["P1 Y Axis"]})
- end
- if frame == key-2 or frame == key-1 then
- joypad.setanalog({["P1 X Axis"] = co[opt].x})
- joypad.setanalog({["P1 Y Axis"] = co[opt].y})
- if frame <= aLimit then
- joypad.set(({["P1 A"] = true}))
- else
- joypad.set(({["P1 A"] = false}))
- end
- end
- if frame == key then
- tastudio.removemarker(key-2)
- key = key+2
- tastudio.setmarker(key-2)
- firstTime = true
- coProg = 1
- maxVel = 0
- if frame >= endFrame then
- tastudio.removemarker(key-2)
- simulating = false
- client.pause()
- tastudio.setrecording(false)
- end
- prevAng = co[opt].angle
- opt = 1
- tastudio.setplayback(key-2)
- tastudio.setrecording(false)
- end
- end
- end
- end
- event.onframestart(simulate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement