Looking for help

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Message
Author
User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#21 Post by Administrator » Sun Apr 12, 2015 4:42 pm

Good. Glad you could get it all working and it seems you learned a few things.

The require function is used to include additional optional packages, including Lua plugins, libraries, or modules. Everything in that lib folder will be considered optional.

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#22 Post by kurapicas » Sun Apr 12, 2015 5:19 pm

Yep I learned a lot today and yesterday.

Now Im learning this. Attach?

Code: Select all

attach( findWindow("  dnbk  ") );
So it would be like this?

Code: Select all

function macro.init()
attach = window.find("  dknb  ");
end
can it work also like attaching process?

Code: Select all

attach = process.findByExe(exeName);
While I was reading through Keyboard Module. I found this attach
If you are running input in attached mode (through use of attach()) it will only send input to the target window, and will not interfere if you decide to switch windows.
So im trying to use attach. its A cool feature, I can Browse without worrying that my Health is going down if im not focus into the game window..

Now the problem is that its reading the Ammo. but i switch to Notepad++ then F1 (Help) appeared.? that keypress should be only send through attach process

I cant find an example of AttachInput script.
Ex: typing "yes" in notepad.exe while not focus on another window?

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#23 Post by Administrator » Sun Apr 12, 2015 5:52 pm

You don't need to attach() with MicroMacro 2. Instead, you just use the keyboard.virtualPress(win, vk) function. It has the same effect of sending the input directly to the window.

You should probably store the window in a variable instead of calling window.find() constantly.

Code: Select all

win = window.find("  dnbk  ");
keyboard.virtualPress(win, key.VK_F1);

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#24 Post by kurapicas » Sun Apr 12, 2015 6:27 pm

Tried that

Code: Select all

keyboard.virtualPress(win, key.VK_F1);
but it doesnt seem to send F1 key, even i went into the game.. VirtualPress doesnt seem to work.

but keyboard.press works fine. Im using Windows 8.1 maybe virtual keyboards doesnt work..

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#25 Post by Administrator » Sun Apr 12, 2015 8:44 pm

Maybe. Whether that type of input works or not depends entirely on how the input logic is programmed in the target application.

Another possibility is that the game is just creating multiple windows, and you're just sending it to the wrong one.. You can use a tool like WinSpy to investigate that further. What happens when you add this to macro.init():

Code: Select all

local windows = process.getWindows( process.findByExe("dark.exe") );
for i,v in pairs(windows) do
	printf("windows[%d]: hwnd: %d, class: %s, name: %s\n", i, v.hwnd, v.class, v.name);
end

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#26 Post by kurapicas » Sun Apr 12, 2015 9:58 pm

Get Error of

Code: Select all

2015-04-12 22:46:33 : Load file error code: 7 (Runtime error)
1test.lua:6: attempt to call a nil value (field 'getWindows')
about the timestamp

Code: Select all

function macro.init()
actionTimestamp = Timestamp:now():addSeconds(200);
it seems when i run the script, It also start the timer, the moment the script start running..
I just wanted the time counter for this part, pressing capslock should activate the timestamp event..

Code: Select all

if( not actionTimestamp:isFuture() ) then
    actionTimestamp = Timestamp:now():addSeconds(200); -- Reset it
    keyboard.press(key.VK_CAPSLOCK);
    mouse.hold(key.VK_RMOUSE);
    print("200 seconds have elapsed.");
else 
if( capsOn ) then 
    keyboard.press(key.VK_CAPSLOCK);
  end
end

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#27 Post by Administrator » Sun Apr 12, 2015 10:06 pm

Sorry about that again. I'm not testing this code at all and it's just off the top of my head. The function is process.getWindows(), not window.getWindows().

If you don't want to start the timer and instead want to trigger it immediately, you could just chop off the ":addSeconds(200)" part of the call that happens outside of the main function. Alternatively, you might consider changing it to 3 seconds or something to give you a chance to switch back to the window before it triggers for the first time.

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#28 Post by kurapicas » Sun Apr 12, 2015 10:20 pm

Code: Select all

windows[1]: hwnd: 1573668, class:   dknb  , name:   dknb
windows[2]: hwnd: 4982006, class: MSCTFIME UI, name: MSCTFIME UI
windows[3]: hwnd: 7734736, class: IME, name: Default IME
about the timer. I just want the timer to trigger if i press capslock. But even without pressing capslock the timer still count.

I even tried

Code: Select all

timeLeft = 200; function. 
but it also start counting from the moment the script start running..because its outside of function macro.main(dt)?.

maybe there a way to put timeleft countdown inside macro.main? so it would only start counting down when capslock is pressed? It would start the script even press capslock on its own.

Code: Select all

function macro.main(dt)


if( capsOn ) then
        keyboard.press(key.VK_CAPSLOCK);
        mouse.hold(key.VK_RMOUSE)
        timeleft = 200; -- start countdown 
   else
        if( timeLeft < 0 ) then -- when countdown reach 0
	keyboard.press(key.VK_CAPSLOCK); -- press capslock again then this goes back to function "( capsOn )"
    end
  end

then it would loop there right?

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#29 Post by Administrator » Sun Apr 12, 2015 10:41 pm

You can try using virtualPress() but specify different windows to see if it works or not. Based on that input, you could do this:

