1 2 3 4 5 6 7 8
Banned User
Joined: 12/23/2004
Posts: 1850
CtrlAltDestroy wrote:
I doubt this, but I'll ask anyway: Is there any way to paint moving objects on a paused FCEU screen?
function d() gui.text(8, 8, "hello"); end; gui.register(d); Beware that unless you have something in the main loop, you will be unable to tell when the emulator is actually emulating.
Perma-banned
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
After finding out about Dpadhero, from this post, I made a script that beats every stage perfectly. It also counts how many balls you hit of each type. If you want to try out the script, run it at the very start of the level, when your score is still 0.
while true do

local function displayer()

points = memory.readbyte(0x06F) + 256*memory.readbyte(0x070) + 65536*memory.readbyte(0x071)

y =    {[0]= 0x3FA, 0x3FF, 0x404, 0x3FA, 0x409, 0x40E, 0x413, 0x418, 0x41D, 0x422, 0x427, 0x42C, 0x431, 0x436, 0x43B, 0x440, 0x445, 0x44A}
t =    {[0]= 0x3F9, 0x3FE, 0x403, 0x3F9, 0x408, 0x40D, 0x412, 0x417, 0x41C, 0x421, 0x426, 0x42B, 0x430, 0x435, 0x43A, 0x43F, 0x444, 0x449}
v =    {[0]= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
q =    {[0]= "B", "B>", "B<", "Bv", "B^", "A", "A>", "A<", "Av", "A^"}

if points==0 then 

h={[0]= 0,0,0,0,0,0,0,0,0,0}

end

for i=0,17,1 do

if memory.readbyte(y[i])==174 then v[i]=1 r=i end

end

w = math.max(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15], v[16], v[17])

if w==1 then

    if memory.readbyte(t[r])==0 then val={B=true} h[0]=h[0]+1
elseif memory.readbyte(t[r])==1 then val={B=true, right=true} h[1]=h[1]+1
elseif memory.readbyte(t[r])==2 then val={B=true, left=true} h[2]=h[2]+1
elseif memory.readbyte(t[r])==3 then val={B=true, down=true} h[3]=h[3]+1
elseif memory.readbyte(t[r])==4 then val={B=true, up=true} h[4]=h[4]+1
elseif memory.readbyte(t[r])==8 then val={A=true} h[5]=h[5]+1
elseif memory.readbyte(t[r])==9 then val={A=true, right=true} h[6]=h[6]+1
elseif memory.readbyte(t[r])==10 then val={A=true, left=true} h[7]=h[7]+1
elseif memory.readbyte(t[r])==11 then val={A=true, down=true} h[8]=h[8]+1
elseif memory.readbyte(t[r])==12 then val={A=true, up=true} h[9]=h[9]+1
else val={} end

else

val={}

end

joypad.set(1, val)

for k=0,9,1 do 
gui.text(10,10+8*k,q[k] .. ": " .. h[k])
end

gui.text(10,90,"Total: " .. h[0]+h[1]+h[2]+h[3]+h[4]+h[5]+h[6]+h[7]+h[8]+h[9])

end

gui.register(displayer)

   FCEU.frameadvance()
end
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
It's been some time since anyone last posted a lua script here, so I thought I might share one with you now. It's a script for the Adventures of Lolo games and eggerland. Just change the variable "game" to the game you're using the script on (so if you're using it on Lolo 2, set game=2, eggerland is game=4)
game=2

poslist = {[0] = 0x06D, 0x091, 0x0CB, 0x083}

steps=0

while true do

input = memory.readbyte(0x008) 
if game<=3 then levelover1=0x007 else levelover1=(0x017) end
levelover = memory.readbyte(levelover1)

xpos = memory.readbyte(poslist[game-1])
ypos = memory.readbyte(poslist[game-1]+2)

if game<=3 then bonus=5 else bonus=-3 end

direction = memory.readbyte(poslist[game-1]+bonus)

if game<=3 then dirval1=2 dirval2=3 else dirval1=3 dirval2=2 end

if direction==dirval1 or direction==1 then changeval=1 end
if direction==0 or direction==dirval2 then changeval=7 end

movement = math.mod(xpos+ypos,8)

if levelover>0 or (game<=2 and AND(input,16)==16) then steps=0 end
if movement==changeval then steps=steps+0.5 end

if math.mod(steps,1)==0 then c1=".0" else c1="" end

gui.text(10,10,"Steps: " .. steps .. c1)

   FCEU.frameadvance()
