Gauges and Compass for Achaea

Posted by Fadedparadox on Mon 25 Aug 2008 02:32 AM — 26 posts, 101,040 views.

USA #0
Three plugins for Achaea.

First, an ATCP plugin that gets the data for the rest. After you add it, you have to log off and back on Achaea, if you're currently connected, to activate it.

http://sites.google.com/site/trevizemoonflair/mushclient/atcp

Second, another gauges plugin, this one uses the images from Nexus, Achaea's web client (with their permission). It's a zip file with bitmaps, unzip it to your normal plugin directory.

http://sites.google.com/site/trevizemoonflair/mushclient/ngauges

And third, a compass. Same as above, uses images from Nexus and is a .zip that needs to be unzipped into the plugin directory.

http://sites.google.com/site/trevizemoonflair/mushclient/ncompass

If you use any of them, you'll want to move the text to the right. This is the script in Lua to do that:

TextRectangle (150, 0, 0, 0, 0, 0x000000, 0, 0x000000, 0)

Enjoy!

(edited to update urls)
Amended on Sun 07 Jun 2009 08:06 PM by Fadedparadox
Netherlands #1
It seems I'm not the only one who wrote an ATCP framework for gauges and compasses to trigger off. Happen to have a screenshot? Mine has the basic stuff working, except that I'm still adding features to it.
USA #2
I used the bitmaps from Nexus, Dusty modified them to work well. Also, the ATCP plugin is mostly borrowed from Keldar, with his permission. I just stripped everything but the basics from it and made it broadcast to any other plugin that wants to listen.

Here's a screenshot of the compass and bars at work:

http://sites.google.com/site/trevizemoonflair/screenshots/MUSHclient_compass_gauges.png
Amended on Wed 10 Jun 2009 01:03 PM by Fadedparadox
Netherlands #3
You've basically done what I have done too and am still working on. Nice. =)
Australia Forum Administrator #4
That looks fantastic! It shows what the miniwindows can do.

Maybe make the textrectangle background colour closer to the background colour of the gauges, but that is just personal preference.

For example:


TextRectangle (150, 0, 0, 0, 0, 0x000000, 0, 0x3F484E, 0)


Amended on Tue 26 Aug 2008 12:24 AM by Nick Gammon
#5
Hey....

stats = {
health = 100, maxhealth = 130,
mana = 100, maxmana = 100,
endurance = 100, maxendurance = 100,
willpower = 100, maxwillpower = 100,
exp = 0, maxexp = 100,

percent = function (stat)
local x = math.floor (stats[stat]/stats["max" .. stat]*100)
if x > 100 then x = 100 elseif x < 0 then x = 0 end
return x
end, -- func
}



gauges = {
name = GetWorldID () .. "1",

position = {5, 20, 35, 50, 65},

create = function (txt, num, col, pos)
WindowRectOp (gauges.name, 1,
26, gauges.position[pos]-1, 127, gauges.position[pos]+1,
ColourNameToRGB ("silver"))
WindowRectOp (gauges.name, 2,
27, gauges.position[pos], 127, gauges.position[pos]+10,
0x010101)
WindowRectOp (gauges.name, 2,
27, gauges.position[pos], 127-(100-num), gauges.position[pos]+10,
ColourNameToRGB (col))
local txtwidth = WindowTextWidth (gauges.name, "font", txt)
WindowRectOp (gauges.name, 2,
25-(txtwidth), gauges.position[pos], 25, gauges.position[pos]+10,
0x010101)
WindowText (gauges.name, "font", txt,
25-(txtwidth), gauges.position[pos], 0, gauges.position[pos]+10,
ColourNameToRGB ("silver"), false)
end, -- func

draw = function ()
gauges.create ("H:", stats.percent ("health"), "red", 1)
gauges.create ("M:", stats.percent ("mana"), "blue", 2)
gauges.create ("E:", stats.percent ("endurance"), "gold", 3)
gauges.create ("W:", stats.percent ("willpower"), "purple", 4)
gauges.create ("XP:", stats.percent ("exp"), "gray", 5)
end, -- func
}



Is there any way I can turn "health", "mana" etc into firing off a variable, rather than the ATCP plugin? I've tried a few variants (GetVariable ("Health") Can'get get anywhere though. Thanks, Scarn.
USA #6
Get rid of the OnPluginBroadcast function and replace the stats table with:


