• 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
DanNet Helpers

Lua - DanNet Helpers 2021-08-30

Download

SpecialEd

Lua Slayer
Joined
Apr 4, 2021
RedCents
5,705¢
SpecialEd submitted a new resource:

DanNet Helpers - Query, Observe, Unobserve?

This is a small library you can include in your lua scripts to easily query/observe/unobserve peers/TLO values using MQ2DanNet.

Installation -

If necessary, create a "lib" folder in your lua directory - then place the dannet/ directory into lua/lib folder.

Usage -

To run the tests in game, /lua run dannet.test.lua <peer name>

[CODE title="Usage / Test Script"]local mq = require('mq')
local Write = require('lib/Write')
local dannet =...[/CODE]

Read more about this resource...
 
I am sure there is a better way.. but I know not

Code:
local function return_string(str, int)
    local counter = 0
    for word in string.gmatch(str, '([^,]+)') do
        counter = counter + 1
        if counter == int then return word end
    end
end

Code:
local peer_name = mq.TLO.DanNet.Peers()
peer_name = peer_name:gsub("_", "")
peer_name = peer_name:gsub(mq.TLO.MacroQuest.Server(), "")
peer_name = peer_name:gsub("|", ",")
for x = 1, mq.TLO.DanNet.PeerCount() do
     local name = return_string(peer_name, x)
     local id = 45574
    local  a = dannet.query(name, "FindItemCount[" .. id .. "]")
    print(a)
    end
 
Last edited:
OK, I see this has not been updated in a while. While working on my project I ended up trying this out, and ran into some issues (timeouts, crashes, no function to get observation result), so I wrote my own version. Changes are a bit more extensive than a couple lines, and changed the library name. Not familiar with how to do this - should I post a new resource? Submit to Ed?

I wouldn't want to introduce a new API and break anyone using this, so is it best to just create a new resource?
 
OK, I see this has not been updated in a while. While working on my project I ended up trying this out, and ran into some issues (timeouts, crashes, no function to get observation result), so I wrote my own version. Changes are a bit more extensive than a couple lines, and changed the library name. Not familiar with how to do this - should I post a new resource? Submit to Ed?

I wouldn't want to introduce a new API and break anyone using this, so is it best to just create a new resource?
You'd want to talk to Ed first and see if it is something he wanted to incorporate/add/update, if he wanted to pass over the resource, or if no, then submit your own, differently named resource for review
 
K, seeing as I am just starting to use this myself, and knowing me it is likely to grow arms and legs as I learn, I don't think I want to start it as a resource of my own. I will just include the code for the current implementation below for anyone to use, and for Ed's consideration.
[CODE lang="Lua" title="DANNET"]local mq = require('mq')

local DANNET = {}

--[[ Add an observer.
@param peer - name of the peer to observe
@param query - query (e.g., 'Me.Invis[1]')
@return true if successful (or observer already present)
]]
function DANNET.addObserver(peer, query)
if not mq.TLO.DanNet(peer).OSet(query)() then
mq.cmdf('/dobserve %s -q "%s"', peer, query)
end
return mq.TLO.DanNet(peer).OSet(query)()
end

--[[ Remove an observer.
@param peer - name of the peer to observe
@param query - query (e.g., 'Me.Invis[1]')
]]
function DANNET.dropObserver(peer, query)
mq.cmdf('/dobserve %s -q "%s" -drop', peer, query)
end

--[[ Determine if we have an observer.
@param peer - name of the peer to observe
@param query - query (e.g., 'Me.Invis[1]')
@return true if observer exists
]]
function DANNET.observing(peer, query)
return mq.TLO.DanNet(peer).OSet(query)()
end

--[[ Returns the most recent observation result.
@param peer - name of the peer to observe
@param query - query (e.g., 'Me.Invis[1]')
@timeout timeout_ms - optional timeout in ms, default is 1000ms
@return observation result (or nil if no result)
@return observation result timestamp (or nil if no result)
]]
function DANNET.observe(peer,query,timeout_ms)
mq.delay(timeout_ms or 1000,function() return mq.TLO.DanNet(peer).O(query)() ~= nil end)
return mq.TLO.DanNet(peer).O(query)(), mq.TLO.DanNet(peer).O(query).Received()
end

--[[ Performs an on-demand query.
@param peer - name of the peer to observe
@param query - query (e.g., 'Me.Invis[1]')
@timeout timeout_ms - optional timeout in ms, default is 1000ms
@return query result (or nil if no result)
@return query result timestamp (or nil if no result)
]]
function DANNET.query(peer,query,timeout_ms)
mq.cmdf('/dquery %s -q "%s"', peer, query)
mq.delay(timeout_ms or 1000,function() return mq.TLO.DanNet(peer).Q(query)() ~= nil end)
return mq.TLO.DanNet(peer).Q(query)(), mq.TLO.DanNet(peer).Q(query).Received()
end

return DANNET[/CODE]
 
Lua - DanNet Helpers

Users who are viewing this thread

Back
Top
Cart