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
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:


