Skip to content

Instantly share code, notes, and snippets.

@chosig
Created November 17, 2022 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chosig/599966621c50a20ade4bdd68eacbeab3 to your computer and use it in GitHub Desktop.
Save chosig/599966621c50a20ade4bdd68eacbeab3 to your computer and use it in GitHub Desktop.
This is the script I use in Mudlet to activate MSDP.
-- Enable MSDP protocol
function enableMSDP()
-- Wait a second then try to enable MSDP
tempTimer(1, function() sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES") end)
-- Wait 2 seconds then try to populate MSDP variables.
tempTimer(2, function() enableMSDPvariables() end)
cecho("<orange>MSDP ENABLED!<reset>")
end
function enableMSDPvariables()
-- If MSDP is ready, get variables reported,
-- else wait 1 second and try again.
if type(msdp.REPORTABLE_VARIABLES) == "table" then
for _,v in pairs(msdp.REPORTABLE_VARIABLES) do
sendMSDP("REPORT", v)
end
cecho("<orange> -- MSDP reporting enabled!")
else
tempTimer(1, function() enableMSDPvariables() end)
end
end
if event_enableMSDP then killAnonymousEventHandler(event_enableMSDP) end
event_enableMSDP = registerAnonymousEventHandler("sysConnectionEvent", enableMSDP)
@chosig
Copy link
Author

chosig commented Nov 17, 2022

And this is the event to populate HMS stuff from MSDP

m = m or {}

function msdpHandler(event, ...)
    if event == "msdp.HEALTH" then
        m.hpCur = tonumber(msdp.HEALTH)
        m.hpMax = tonumber(msdp.HEALTH_MAX)
        m.hpPct = (m.hpCur / m.hpMax) * 100
    elseif event == "msdp.MANA" then
        m.mnCur = tonumber(msdp.MANA)
        m.mnMax = tonumber(msdp.MANA_MAX)
        m.mnPct = (m.mnCur / m.mnMax) * 100
    elseif event == "msdp.STAMINA" then
        m.stCur = tonumber(msdp.STAMINA)
        m.stMax = tonumber(msdp.STAMINA_MAX)
        m.stPct = (m.stCur / m.stMax) * 100
    elseif event == "msdp.OPPONENT_HEALTH" then
        m.opHp = tonumber(msdp.OPPONENT_HEALTH)
    elseif event == "msdp.OPPONENT_NUMBER" then
        m.opNo = tonumber(msdp.OPPONENT_NUMBER)
    end
end

registerAnonymousEventHandler("msdp.HEALTH", "msdpHandler")
registerAnonymousEventHandler("msdp.MANA", "msdpHandler")
registerAnonymousEventHandler("msdp.STAMINA", "msdpHandler")
registerAnonymousEventHandler("msdp.OPPONENT_HEALTH", "msdpHandler")
registerAnonymousEventHandler("msdp.OPPONENT_NUMBER", "msdpHandler")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment