PNPC.lua

From Moondust Wiki
Revision as of 05:27, 1 March 2015 by Rednaxela (talk | contribs)
Jump to navigation Jump to search


Download Latest Version

pNPC is a library for getting a wrapper object for NPC class objects LunaLua, which unlike those remains valid across ticks.

For extra utility it also provides a uid and a property for user-defined data storage.

Installation

Place the file pnpc.lua into the LuaScriptsLib folder.

How to use

To enable the pNPC library for a specific level, add this line to lunadll.lua:

local pNPC = loadAPI("pnpc");

This will load the pNPC API.

External Use Functions

These are functions you will need to use the library

wrap npc
Get a wrapper around a specified NPC which will remain valid across ticks. If one already exists, it is returned, otherwise a new one is created. NPC-like Wrapper NPC

The NPC to wrap.

getExistingWrapper npc
Get a wrapper around a specified NPC which will remain valid across ticks. If one doesn't already exist, return nil. NPC-like Wrapper NPC

The NPC to find the wrapper for

The NPC Wrapper

All properties supported by LunaLua's NPC class are automatically supported.

The mem and kill methods are also supported.

There are four additional properties defined:

data A table which user-defined data associated with the NPC can be entered into
uid (read-only) A unique identifier for this NPC
pid (read-only) The persistence identifier for this NPC. If the uid is less than 0x8000, it is guaranteed to be the same as pid. Intended for debugging.
pidIsDirty (read-only) Flag to indicate that the persistence identifier is recycled. Intended for debugging.