• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Problem - Problem with /keypress

Soandso2

Well-known member
Joined
Mar 13, 2023
RedCents
937¢
In my bard Lua I had a snippet of code that toggled between a "fight melody" and a "rest melody". This used to work flawlessly. Until I noticed today that it didn't. I tried loads of stuff to get it to work, but I couldn't. So I took the snippet out and made a stand-alone Lua of it instead, to see if that worked better. And it "kind of" did, but not 100%.

Here is the snippet.

[CODE lang="Lua" title="melodies"]mq = require('mq')

require("../includes/utils")

local fightMelody = false

while true do
if me.Combat() and target() then
if not fightMelody then
fightMelody = true
mq.cmd("/keypress 1")
mq.delay(1000)
print("Pressed key 1 and waited 1 second")
end
end
if not me.Combat() then
if fightMelody then
fightMelody = false
mq.cmd("/keypress 2")
mq.delay(1000)
print("Pressed key 2 and waited 1 second")
end
end
end[/CODE]

It is dead simple.
If I enter combat and the fight melody is not playing, play it (/keypress 1) and set the boolean to true so we dont try to start the melody again. Once is enough.
And when I am no longer in combat, check if fightMelody is true and if it is, set it to false and start playing the rest melody.

The fight melody is in hot button 1, and the rest melody is in hot button 2. Both these hot buttons start with /stopsong, a pause and then the /melody command, followed by a group tell.

And it works sometimes. And when code works sometimes, it is usually something else than code logic that screws things up. But I am out of ideas. I added the delay in the Lua code just to make sure that for some reason the script wouldnt rush through the loop a million times before the game actually realised that I had issued a command. But it does not help.

And yeah, me.Combat() works, since the me a short version of the mq.TLO.Me, all set and fixed in the required utils-Lua. So that is not the issue.

Bear in mind, the print-lines both execute as expected. They print everytime they should But the fight melody does not always start. Ah, that is one thing to mention, I guess. It is always the fight melody that does not start. The rest melody always starts, when it should. I THINK the issue is with the /keypress commands for some reason, but I dont know. But that is why I named this thread "Problem with /keypress".

The hot buttons look like this;:
Fight melody button (/keypress 1)
/pause 10, /stopsong
/melody 1 2 3 4 5 6 7 8 9 10 11
/g playing a fight melody

The rest melody button (/keypress 2)
/pause 10, /stopsong
/melody 9 10 3 4 5
/g playing a rest melody
 
Last edited:
would doing
Code:
while not mq.TLO.Me.BardSongPlaying() do
    mq.cmd("/keypress 1")
    mq.delay(1000)
end
instead work ?
 
would doing
Code:
while not mq.TLO.Me.BardSongPlaying() do
    mq.cmd("/keypress 1")
    mq.delay(1000)
end
instead work ?
Did not know you could do that, but I am not sure that would solve the issue anyway. There should always be a melody playing, either rest or fight. Can BardSongPlaying tell which melody is playing?
 
you could just put the melody you want into your lua code instead of using a keypress.
I used to do that in the beginning, but thought it would be easier to be able to change the songs I wanted in my melodies in the game without changing any Lua code. But if /keypress IS the reason this does not work 100%, then I will have to do that. You think my suspicion that the problem lies with the /keypress is correct then?
 
i mean, it certainly adds a level of uncertainty to it.

When I do commands in mq.cmd i use single ' instead of double " unless there's a ' or a in the thing I'm trying to do. I don't know if that's a matter of personal preference or might have some impact.
 
Alright, I have changed the Lua and I will be testing within a few hours. I'll keep you posted on the progress.

A few moments later...

So, first I changed the keypress command to the melody command in the Lua, like so:
mq.cmd("/melody 1 2 3 4 5 6 7 8 9 10 11")
I also reduced the delay to 500.

That did not help one bit. Worked just as poorly as with the /keypress 1

Then I increased the delay again and it seemed to work better, but far from perfect.
I increased the delay again, to 1500 and now it started working almost 9 times out of 10, but still not 100%

I came to think of that it was always the fight melody that failed, not the rest melody, and realised that whenever I issue the command to the bard to start attacking, she uses /nav target dist=10 to position herself so she can hit the mob with her weapons. Then I added a check to make sure that I was standing still before trying to start the melody and now it seems to work as intended. I have not been able to test this for a long period of time, but for 10-15 minutes straight it did not fail once.