end
You can reset the steps counter in Lolo 1 and 2 by pressing start. The steps couner is reset when you get to the next level or reload the script in all four games.
adelikat
He/Him
Emulator Coder, Expert player, Site Developer, Site Owner (3581)
Joined: 11/3/2004
Posts: 4736
Location: Tennessee
Handy! Can you mod it to work with Eggerland? :)
It's hard to look this good. My TAS projects
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
adelikat wrote:
Handy! Can you mod it to work with Eggerland? :)
Done! See my previous post for the updated script. Put game=4 for eggerland. Note that resetting the steps counter by pressing start does not work in Lolo 3 or Eggerland, because pressing start has an effect in those two games. I'm not sure how to solve this, but at the moment, the only way to reset the steps counter in these games is to reload the script, or get to the next level.
adelikat
He/Him
Emulator Coder, Expert player, Site Developer, Site Owner (3581)
Joined: 11/3/2004
Posts: 4736
Location: Tennessee
Use input.get() and route it to a keyboard key instead of a gamepad key. (This requires FCUEX)
It's hard to look this good. My TAS projects
Editor, Skilled player (1158)
Joined: 9/27/2008
Posts: 1084
local t= {}      -- Cool! A table!
t["A"]= false    -- Somebody set us up the bomb
joypad.set(1, t) -- After excecution, "A" is stuck at false
For whatever reason, when I set a button to false, that button is forever stuck. I set it to true, nothing. I stop controlling the button, and the player still can't press the button. I end the script, and the button is still stuck. In fact, there's only two ways to get the button unstuck. The above code, a mere three lines, should display the problem well. As far as I can tell, only one button at a time may be stuck like this. One of the ways to get a button unstuck is, implied by the previous sentence, is to get another button stuck. In any case, sending joypad.set a table with multiple false values will only make one button stuck. The other way to unstuck the glitched button is to completely close down FCEUX. Thankfully, it doesn't persist beyond that. It persists beyond the script, that much is certain. Setting true and nil seems to be fine, though. Just something odd I found out with false.
Ambassador, Experienced player (695)
Joined: 7/17/2004
Posts: 985
Location: The FLOATING CASTLE
Lua scripting rocks! I am building up a huge library for Crystalis. But it would be more convenient if there was an lua unpause command. My goal is to be able to have a collection of macros that are run from a central console. So playing this way I'll either do some manual input or run a macro, then pause. Now I want to run another macro. Right now I have to hit a button in my UI and hit unpause for it to run. I have to move the mouse to change focus and hit the pause button. It would be a little faster and easier if I hit the button and it just runs.
adelikat
He/Him
Emulator Coder, Expert player, Site Developer, Site Owner (3581)
Joined: 11/3/2004
Posts: 4736
Location: Tennessee
so you want a FCEUX.pause() and an FCEUX.unpause() function? I have a hard time believing that isn't already in there. But if it isn't, I could make those in 5 minutes.
It's hard to look this good. My TAS projects
Ambassador, Experienced player (695)
Joined: 7/17/2004
Posts: 985
Location: The FLOATING CASTLE
Pause is there and works fine. I just tried FCEU.unpause() and it fails. There's no unpause listed on qFox's page either.
adelikat
He/Him
Emulator Coder, Expert player, Site Developer, Site Owner (3581)
Joined: 11/3/2004
Posts: 4736
Location: Tennessee
fceu.unpause() added: http://fceux.com/zip Also, all documentation in in the fceux.chm that comes with a fceux release. It will be more up to date than qfox's site.
It's hard to look this good. My TAS projects
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
I have a question about a script I made, namely this:
while true do

mf = movie.framecount()

if mf<500 then FCEU.speedmode("turbo") elseif mf==500 then FCEU.speedmode("normal") end

FCEU.frameadvance()

