Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Message
| A more concrete example of talking to the status bar is this example, which I used to do the screenshot above. It uses the Lua socket library to send UDP packets:
dofile "lua.lua"
socket = require "socket"
s = socket.udp ()
s:setpeername ("127.0.0.1", 4111)
s:send ("magic,title,Status Bar - BabbleMUD")
s:send ("magic,config,10,5,100,15,60,320,20")
s:send ("magic,size,10,10,350,140")
s:send ("magic,textcolour," .. ColourNameToRGB ("indigo"))
s:send ("magic,backcolour," .. ColourNameToRGB ("lightsteelblue"))
s:send ("magic,labels,HP,Mana,Move,XP")
s:send ("magic,values,10,20,30,80")
s:send ("magic,font,Comic Sans MS,10,0,700")
s:send ("magic,colours," ..
ColourNameToRGB ("darkgreen") .. "," ..
ColourNameToRGB ("darkblue") .. "," ..
ColourNameToRGB ("saddlebrown") .. "," ..
ColourNameToRGB ("dimgray"))
s:send ("magic,fillcolours," ..
ColourNameToRGB ("lightgreen") .. "," ..
ColourNameToRGB ("lightblue") .. "," ..
ColourNameToRGB ("tan") .. "," ..
ColourNameToRGB ("gainsboro"))
s:send ("magic,text,5,88,Darkhaven Square")
s:close ()
However since not everyone will want to use Lua to talk to status bars, MUSHclient 3.56 now has a UdpSend function added to it. This simply lets you send a single UDP packet to the network.
Here is an example of using the UdpSend function (in Lua again, but it could just as easily be VBscript) to capture an inventory and display it:
function multiline_trigger (name, line, wildcards)
local function udp (msg)
UdpSend ("127.0.0.1", 4111, "m," .. msg)
end
udp ("title,Inventory")
udp ("size,10,10,300,300")
udp ("config,10,5,100,15,80,300,20")
udp ("font,Harem,12")
udp ("textcolour,0")
udp ("backcolour,14804223")
udp ("text,5,5," .. wildcards.inventory)
end -- function
The above example uses a "helper" function to send to the correct address and port, and put the magic word at the start of the line. It illustrates, by the way, the method of declaring "local" functions in Lua, which are functions that are visible only inside another function.
The code above sets the window title and size, sets the font to Harem, defines the text and background colours, and sends the inventory as multi-line text. See below for how it looks:
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|