Code: Select all

win = 1573668;
keyboard.virtualPress(win, key.VK_F1);
When that doesn't work, change win to the next number and try again. Note that these numbers will certainly change every time you restart the game, but if you can find a window that works, then we can work around that. If all don't work, then that type of synthetic input just isn't picked up by the game's input code, so there's not much you can do about it except just use regular input (though that requires the game to be focused).


OK, so, you want the timer to only start when you manually press the capslock key. First, remove both calls that were setting actionTimestamp (both outside the main function and the one where it is triggered). On the trigger itself, you again want to change this line:

Code: Select all

if( actionTimestamp and not actionTimestamp:isFuture() ) then
  actionTimestamp = nil;
so it includes the "actionTimestamp and" part again, as well as the "actionTimestamp = nil" inside it. This is so we won't get nil errors, and disable it after it has been triggered.

Now, you're going to add some code to capture an event:

Code: Select all

function macro.event(e, ...)
	if( e == "keyreleased" ) then
		vk,toggle = ...;
		if( vk == key.VK_CAPSLOCK ) then
			actionTimestamp = Timestamp:now():addSeconds(200);
			if( toggle ) then
				keyboard.press(key.VK_CAPSLOCK, false);
			end

			print("Timestamp set.");
		end
	end
end
This will check if the user has pressed and released their capslock key, and if they have, it starts the actionTimestamp timer to be triggered in 200 seconds. It will also disable the capslock key instantly.

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#30 Post by kurapicas » Mon Apr 13, 2015 12:18 am

It seem it only trigger once.

The game have feature of auto attack by pressing CapsLock and Holding right click.
The Auto Attack last for 3 minutes only (180 seconds)..
So in order to auto attack again I must press capslock and Hold right click again...

maybe im doing something wrong. But here entire code.

http://codepad.org/6cAN0Bm1

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#31 Post by Administrator » Mon Apr 13, 2015 9:47 am

You didn't do anything wrong, you just coded it to be enabled, but not ever disabled when pressing the capslock again.

Code: Select all

   if( e == "keyreleased" ) then
      vk,toggle = ...;
      if( vk == key.VK_CAPSLOCK ) then
		if( actionTimestamp ) then
			actionTimestamp = nil;
			print("Disabled");
		else
			actionTimestamp = Timestamp:now():addSeconds(185);
			print("Enabled");
		end

         if( toggle ) then
            keyboard.press(key.VK_CAPSLOCK, false);
         end
      end
   end
Just need to add in that if/else statement to toggle it.


Oh, also remove the line setting actionTimestamp to nil on the trigger code, so it doesn't get disabled after one run. Re-add the code that restarts the timer.

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#32 Post by kurapicas » Wed Apr 15, 2015 8:23 am

Sorry for late reply... Was away for a while.

Thanks works completely now..

Is there a way to change the Value of HP and MP to Percent?. I had to keep changing the value everytime i play low level character or high level character. How to make it 50%?

if( HP < 50% ) doesnt seem to work :P

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#33 Post by Administrator » Wed Apr 15, 2015 10:46 am

Well, a percentage is just a ratio of the current level out of its maximal amount, so you'll need to get the max HP and max MP values as well. Then you can just do this:

Code: Select all

local HP_percent = (HP / maxHP) * 100;
local MP_percent = (MP / maxMP) * 100;

if( HP_percent < 50 ) then

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#34 Post by kurapicas » Wed Apr 15, 2015 7:37 pm

can the max HP and Max MP value just be read from the HP/MP address?. cuz lowest character HP Value is like 400 while my other character have 5k+ hp.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#35 Post by Administrator » Wed Apr 15, 2015 9:35 pm

The max HP/MP values are very often stored +4 bytes from the original. That is, your HP is stored at 0x00A880C4, so try checking 0x00A880C8. Do the same thing for MP.

kurapicas
Posts: 19
Joined: Sat Apr 11, 2015 1:51 pm

Re: Looking for help

#36 Post by kurapicas » Thu Apr 16, 2015 6:36 pm

So the way I add it would be like this?

Code: Select all

      
local HP = process.read(proc, "int", 0x00A880C4);
local MP = process.read(proc, "int", 0x00A880C8);
local maxHP = process.read(proc, "int", 0x00A880CC);
local maxMP = process.read(proc, "int", 0x00A880D0);
local HP_percent = (HP / maxHP) * 100;
local MP_percent = (MP / maxMP) * 100;
or

Code: Select all

local HP_percent = (0x00A880C4 / 0x00A880CC) * 100;
local MP_percent = (0x00A880C8 / 0x00A880D0) * 100;
or

Code: Select all

	  
local HP_percent = process.read(proc, "int", 0x00A880C4 / 0x00A880CC) * 100;
local MP_percent = process.read(proc, "int", 0x00A880C8 / 0x00A880D0) * 100;
Which way is the right one? Im very noob at this :(

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Looking for help

#37 Post by Administrator » Thu Apr 16, 2015 7:38 pm

The first one. But first, you should try adding those addresses in Cheat Engine to make sure that they are correct.

tongclub62
Posts: 3
Joined: Sun May 03, 2015 11:37 pm

Re: Looking for help

#38 Post by tongclub62 » Tue May 19, 2015 10:33 pm

Thanks for sharing. ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests