ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Cuemif on October 06, 2010, 05:48:47 AM

Title: Adding a hotkey
Post by: Cuemif on October 06, 2010, 05:48:47 AM
I was trying to add a hot key to this here script was wondering if I could get a quick help out with it as my attempts are fail

Code: [Select]
set %bag_to_keep_open_1 VACTRMD
set %bag_to_keep_open_2 BOPVKMD


set #lobjectID %bag_to_keep_open_1
event macro 17
wait 10
set #lobjectID %bag_to_keep_open_2
event macro 17
wait 10

Thank you so much and sorry about my lame newbness
Title: Re: Adding a hotkey
Post by: 12TimesOver on October 06, 2010, 06:19:37 AM
What are you trying to accomplish by hitting the hotkey?
Title: Re: Adding a hotkey
Post by: Cerveza on October 06, 2010, 06:24:14 AM
Code: [Select]
; near the beginning of the script in the setup
set %bag_to_keep_open_1 VACTRMD
set %hotkey_to_open_bag_1 F1

set %bag_to_keep_open_2 BOPVKMD
set %hotkey_to_open_bag_2 F2

; then in the mainloop of the script
onhotkey %bag_to_keep_open_1
gosub open_bag %bag_to_keep_open_1

onhotkey %bag_to_keep_open_2
gosub open_bag %bag_to_keep_open_2

; then somewhere out of the way (end) of the script
sub open_bag
set #lobjectID %1
event macro 17
wait 10
return

Please note that onhotkey isn't an instant key press and action. You often have to hold down the key for like half a second to get it to "take".
Title: Re: Adding a hotkey
Post by: Cuemif on October 06, 2010, 10:48:55 AM
Ok what I added there is my script. I do not think that there is a loop . GOD I am a newb I should just stop trying lol sorry . Please help if you can later
Title: Re: Adding a hotkey
Post by: Cerveza on October 06, 2010, 10:56:03 AM
The script must have a main loop. Your still trying to use this with CEO's medic, right?

Look for a line with this

Mainloop:

and put this in under it...
Code: [Select]
; then in the mainloop of the script
onhotkey %bag_to_keep_open_1
gosub open_bag %bag_to_keep_open_1

onhotkey %bag_to_keep_open_2
gosub open_bag %bag_to_keep_open_2

Make sure you have the setup stuff at the beginning and the sub at the end.
Title: Re: Adding a hotkey
Post by: Cuemif on October 06, 2010, 11:36:06 AM
Ok I added
Code: [Select]
set %hotkey_bag_to_keep_open_1 Mat top of script
And then right below Mainloop: I added
Code: [Select]
onhotkey %bag_to_keep_open_1
gosub open_bag %bag_to_keep_open_1

Then at bottom of script I added this
Code: [Select]
sub open_bag
set #lobjectID %1
event macro 17
wait 10
return

It still does not work I even held the M key down for about 5 secs what might I be doing wrong ?
Title: Re: Adding a hotkey
Post by: Cerveza on October 06, 2010, 11:46:54 AM
You have your hotkey set to the variable

%hotkey_bag_to_keep_open_1

but when you call that hotkey you are calling a different variable

%bag_to_keep_open_1 <- notice it's different, missing "hotkey_"

You can shorten or rename this stuff to whatever makes it easier for you....

set %hotkey_1 M
set %bag_1 VACTRMD

onhotkey %hotkey_1
  gosub open_bag %bag_1

Title: Re: Adding a hotkey
Post by: TrailMyx on October 06, 2010, 12:08:59 PM
Something for everyone to consider when using hotkeys.  Since onhotkey isn't latched, it's easy to miss the key.  People originally reported in the CLAw that it would take quite a bit of time for the script to react to keyboard selections.  My solution was to build a function that would just set flags and allow the script to handle a successful keypress later.  So I had a function:

Code: [Select]
;-------------------------------------------------------------------------------
sub CheckHotKey
  menu get EUOEditKey1
  onhotkey #MENURES ALT
    set %targetkey #TRUE
  menu get EUOEditKey2
  onhotkey #MENURES ALT
    set %lootarea #TRUE
return

And then I could pepper the code with "gosub CheckHotKey" to scan and capture at a higher rate.  Then you just look at the variables %targetkey and %lootarea to make the call that a key has been pressed.

To get onhotkey to be response, I'd just do this:

Code: [Select]
gosub HandleItemLoggingToHistory
gosub CheckHotKey
gosub VerifyLootCheckmarks
gosub CheckHotKey
gosub ManageIgnoreList
gosub CheckHotKey
gosub HandleExternalInterface
gosub CheckHotKey

No more hotkey lag complaints.... ;)
Title: Re: Adding a hotkey
Post by: Cuemif on October 06, 2010, 12:12:40 PM
Something for everyone to consider when using hotkeys.  Since onhotkey isn't latched, it's easy to miss the key.  People originally reported in the CLAw that it would take quite a bit of time for the script to react to keyboard selections.  My solution was to build a function that would just set flags and allow the script to handle a successful keypress later.  So I had a function:

Code: [Select]
;-------------------------------------------------------------------------------
sub CheckHotKey
  menu get EUOEditKey1
  onhotkey #MENURES ALT
    set %targetkey #TRUE
  menu get EUOEditKey2
  onhotkey #MENURES ALT
    set %lootarea #TRUE
return

And then I could pepper the code with "gosub CheckHotKey" to scan and capture at a higher rate.  Then you just look at the variables %targetkey and %lootarea to make the call that a key has been pressed.

To get onhotkey to be response, I'd just do this:

Code: [Select]
gosub HandleItemLoggingToHistory
gosub CheckHotKey
gosub VerifyLootCheckmarks
gosub CheckHotKey
gosub ManageIgnoreList
gosub CheckHotKey
gosub HandleExternalInterface
gosub CheckHotKey

No more hotkey lag complaints.... ;)

Yes the lag is crazy BUT the above confuses me lol
Title: Re: Adding a hotkey
Post by: Cuemif on October 06, 2010, 12:21:50 PM
I am gonna have to figure this out
Title: Re: Adding a hotkey
Post by: TrailMyx on October 06, 2010, 12:39:24 PM
Really what I'm doing is just calling onhotkey lots more times and registering the occurrences instead of missing them.
Title: Re: Adding a hotkey
Post by: Cuemif on October 06, 2010, 12:46:35 PM
So... all I need to do is add
Code: [Select]
onhotkey %bag_to_keep_open_2
gosub open_bag %bag_to_keep_open_2

Here there and everywhere?
Title: Re: Adding a hotkey
Post by: TrailMyx on October 06, 2010, 01:12:50 PM
Sorry, may have confused you with a more advanced thought.  You should look at EasyUO the exact syntax of onhotkey.  It's looking for the arguments of the key.  In my case I had F1 in the menures variable so I'm looking for:

onhotkey F1 ALT

This returns true.

Other than that, pay no attention to my post; it's probably more than you need and hard to explain.
Title: Re: Adding a hotkey
Post by: Cuemif on October 06, 2010, 01:14:51 PM
I do want it to open faster right now it takes like 4 to 5 secs to open my bags and that is just well TO slow I am a semi fast learner so I am gonna look more into this