Difference between revisions of "Manual:Mudlet Packages"

From Mudlet
Jump to navigation Jump to search
Line 81: Line 81:
  
 
== Requires ==
 
== Requires ==
As of mudlet 3.6.2 you can require "file" from the profile folder.
+
As of mudlet 3.6.2 you can <code>require "file"</code> from the profile folder.
As an example, if you have your package "sipper", using a custom echo function named "sipperecho" defined in "customFunctions.lua" you can
+
 
 +
As an example, if you have your package '''sipper''', using a custom echo function named '''sipperecho''' defined in '''customFunctions.lua''' you can
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
Line 90: Line 91:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Alternatively you can rename "customFunctions.lua" to "init.lua", this will allow you to simply require "<name of your package>" and
+
Alternatively you can rename '''customFunctions.lua''' to '''init.lua''', this will allow you to simply <code>require "<name of your package>"</code> and
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">

Revision as of 18:50, 20 December 2017

What is a Mudlet package

It's a archive file that ends with .mpackage or .zip that contains xml files to import along with any resources a package might have (images, sounds and etc). Packages can be installed / uninstalled via a window in Mudlet.

The system is backwards-compatible and existing .xml files will also be recognized as packages.

You'll see packages represented in brown in the script editor everywhere - triggers, aliases, etc. All items of a package have to go into a package folder that they belong in - so the user can know which package do items belong to, and modify the package for their needs (if it didn't have a folder, then you wouldn't be able to 'add' anything to a package).

Mudlet Packages were introduced to Mudlet in the 2.0 release.

How to install a Mudlet package

manually

Toolbox→Package Manager will open the window where you can 'Install' to install a package. The package will then get merged into the Mudlet profile and can be deleted.

as a module

Toolbox→Module Manager will allow you to install a package into many profiles at once, and it will keep it in sync across them if you edit it in one profile. The package is also not merged into your Mudlet profile, but loaded from, and saved to, the original file you installed it from - particularly useful for package authors as you don't have to re-export after your changes.

(xmls installed via Import will be converted to packages too, but do not Import packages.)

as a one-liner

As a script writer, you can also allow people to just copy/paste a command into Mudlet to install your package - super easy. Here's a demo, paste this into Mudlet:

lua function d(a,b)if not b:find("oci",1,true)then return end installPackage(b)os.remove(b)cecho("<lime_green>Package installed!\n")end registerAnonymousEventHandler("sysDownloadDone","d")downloadFile(getMudletHomeDir().."/oci.mpackage","http://www.mudlet.org/wp-content/files/one-click-install-demo.mpackage")

To get such a line for your script, do the following:

1) Copy/paste code below to https://mothereff.in/lua-minifier

local URL = "http://www.mudlet.org/wp-content/files/one-click-install-demo.mpackage"

function d(_, f)
  if not f:find("oci", 1, true) then return end
 
  installPackage(f)
  os.remove(f)
  cecho("<lime_green>Package installed!\n")
end
 
registerAnonymousEventHandler("sysDownloadDone", "d")

downloadFile(getMudletHomeDir()..(URL:ends("xml") and "/oci.xml" or "/oci.zip"), URL)

2) replace the URL (the http://www.mudlet.org/wp-content/files/one-click-install-demo.mpackage bit) with your .zip, .mpackage, or .xml URL

3) find & replace all semicolons (;) with spaces ( ) in the minified version

4) prefix it with 'lua ' and paste it into Mudlet!

note: requires Mudlet 3.0 to work.

from the MUD

Packages can also be auto-installed from the MUD server via ATCP or GMCP - see ATCP extensions or GMCP extensions for more.

How to create a Mudlet package

Create a zip file that ends with either .mpackage (preferred) or .zip. Include all xml's that you'd like to be installed in the top level folder of the package (that is, don't have them within a folder in the archive - just have them be upfront).

Naming the package

Add a file at the top level of the package (so not inside any folders in the package) called config.lua that has the following line to name your package:

mpackage = "<name of your package>"

That's it. If you don't include config.lua, Mudlet will then deduce the package name from the file name.

Including images, sounds, and other files

If you'd like to include other folders or files in the package, you can - they will be copied into getMudletHomeDir().."/"..packagename upon installation, so your scripts can use them. For example, if your package is called "sipper" and you have health.png as an image in it, you can place on a label like so:

-- you don't have to worry about \ versus / for file paths - use / everywhere, Lua will make it work on Windows fine

setBackgroundImage("my health label", getMudletHomeDir().."/sipper/health.png")

Install the one-liner package demo above for an example of how to make use of images in packages.

Requires

As of mudlet 3.6.2 you can require "file" from the profile folder.

As an example, if you have your package sipper, using a custom echo function named sipperecho defined in customFunctions.lua you can

require "sipper.customFunctions"

sipperecho("I work")

Alternatively you can rename customFunctions.lua to init.lua, this will allow you to simply require "<name of your package>" and

require "sipper"

sipperecho("I work")