stats = {
  percent = function (stat)
    local x = math.floor (tonumber (GetPluginVariable ("", stat))/tonumber (GetPluginVariable ("", "max" .. stat))*100)
    if x > 100 then x = 100 elseif x < 0 then x = 0 end
    return x
  end, -- func
  }


Just make sure you have each stat and max stat as a variable in the World, by the same names as used in the table.
Amended on Fri 29 Aug 2008 07:18 AM by Fadedparadox
#7
Error number: 0
Event: Run-time error
Description: [string "Plugin"]:7: attempt to perform arithmetic on a nil value

stack traceback:

[string "Plugin"]:7: in function 'percent'

[string "Plugin"]:41: in function 'draw'

[string "Plugin"]:51: in main chunk
Called by: Immediate execution


Here is the plugin, im royally confused now.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
name="Gauges"
author="Trevize"
id="0860ccb8e0e747814da4d907"
language="Lua"
purpose="gauges"
date_written="2008-08-18"
requires="4.35"
version="1.01"
>
</plugin>

<script><![CDATA[

TextRectangle (300, 0, 0, 0, 0, 0x000000, 0, 0x000000, 0)



stats = {
percent = function (health)
local x = math.floor (tonumber (GetPluginVariable ("Health", health))/tonumber (GetPluginVariable ("", "max" .. health))*100)
if x > 100 then x = 100 elseif x < 0 then x = 0 end
return x
end, -- func
}




gauges = {
name = GetWorldID () .. "1",

position = {5, 20, 35, 50, 65},

create = function (txt, num, col, pos)
WindowRectOp (gauges.name, 1,
26, gauges.position[pos]-1, 127, gauges.position[pos]+1,
ColourNameToRGB ("silver"))
WindowRectOp (gauges.name, 2,
27, gauges.position[pos], 127, gauges.position[pos]+10,
0x010101)
WindowRectOp (gauges.name, 2,
27, gauges.position[pos], 127-(100-num), gauges.position[pos]+10,
ColourNameToRGB (col))
local txtwidth = WindowTextWidth (gauges.name, "font", txt)
WindowRectOp (gauges.name, 2,
25-(txtwidth), gauges.position[pos], 25, gauges.position[pos]+10,
0x010101)
WindowText (gauges.name, "font", txt,
25-(txtwidth), gauges.position[pos], 0, gauges.position[pos]+10,
ColourNameToRGB ("silver"), false)
end, -- func

draw = function ()
gauges.create ("H:", stats.percent ("health"), "red", 1)
end, -- func
}

WindowCreate (gauges.name, 0, 0, 133, 80, 10, 4, ColourNameToRGB ("black"))
WindowFont (gauges.name, "font", "Lucida Console", 8, false, false, false, false)
gauges.draw ()
WindowShow (gauges.name, true)



]]></script>

</muclient>

USA #8
You changed it. Put the script in exactly how I posted.
#9
Ok so I'm a total noob, to muds and to MUSHclient. I've just downloaded it today and would like to know how to install/use these plugins.

I've downloaded those files, saved them as XML's and moved them to the plugin directory.

While in MUSHclient used "File->Plugins->Add" but I get errors as soon as they are loaded.

I think that I'm somehow downloading them wrong because the files I get don't look like XML files.

Any help will be appreciated, thanks!
Netherlands #10
You need to extract the file first, using a program like WinRAR or 7-zip. Merely renaming the compressed files does not make it possible for MUSHclient to read the plugin. :)
#11
Ok, the problem wasn't the zip folders, it was the xml files. The first two files in the list.

How am I supposed to get the first two files to work?
#12
nevermind, it was my browser that wouldn't let me get the files in the right format
#13
I am having some trouble with installing this plugin. The NCompass and Ngauges are not working for some reason. I got the following error message when I try to install the Compass plugin.