The end result:
[CODE title="fight melody seems to work now"]mq = require('mq')

require("../includes/utils")

local fightMelody = false

while true do
if me.Combat() and target() and not fightMelody and not me.Moving() then
fightMelody = true
mq.cmd("/stopsong")
mq.delay(1500)
mq.cmd("/melody 1 2 3 4 5 6 7 8 9 10 11")
mq.cmd("/g Playing the FIGHT song!")
end
if not me.Combat() and fightMelody then
fightMelody = false
mq.cmd("/stopsong")
mq.delay(750)
mq.cmd("/melody 9 10 3 4 5")
mq.cmd("/g Playing the REST song!")
end
end[/CODE]
 
Last edited:
Seems like you could improve your delays by adding the second callback parameter. I'm assuming it's just waiting for all the songs to stop playing. So you could have

Code:
local function done_playing()
  return not mq.TLO.Me.BardSongPlaying()
end

-- then change your delays like this

while true do
    if me.Combat() and target() and not fightMelody and not me.Moving() then
        fightMelody = true
        mq.cmd("/stopsong")
        mq.delay(1500, done_playing)
        mq.cmd("/melody 1 2 3 4 5 6 7 8 9 10 11")
        mq.cmd("/g Playing the FIGHT song!")
    end
    if not me.Combat() and fightMelody then
        fightMelody = false
        mq.cmd("/stopsong")
        mq.delay(750, done_playing)
        mq.cmd("/melody 9 10 3 4 5")
        mq.cmd("/g Playing the REST song!")
    end
end

Shouldn't affect your primary issue, but playing the new melody shouldn't take as long if your delay timer is normally sufficiently long enough.
 
#NotABard, but isn't this what mq2twist is for? The plugin seems to handle things like stuck keys and delays automagically.
 
Standing still shouldn't have any effect on a bard melody. In fact one of the major reasons for having a bard is casting while moving.
Yeah that is why I did not have this check to begin with - bards can cast (sing) whilst moving. But this check still made a difference. Something going on in mq2nav perhaps? Or it is just random coincidence.
 
#NotABard, but isn't this what mq2twist is for? The plugin seems to handle things like stuck keys and delays automagically.
Honestly, there are probably plugins for 95% of the stuff I do in my own scripts but I kind of like figuring things out. I might give mq2twist a look if this does not work out. :)
 
Honestly, there are probably plugins for 95% of the stuff I do in my own scripts but I kind of like figuring things out. I might give mq2twist a look if this does not work out. :)
Just because there is something that does a thing doesn't mean you cannot or should not make something that does it differently. This is how both learning and innovation is going to happen. I strongly encourage approaching things from various angles in an attempt to improve existing options. With that said, sometimes using existing things is a better option, if only at first.
 
I am going to try mq2twist just for kicks and giggles. The instructions are kind of limited, but I take it I could just do like this? (I will soon find out, but I am posting anyway. :) )

Edit: Half an hour in The Hero's Forge and not one single fail. :)

I read something about a bug fix in the twist-plug, something about interruptions if someone uses a clicky whilst doing the twist. My bard uses at least one clicky (BP click) during the fights. Could this possibly be a reason for the fails of my original script? That the /useitem collides with the /melody (or even the original /keypress) ?

Lua:
mq = require('mq')

require("../includes/utils")

local fightMelody = false

while true do
    if me.Combat() and target() and not fightMelody then
        fightMelody = true
        --mq.cmd("/stopsong")
        mq.cmd("/twist 1 2 3 4 5 6 7 8 9 10 11")
        mq.cmd("/g twisting the FIGHT song!")
        --mq.delay(1500)
        --mq.cmd("/melody 1 2 3 4 5 6 7 8 9 10 11")
        --mq.cmd("/g Playing the FIGHT song!")
    end
    if not me.Combat() and fightMelody then
        fightMelody = false
        --mq.cmd("/stopsong")
        --mq.delay(750)
        --mq.cmd("/melody 9 10 3 4 5")
        mq.cmd("/twist 9 10 3 4 5")
        mq.cmd("/g twisting the REST song!")
        --mq.cmd("/g Playing the REST song!")
    end
end
 
Last edited:
Problem - Problem with /keypress

Users who are viewing this thread

Back
Top
Cart