Post subject: Help with mouse control in Ogre Battle
Joined: 10/23/2009
Posts: 4
Hello Denizens of this board: I am new to LUA programming, and I would like to seek your help on programming a LUA code to use the mouse as the control pad. I am hoping to make it so that when the mouse is moved in the x axis for 10-20, right keyboard button is pressed once, twice if change in x is 20-30, and so on. The same applies for the y direction. That is a tentative plan, however, and I more than welcome suggestions or codes on how to do it. As well, I am hoping to convert the right button to A, and the left button to B. However, I have no clue as to how to start. I think this will have an application for a large number of people who are not aware of the magic of LUA programming in the snes. For instance, Ogre Battle will be alot more fun with mouse control. Thank you! SnowDream
mz
Player (79)
Joined: 10/26/2007
Posts: 693
Hi! I made a quick and simple script. Not quite what you asked, but at least it should help you get started, I think.
local oldXmouse = 0
local oldYmouse = 0

while (true) do
	local inp = input.get()

	if inp.leftclick then joypad.set(1,{["B"]=true}) end
	if inp.rightclick then joypad.set(1,{["A"]=true}) end

	local deltax = inp.xmouse-oldXmouse
	local deltay = inp.ymouse-oldYmouse
	if deltax < 0 then joypad.set(1,{["left"]=true})
	elseif deltax > 0 then joypad.set(1,{["right"]=true}) end
	if deltay < 0 then joypad.set(1,{["up"]=true})
	elseif deltay > 0 then joypad.set(1,{["down"]=true}) end

	oldXmouse = inp.xmouse
	oldYmouse = inp.ymouse
	snes9x.frameadvance()
end
It's probably better to write directly to RAM the X and Y position of the cursor, by reading the current mouse position, as in the Gradius III script.
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.
Joined: 10/23/2009
Posts: 4
Thanks! That is very useful. Now I have to find a way to increase the mouse sensitivity... uhm... (the mouse tends to lags on the x direction versus the y one, an interesting problem...)
mz
Player (79)
Joined: 10/26/2007
Posts: 693
Something like this works better when you're on the field:
while (true) do 
	local inp = input.get() 

	if inp.leftclick then joypad.set(1,{["B"]=true}) end 
	if inp.rightclick then joypad.set(1,{["A"]=true}) end 

	if inp.xmouse < 8 then joypad.set(1,{["left"]=true}) end
	if inp.xmouse > 231 then joypad.set(1,{["right"]=true}) end
	if inp.ymouse < 8 then joypad.set(1,{["up"]=true}) end
	if inp.ymouse > 199 then joypad.set(1,{["down"]=true}) end
	memory.writebyte(0x7e14de, inp.xmouse)
	memory.writebyte(0x7e14e0, inp.ymouse)

	snes9x.frameadvance() 
end
Since I wrote this very quickly, it probably works better only in fullscreen. You'd want to check if the mouse is out of bounds and all that, if you want to use it in window mode. And you will still need to figure out a good way to move the cursor during menus. :P
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.
Joined: 10/23/2009
Posts: 4
Works like a charm! Thank you! If you don't mind, I would like to post a link to this thread onto another Ogre Battle fan forum to draw more attention to this. It should raise a little interest in TASvideo and LUA scripting from a dedicated population.
mz
Player (79)
Joined: 10/26/2007
Posts: 693
SnowDream wrote:
If you don't mind, I would like to post a link to this thread onto another Ogre Battle fan forum to draw more attention to this.
Sure, that sounds great. It's always a good thing to have more people using these emulators. :D This looks like fun, but unfortunately I've been very busy lately... One thing I believe would be nice to have, is to move the camera with the keyboard. You move the cursor with the mouse and the camera position with ASDW, for example. To do that, you'd need to find the RAM addresses of the camera position (we have an article here if you need help on that: MemorySearch) and then, for example, if you press the W key, subtract a certain value from the camera Y position in RAM.
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.
Joined: 10/23/2009
Posts: 4
mz wrote:
SnowDream wrote:
If you don't mind, I would like to post a link to this thread onto another Ogre Battle fan forum to draw more attention to this.
Sure, that sounds great. It's always a good thing to have more people using these emulators. :D
Just for people's information, the forum where I posted it at is this one: http://z11.invisionfree.com/Tactics_Ogre_Forums/index.php?showtopic=935&hl=