end
As you can see, the script is simple. When it's running, and you're playing a movie, FCEU will run at turbo speed up to frame 500, where it will change and start running at normal speed. I tried this script on FCEU 0.98.28, and it works just fine. However, when running the script on FCEUX 2.1.1, it just keeps running at turbo speed even after frame 500. Somehow, FCEUX doesn't recognize the FCEU.speedmode("normal") command. I have tried changing FCEU to FCEUX in the code, but it didn't work. Does anyone have any idea why this script works in FCEU but not FCEUX?
Active player (250)
Joined: 3/12/2006
Posts: 155
Location: Taiwan
How to use the function gui.gdoverlay(int x = 0, int y = 0, string gdimage)? I want to insert a image on game screen,but the msg always say "bad image data" while run the lua script.The source of the image is from emu screenshot. Does it has any example to learn?
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
What formats are allowed? What is the format of your image? IMO you should try a PNG, because it is an open lossless compression standard, instead of JPG (not lossless) or BMP (not compressed and not open)
i imgur com/QiCaaH8 png
mz
Player (79)
Joined: 10/26/2007
Posts: 693
parrot14gree wrote:
How to use the function gui.gdoverlay(int x = 0, int y = 0, string gdimage)? I want to insert a image on game screen,but the msg always say "bad image data" while run the lua script.The source of the image is from emu screenshot. Does it has any example to learn?
If you want to insert an image from a file, this should work:
im = gd.createFromPng("example.png"):gdStr()
gui.gdoverlay(20,20,im)
If you want to use a screenshot, you should replace "gd.createFromPng()" with "gui.gdscreenshot()":
im = gui.gdscreenshot()
gui.gdoverlay(20,20,im)
You need to install Lua-GD for this to work. Just get this file and this file and extract only the dll files into your emulator folder.
You're just fucking stupid, everyone hates you, sorry to tell you the truth. no one likes you, you're someone pretentious and TASes only to be on speed game, but don't have any hope, you won't get there.
Active player (250)
Joined: 3/12/2006
Posts: 155
Location: Taiwan
wow,it works. Finally can insert image in the emu. great appreciate to mr.mz :)
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
Hello, I have a lua-scripting question: I have a vector called answord of very big length (think over 100 entries) where each entry is a letter. The vector starts at index 0. I also have a variable called length which tells me how many of these letters I want to display on screen. Right now my code looks like this:
if length==1 then gui.text(10,10,"Answer: " .. answord[0]) end
if length==2 then gui.text(10,10,"Answer: " .. answord[0] .. answord[1]) end
if length==3 then gui.text(10,10,"Answer: " .. answord[0] .. answord[1] .. answord[2]) end
if length==4 then gui.text(10,10,"Answer: " .. answord[0] .. answord[1] .. answord[2] .. answord[3]) end
if length==5 then gui.text(10,10,"Answer: " .. answord[0] .. answord[1] .. answord[2] .. answord[3] .. answord[4]) end
I think you get the picture. Remember that the value of length can be quite big, so I need quite a few of these if:s if I want to solve it this way. Is there a nice way to do this without having to write one "if" for each possible value of the length? Perhaps this can be done with a for-loop somehow, but I'm not sure how... help is appreciated!
Player (120)
Joined: 2/11/2007
Posts: 1522
Something like: result = "" For i = 0 to length-1 result = result .. answord End gui.text(10,10,result) There's probably a more elegant solution, but that's what I would do :)
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
alden wrote:
Something like: result = "" For i = 0 to length-1 result = result .. answord End gui.text(10,10,result) There's probably a more elegant solution, but that's what I would do :)
This solution worked beautifully. I didn't know you could do that "result = result .. answord" command, but that seemed to do the trick. :) Thanks for the help!
Player (120)
Joined: 2/11/2007
Posts: 1522
OK, I think a faster solution would be if you could use a string instead of a vector of characters. Then you can use something like string.sub(originalstring,1,length). Probably not too much of an issue though :)
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
Yes, it's me again, and yes, I have a question again: is it in any way possible to make a lua script write data to a .txt file or an Excel file? If not, I think this could make a nice feature: Let's say that you are interested in knowing the value of RAM address $1234 20 frames after pressing the A button between frames 1000 and 2000 while recording a movie. You're not looking for the highest or lowest value of $1234, you're looking for the all the values of $1234 depending on what frame you pressed A. In this case it would be great if the lua-script could write all 1001 data points to an excel file or a .txt file into two columns, where the first column is the frame you pressed A and the second column is the value of $1234 20 frames after you have pressed A on that frame. I have looked through the commands on qFox lua page but I couldn't find anything like that there.
Joined: 10/3/2005
Posts: 1332
Lua has a set of file I/O functions, which you can find in the manual First open a file in write mode, and assign it to a variable:
myfile = io.open("somefile.txt", "w")
Then you can write stuff to it:
myfile:write("words!")
mynum = memory.readbyte(somebyte)
joydata = joypad.read(1)
myfile:write(string.format("\n%d\t%s", mynum, joydata.A)
Note that I haven't written any EmuLua code in months, so that example probably has problems, but I think the idea is pretty clear. Also, I don't think writing an excel file would be trivial. A quick google didn't reveal a library for that... edit: and yeah, you should probably close the resource when you're done with it. I guess Lua would clean up after itself when the emulator closes, but if you re-execute the script, something bad could conceivably happen without this call:
myfile:close()
Player (120)
Joined: 2/11/2007
Posts: 1522
If you write a text file with commas between each "columns" and line feeds at the end of each "row" Excel will interpret it very nicely as a spreadsheet (use extension .csv for the file) For example: 1,5 2,5 3,5 4,6
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Skilled player (1882)
Joined: 4/20/2005
Posts: 2160
Location: Norrköping, Sweden
Thanks Dromiceius, it seems to work nicely! alden: I'm not sure I understand, do I just copy that text to a .txt-file, convert it to .csv, and then open it with Excel? In that case, how do I convert the file to .csv? I tried just putting .csv at the end of the file name, but Excel didn't want to open it.
Player (120)
Joined: 2/11/2007
Posts: 1522
In the lua script name the file "something.csv" instead of .txt... Are you trying to open within Excel or double-clicking on the file? Opening within Excel will probably work better.
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
1 2 3 4 5 6 7 8