• 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

Lua - Timer data type

Joined
Mar 18, 2011
RedCents
212¢
Sorry for the dumb question, is there a way to access the timer data type in MQ macro rather than creating a whole timer thingie? I haven't been able to find a similar data type for Lua. Only thing I've found is creating a function, which is all fine and good, I just want to make sure I'm not missing something incredibly simple.

Any help would be appreciated, the Lua stuff has me really interested but it's a very steep learning curve for me.

Cheers
 
I have been digging around for the same thing. I couldn't find any specific data type for a built in timer in Lua/MQ2LUA. Did snatch this from another post elsewhere in the google-verse. I made a "functions.Lua" file and have been putting random things in there that are beneficial to have quick access to through require commands.

Functions.Lua
INI:
local mq = require('mq')

lastTimeProcessed = os.clock()

function DoTimer(currentTime, timer)
    span = currentTime - lastTimeProcessed
    if span >= timer then
        lastTimeProcessed = currentTime
        return true
    end

    return false
end

FD.Lua (what ive been testing with)
[CODE lang="ini" highlight="2"]local mq = require('mq')
require('functions')

while true do
mq.delay(1)
if DoTimer(os.clock(), 15) and mq.TLO.Me.AbilityReady('Feign Death') and mq.TLO.Me.Standing() then
mq.cmd.doability('"feign death"')
end
end[/CODE]

What that does is checks to see if it has been 15s since the last time the timer was checked. If true (and other requirements are met), then it will execute the FD. I dont think its the best way to handle timers, but it gets the job done.
 
Last edited:
I use a class library called middleclass https://github.com/kikito/middleclass for my Lua bots. I just created a Timer class with similar mechanics, it just has start/stop, reset etc. Store the time it starts and the length of time it should last, then have an Expired() function that checks if it has expired or not.
 
You can use all of the functions a macro has, but if you're talking about processing an event based timer you would need to do that in the Lua syntax. The two examples above are good, but if you get into the specifics of what you're trying to do we might be able to help more.
 
thanks for the responses guys.


@Knightly, super basic.
essentially what I am wanting to do is declare a variable that is a timer.
I can then set the timer variable to be X seconds or mins.
I then use that variable as a cooldown essentially. so if the variable has a timer that is counting down I can get my macro to either skip or do actions based on what the variable is doing at that point in time.

if there is a better way of doing this i'm happy to do some reading if you can point me in the right direction.
 
I guess this is also a good time to readdress the use of timers? I see a lot of macros that wait some specific time AND until some event happens when specifically they're just trying to test the event truthiness.

In the example shown above:

JavaScript:
local mq = require('mq')
require('functions')

while true do
    mq.delay(1)
    if DoTimer(os.clock(), 15) and mq.TLO.Me.AbilityReady('Feign Death') and mq.TLO.Me.Standing() then
        mq.cmd.doability('"feign death"')
    end
end

I'm assuming the 15-second wait timer is because the Necromancer Feign Death spell has a base recast of 15 seconds.

However, we're in the loop checking to see if the 15-second timer has elapsed at a faster rate as seen in the mq.delay(1).

Once the 15 seconds check returns TRUE, we then check to see if the ability 'Feign Death' is ready and if so we check to see if we're standing. Lua short-circuits logical and's - that is it only continues along the path if the first and is TRUE, and so forth.

Basically what I'm getting to is that the 15 second wait timer (in this case) is not needed. And I would contend in a lot of cases the wait timers are not needed, but rather has just become the idiom used in cases where you want to check something.

If you remove the timer check, you basically will check every second for your feign death ability to be ready AND your character to be standing, and if so, you'll cast feign death.

Now, I understand that some mechanics may need timers - that's understandable. But I think a lot of timing conditions could be replaced with simple polling for some conditions.
 
This also leads into the conversation about state management. But I don’t want to confuse the issue, so I think Coldblooded summed it up well.
 
I understand how that is applicable to abilities as they have cooldowns already applied to them in game.

How would that apply to events?

Let's say event triggers. Now I want the macro to run as normal but I don't want the same event to trigger at least until 5 min has passed?? I can't picture any other way other than a timer.

Recognising that my experience is very low with writing macros.
 
Well, as I said, it's not always possible. But in your example Rhiza, what does the 5 minutes represent? Is it some other (event, in-game timer, mob spawn, pizza ready) that you're waiting for? Is there a test that could be applied to that as well? And not just some amount of time?
 
Essentially trying to remove 'bot like behavior'.

Lets say I have a buff bot sitting around willing to buff. Joe blogs comes up and asks for SoW. He might notice that my buff bot has been sitting there for some time and get's inquisitive, starts spamming my buff bot with requests for SoW to which it responds. Essentially I don't want my buff bot responding to every single request if it is unreasonable to do so. I can add in a timer where if the same person has requested X buff within Y time frame it won't respond.

I also use the same idea in a beg for buff macro I use as I don't want my macro spamming begs if the buffer isn't ready and I don't want to use delay because I still want the macro to carry on with its normal duties.
 
In that case Rhiza, I would have my buff bot keep a short FIFO stack of who/when it buffs people, and then check when was the last time Joe Blogs asked me for a buff? If currentTime < 5 minutes from lastTime then ignore and move on. I mean there's always more than one way to skin a cat :)
 
Did some reading and came across this, which answered my questions. There is another article listed in the comments that is also relevant which I've included, below. This stuff gets pretty intense. I've a lot of processing to do...


 
i use timers in my reacts, because Me.ItemReady is unreliable, so use the timer as an analog for the item cooldown. Where I differ from the above, is I never check itemready status.
Code:
  BPBer:
    action: >-
      /multiline ; /useitem ${Me.Inventory[Chest].Name}; /timed 10 /if
      (${Me.Buff[Shield of Blood].ID}) /varset BPBerTimer 602s
    condition: "${BPBerTimer}==0 && ${React.Global[Combat]}"

where i've declared a global timer called "BPBerTimer" elsewhere.

I am always nervous about setting global variables, so is this implementation of os.timer in Lua a better approach ?
 
Last edited:
Lua - Timer data type

Users who are viewing this thread

Back
Top
Cart