Run-time error
Plugin: Compass (called from world: Achaea)
Function/Sub: OnPluginBroadcast called by Plugin Compass
Reason: Executing plugin Compass sub OnPluginBroadcast
[string "Plugin"]:85: attempt to perform arithmetic on field '?' (a nil value)
stack traceback:
[string "Plugin"]:85: in function 'create'
[string "Plugin"]:99: in function 'draw'
[string "Plugin"]:28: in function <[string "Plugin"]:25>
Error context in script:
81 : for dir in tpairs (compass.active) do
82 : if compass.directions[dir] then
83 : local left = compass.location[dir][1]
84 : local top = compass.location[dir][2]
85*: local right = compass.location[dir][1] + compass.dimension[dir][1]
86 : local bottom = compass.location[dir][2] + compass.dimension[dir][2]
87 : WindowDrawImage (compass.name, dir,
88 : left, top, right, bottom, 1)
89 : WindowAddHotspot (compass.name, dir,

Thanks in advance.

Regards

Speedy999
Amended on Fri 05 Jun 2009 01:01 PM by Speedy999
Australia Forum Administrator #14
Is that copied and pasted, or retyped? I didn't write that plugin, but I am not familiar with the tpairs function used near the top of your message.

Also, this looks strange:

85*: local right = compass.location[dir][1] + compass.dimension[dir][1]

It seems to be adding something to itself. Something which, according to the error, is nil (that is, the value does not exist).
#15
That is copy and pasted
USA #16
I've just had two new people get that error when using the compass plugin. Here's a screenshot one of them posted on another forum:

http://i60.photobucket.com/albums/h12/Kaedinvars/MUSHSCREEN.jpg

They get it upon installation. The compass files linked in the original post are the ones they're using. I'm completely unable to duplicate this error.

What you said in your post, Nick: "85*: local right = compass.location[dir][1] + compass.dimension[dir][1]" about that looking strange, basically I have a table, compass.location, that has the starting point (upper left) of each arrow. I also have compass.dimension defined at the bottom of the plugin, when it's created, to be the dimensions of each arrow. The line makes the right property of the image the left side plus the width.

The origin of the error is the OnPluginBroadcast function. It calls draw which calls create, which is where the error seems to be. It sees compass.location[dir][1] or compass.dimension[dir][1] as nil. Both should be set, and at least when I use it, are. The only thing I could think of is when they're set, it uses the image width/height but even when I don't have the images where the plugin expects, it doesn't error out.

I can't seem to duplicate this error, no matter how hard I try. Any ideas?
Amended on Sun 07 Jun 2009 12:00 PM by Fadedparadox
USA #17
An update, I've narrowed it down to either:

1. compass.location[dir][1] not existing
2. compass.dimension[dir][1] not existing

It gives an error with '?' in it. I am sure that both compass.location[dir] and compass.dimension[dir] exist, as I get a 'cannot index...' error if I delete either of them where they're made. Same with compass.location and compass.dimension. And I get an error with 'compass' in it if I delete compass entirely. I only get the '?' error if it's the key 1 that doesn't exist.

I still can't play with it to find which of the two, or the exact cause, though, since I can't make it happen as the plugin is now.
Amended on Sun 07 Jun 2009 09:45 PM by Fadedparadox
Australia Forum Administrator #18
I apologize, I misread the earlier message, the add is not adding something to itself.

The only thing I can see would go wrong is this:


for dir in pairs (compass.directions) do
  WindowLoadImage (compass.name, dir, plugindir .. [[compass/arrow_]] .. dir .. ".bmp")
  compass.dimension[dir] = {}
  compass.dimension[dir][1] = WindowImageInfo(compass.name, dir, 2)
  compass.dimension[dir][2] = WindowImageInfo(compass.name, dir, 3)
end -- for


Now if the file compass/arrow_ne (for example) doesn't exist, then the WindowLoadImage will fail, and the WindowImageInfo will return nil, which would account for the later error.

I would check the return code from WindowLoadImage. Perhaps they didn't load the images where they were supposed to?
USA #19
Ah. Finally.

That worked, thanks Nick. You were right, they must not have the images in the right place.

I tried moving the images before then adding the plugin and it still worked. Guess I did something in the wrong order before, and somehow avoided the error.

Appreciate it!
#20
Thanks very much for your efforts. Is there anything I should change to fix it?
USA #21
Delete the plugin and images you have now. Go to my new website and get the file here:

http://sites.google.com/site/trevizemoonflair/mushclient/ncompass

I updated it to not only not error out if the images aren't in the right place, but to also tell you where they should be.
#22
It works now.

Thanks very much for all your help
USA #23
Awesome! And my pleasure.
Australia Forum Administrator #24
Your screenshot site mentioned in the earlier post:

http://sites.google.com/site/fadedparadox/screenshots/gauges-compass.jpg

... gives me:


Forbidden

Error 403


USA #25
Sorry about that! Google quit supporting google pages, in favour of google sites, and so all my stuff had to be moved over. Here's a new image:

http://sites.google.com/site/trevizemoonflair/screenshots/MUSHclient_compass_gauges.png

I fixed the old link too.