Jump to content

Author script for adding commands to items


charlenni

Recommended Posts

Hello,

 

the appended Lua script add functionality for normal items. Each item need scripts to add a take and a drop command with scripts. For most of this items, this script installs defaults. You could also add other commands very easy. Copy the functions to your author script section.

 

function AddDefaultCommands(CartridgeFile,OptionalItemTable)

Add the commands "Take" and "Drop" to each item in the cartridge or to each item listed in "OptionalItemTable" (example: {zitemItem1,zitemItem2}). If the item already have a command with this name, the command will not overwritten. So you can make your special "Take" and "Drop" scripts with the builder. You need also the functions "TakeItem" (called on OnTake), "DropItem" (called on OnDrop) and GetActiveZone (called from DropItem to get a zone, if you are not in a zone, you get a message, that you couldn't drop the item)

 

function AddCommand(CartridgeFile,Command,Enabled,Function,OptionalItemTable)

Add the command "Command" (example: "Lock") with state enabled as "Enabled" (true) to all items in the cartridge or to all item in OptionalItemTable (example: {zitemItem1}). If then event OnCommand (example: OnLock) occures, the function "Function (example: "LockItem", string) will be called.

 

Both functions are implemented in a small cartridge to show the behavior.

 

Related ideas are welcome!

 

Best regards

Dirk

DefaultCommands.zip

Link to comment

This script is absolutelly great. I had used similar technique in my Cartridge Arabela, but this is much better code. Using lua functions with self parametr is great idea.

But the best in this code is use of loadstring to asign function to command. But there is a little bug - when Item.Name contains spaces, it throws an error.

So it is better to replace spaces in Name:

f = loadstring("zitem"..string.gsub(v.Name," ","")..".On"..parCommand.." = "..parFunction)

Anyway, thanks a lot for this usefull script.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...