Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Scrolling input display for Capcom 6-button fighters
- written by Dammit (dammit9x at hotmail dot com)
- version 11/18/2009
- Works with FBA, snes9x and Gens:
- http://code.google.com/p/fbarr/downloads/list
- http://code.google.com/p/snes9x-rr/downloads/list
- http://code.google.com/p/gens-rerecording/downloads/list
- The files gd.dll and lua51.dll must be with the emulator exe.
- They can be found in these packages:
- http://luaforge.net/frs/download.php/1594/lua-gd-2.0.33r2-win32.zip
- http://luaforge.net/frs/download.php/3677/lua5_1_4_Win32_bin.zip
- You may tweak the parameters above the dashed line.
- Positioning is optimized for CPS1-2-3. The x[2] value must be reduced for the other emus.
- You may use your own images, but their filenames must conform to "(imageset)-(gamekey).png"
- For gens, the images must be in the same place as gens.exe.
- For fba and snes9x, the images must be with the lua script.
- Possible improvements:
- save and load data in savestates: not all emus have savestate.* lua functions
- add pcsx: needs better lua support
- add pcejin: needs better lua support
- add vba: more research needed
- ]]
- local imageset="sf4" --the prefix that must be on image files
- local timeout=240 --how many idle frames until old records are cleared
- local buffersize=10 --how many records to show
- local x={[1]=0x00,[2]=0x120} --horizontal starting position
- local y=0x20 --vertical starting position
- local dx,dy=0x10,0x10 --how far apart to space the symbols
- local opacity=0.8 --factor by which to multiply the opacity of the images
- local draw={[1]=true,[2]=true} --whether to draw each player's commands
- local switch={[1]="Q",[2]="W"} --key used to toggle each player on/off
- ----------------------------------------------------------------------------------------------------
- require "gd"
- local thisframe,lastframe,oldswitch,e,keyset,ghetto,changed={},{},{}
- local inp={[1]={},[2]={}}
- local idle={[1]=0,[2]=0}
- local emulator={snes9x,gens,fba}
- local gamekeys={
- "ul","ur","dl","dr",
- { "l", "left", "left", "Left"},
- { "r", "right","right", "Right"},
- { "u", "up", "up", "Up"},
- { "d", "down", "down", "Down"},
- {"LP", "Y", "X", "Weak Punch"},
- {"MP", "X", "Y","Medium Punch"},
- {"HP", "L", "Z","Strong Punch"},
- {"LK", "B", "A", "Weak Kick"},
- {"MK", "A", "B", "Medium Kick"},
- {"HK", "R", "C", "Strong Kick"},
- { "S","select", "none", "Start"} --taunt button
- }
- for index,name in ipairs(gamekeys) do --Check if all the images are present.
- local file=imageset..(name[1] or name)..".png"
- if not io.open(file,"rb") then
- print(file,"not found.")
- ghetto=true
- end
- end
- if ghetto then print("Falling back on ghetto mode.") end
- for k,emu in pairs(emulator) do --Detect what emulator this is.
- if emu then
- keyset=k+1
- e=emu
- break
- end
- error("This script doesn't work on this emulator yet.")
- end
- local function toggleplayer(p)
- local nowswitch=input.get()[switch[p]] --Press the "switch" keys to toggle display for each char.
- if nowswitch and not oldswitch[p] then
- if not draw[p] then draw[p]=true
- else draw[p]=false
- end
- end
- oldswitch[p]=nowswitch
- end
- local function filterinput(p,f)
- for pressed,state in pairs(joypad.getdown(p)) do --Check current controller state >
- for index,name in pairs(gamekeys) do --but ignore non-gameplay buttons.
- if pressed==name[keyset] or pressed=="P"..p.." "..tostring(name[keyset]) then
- f[name[1]]=state --FBA does not distinguish joypads, so inputs must be filtered by "P1" and "P2".
- break
- end
- end
- end
- end
- local function compositeinput(f)
- for _,a in pairs({"u","d"}) do --Convert individual directions to diagonals.
- for _,b in pairs({"l","r"}) do
- if f[a] and f[b] then
- f[a],f[b]=nil,nil
- f[a..b]=true
- end
- end
- end
- end
- local function detectchanges(f1,f2)
- changed=false
- for key,state in pairs(f2) do --If a key is pressed >
- if not f1[key] then --that wasn't pressed last frame >
- changed=true --then changes were made.
- end
- end
- end
- local function updaterecords(p,f2,i)
- if changed then --If changes were made >
- if idle[p]<timeout then --and the player hasn't been idle too long>
- for record=buffersize,2,-1 do
- i[record]=i[record-1] --then shift every old record by 1 >
- end
- else
- for record=buffersize,2,-1 do
- i[record]=nil --otherwise wipe out the old records.
- end
- end
- idle[p]=0 --Reset the idle count >
- i[1]={} --and set current input as record 1 >
- local index=1
- for _,name in ipairs(gamekeys) do --but the order must not deviate from gamekeys.
- for key,state in pairs(f2) do
- if key==name[1] or key==name then
- i[1][index]=key
- index=index+1
- break
- end
- end
- end
- else idle[p]=idle[p]+1 --Increment the idle count if nothing changed.
- end
- end
- local function displayrecords(p,i)
- if draw[p] then
- for line,stuff in pairs(i) do
- for index,key in pairs(i[line]) do
- if not ghetto then
- gui.gdoverlay(x[p]+index*dx,y+line*dy,gd.createFromPng(imageset..key..".png"):gdStr(),opacity)
- else
- gui.text(x[p]+index*dx,y+line*dy,key) --Ghetto mode displays text symbols only.
- end
- end
- end
- end
- end
- e.registerbefore(function()
- for player=1,2 do
- thisframe={}
- toggleplayer(player)
- filterinput(player,thisframe)
- compositeinput(thisframe)
- detectchanges(lastframe[player],thisframe)
- updaterecords(player,thisframe,inp[player])
- lastframe[player]=thisframe
- end
- end)
- gui.register(function()
- gui.text(0,0,"")
- for player=1,2 do
- displayrecords(player,inp[player])
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement