StendhalScripting/LuaAPI: Difference between revisions

From Arianne
Jump to navigation Jump to search
Content deleted Content added
imported>AntumDeluge
game: added "game:setMusic" method
imported>AntumDeluge
add scripting category
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Navigation for Stendhal Top|Playing}}

The following objects & functions are exposed to the Lua engine:
The following objects & functions are exposed to the Lua engine:


Line 37: Line 39:


Methods:
Methods:

* ''<span style="color:green;">logger:info</span>(message)''
; ''<span style="color:green;">logger:info</span>(message)''
** Prints an information level message to the console.
: Prints an information level message to the console.
** <span style="color:darkblue; font-style:italic;">message:</span> Text to be printed.
: '''''message:''''' Text to be printed.
* ''<span style="color:green;">logger:warn</span>(message)''

** Prints a warning level message to the console.
** <span style="color:darkblue; font-style:italic;">message:</span> Text to be printed.
; ''<span style="color:green;">logger:warn</span>(message)''
: Prints a warning level message to the console.
* ''<span style="color:green;">logger:error</span>(message)''
: '''''message:''''' Text to be printed.
** Prints an error level message to the console.

** <span style="color:darkblue; font-style:italic;">message:</span> Text to be printed.
; ''<span style="color:green;">logger:error</span>(message)''
: Prints an error level message to the console.
: '''''message:''''' Text to be printed.


Example usage:
Example usage:
Line 60: Line 65:


Defines functions for accessing Java system properties.
Defines functions for accessing Java system properties.

Methods:

; ''<span style="color:green;">properties:getValue</span>(p)''
: Retrieves the value of a property.
: '''''p:''''' (string) Property name.
: '''''returns:''''' (string) Property value or `nil`.

; ''<span style="color:green;">properties:enabled</span>(p)''
: Checks if a property is enabed.
: '''''p:''''' (string) Property name.
: '''''returns:''''' (boolean) `true` if enabled.

; ''<span style="color:green;">properties:equals</span>(p, v)''
: Checks if a property is set to a specified value.
: '''''p:''''' (string) Property name.
: '''''v:''''' (string) Value to compare with.
: '''''returns:''''' (boolean) `true` if the value of the property is the same as `v`.

Examples usage:

<pre>
-- example of only executing script contents on test server

if not properties:enabed("stendhal.testserver") then
do return end
end
</pre>


== game ==
== game ==
Line 66: Line 99:


Methods:
Methods:

* ''<span style="color:green">game:add</span>(npc)''
* ''<span style="color:green">game:add</span>(object)'' - Adds an object to the current zone.
; ''<span style="color:green">game:add</span>(object)''
: Adds an {{MarauroaFile|master|src/marauroa/common/game/RPObject.java|RPObject}} instance to the current zone.
* ''<span style="color:green">game:add</span>(creature, x, y)''
: '''''object:''''' Object to add.
* ''<span style="color:green">game:remove</span>(npc)''

* ''<span style="color:green">game:remove</span>(object)''
* ''<span style="color:green">game:addGameEvent</span>(source, event, params)''
; ''<span style="color:green">game:add</span>(npc)''
: Adds an {{StendhalFile|master|src/games/stendhal/server/entity/npc/NPC.java|NPC}} instance to the current zone.
* ''<span style="color:green">game:setZone</span>(name)'' - Sets the current zone.
: '''''npc:''''' NPC to add.
* ''<span style="color:green">game:setZone</span>(zone)''

* ''<span style="color:green">game:getZone</span>(rpobject)''
; ''<span style="color:green">game:add</span>(creature, x, y)''
: Adds a {{StendhalFile|master|src/games/stendhal/server/entity/creature/Creature.java|Creature}} instance to the current zone.
: '''''creature:''''' Creature to add.
: '''''x:''''' Horizontal position of where to add creature.
: '''''y:''''' Vertical position of where to add creature.

; ''<span style="color:green">game:remove</span>(object)''
:
: '''''object:'''''

; ''<span style="color:green">game:remove</span>(npc)''
:
: '''''npc:'''''

; ''<span style="color:green">game:addGameEvent</span>(source, event, params)''
: Adds a new {{StendhalFile|master|src/games/stendhal/server/core/engine/GameEvent.java|GameEvent}}.
: '''''source:'''''
: '''''event:'''''
: '''''params:'''''

; ''<span style="color:green">game:setZone</span>(name)''
: Sets the current zone.
: '''''name:''''' String identifier for zone to be set as current zone.
: ''returns:'' <code>true</code> if zone was successfully set.

; ''<span style="color:green">game:setZone</span>(zone)''
: Sets the current zone.
: '''''zone:''''' {{StendhalFile|master|src/games/stendhal/server/core/engine/StendhalRPZone.java|StendhalRPZone}} instance to set as current zone.
: ''returns:'' <code>true</code> if zone was successfully set.

; ''<span style="color:green">game:getZone</span>(object)''
: Retrieves the zone where <code>object</code> is located.
: '''''object:''''' The {{MarauroaFile|master|src/marauroa/common/game/RPObject.java|RPObject}} from which the zone should be retrieved.
: ''returns:'' {{StendhalFile|master|src/games/stendhal/server/core/engine/StendhalRPZone.java|StendhalRPZone}} or <code>null</code> if it doesn't exists

; ''<span style="color:green">game:getZone</span>(name)''
: Retrieves a zone by string ID.
: '''''zoneName:''''' Name of zone to retrieve.
: ''returns:'' {{StendhalFile|master|src/games/stendhal/server/core/engine/StendhalRPZone.java|StendhalRPZone}} or <code>null</code> if it doesn't exist.


; ''<span style="color:green">game:setMusic</span>(filename, args)''
; ''<span style="color:green">game:setMusic</span>(filename, args)''
Line 88: Line 160:
::: <span style="color:darkblue; font-style:italic;">radius:</span> The radius from which the music can be heard (default: 10000).
::: <span style="color:darkblue; font-style:italic;">radius:</span> The radius from which the music can be heard (default: 10000).


* ''<span style="color:green">game:playerIsInZone</span>(player, zoneName)''
; ''<span style="color:green">game:playerIsInZone</span>(player, zoneName)''
:
* ''<span style="color:green">game:getCreatures</span>()''
: '''''player:'''''
* ''<span style="color:green">game:getCreature</span>(clazz)''
: '''''zoneName:'''''
* ''<span style="color:green">game:getItems</span>()''
: ''returns:'' <code>boolean</code>
* ''<span style="color:green">game:getItem</span>(name)''

* ''<span style="color:green">game:modify</span>(entity)''
* ''<span style="color:green">game:privateText</span>(player, text)''
; ''<span style="color:green">game:getCreatures</span>()''
:
* ''<span style="color:green">game:getMessage</span>()''
: ''returns:'' An array of all available creatures.
* ''<span style="color:green">game:setMessage</span>(message)''

; ''<span style="color:green">game:getCreature</span>(clazz)''
: Retrieves a {{StendhalFile|master|src/games/stendhal/server/entity/creature/Creature.java|Creature}} instance.
: '''''clazz:''''' String name of the creature.
: ''returns:'' Creature or <code>null</code> if doesn't exist.

; ''<span style="color:green">game:getItems</span>()''
:
: ''returns:'' Array list of available items.

; ''<span style="color:green">game:getItem</span>(name)''
:
: '''name:'''
: ''returns:'' Item instance or <code>null</code> if doesn't exist.

; ''<span style="color:green">game:modify</span>(entity)''
:
: '''''entity:'''''

; ''<span style="color:green">game:privateText</span>(player, text)''
: Sends a private text to a player.
: '''''player:''''' Player to receive the message.
: '''''text:''''' Message text to send to player.

; ''<span style="color:green">game:getMessage</span>()''
:
: ''returns:'' <code>String</code>


== entities ==
== entities ==

See also: [[StendhalAPI#Entities]] for public methods that can be performed on <code>Entity</code> objects.


Methods:
Methods:

* ''<span style="color:green">entities:getPlayer</span>(name)''
* ''<span style="color:green">entities:getNPC</span>(name)''
; ''<span style="color:green">entities:getPlayer</span>(name)''
: Retrieves a logged in Player.
* ''<span style="color:green">entities:getItem</span>(name)''
: '''''name:''''' (<code>String</code>) Name of player.
* ''<span style="color:green">entities:getStackableItem</span>(name)''
: ''returns:'' Logged in {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} or <code>null</code>.
* ''<span style="color:green">entities:createSpeakerNPC</span>(name)''

* ''<span style="color:green">entities:createSilentNPC</span>()''
* ''<span style="color:green">entities:setPath</span>(entity, table, loop)''
; ''<span style="color:green">entities:getNPC</span>(name)''
: Retrieves an existing SpeakerNPC.
* ''<span style="color:green">entities:setPathAndPosition</span>(entity, table, loop)''
: '''''name:''''' (<code>String</code>) Name of NPC.
* ''<span style="color:green">entities:createSign</span>(visible)''
: ''returns:'' [[StendhalScripting/LuaAPI#LuaSpeakerNPC|SpeakerNPC]] instance or <code>null</code>.
* ''<span style="color:green">entities:createShopSign</span>(name, title, caption, seller)''

; ''<span style="color:green">entities:getItem</span>(name)''
: Retrieves a registered Item.
: '''''name:''''' (<code>String</code>) Name of the item.
: ''returns:'' {{StendhalFile|master|src/games/stendhal/server/entity/item/Item.java|Item}} instance or <code>null</code> if not a registered item.

; ''<span style="color:green">entities:getStackableItem</span>(name)''
: Retrieves a registered StackableItem.
: '''''name:''''' (<code>String</code>) Name of the item.
: ''returns:'' {{StendhalFile|master|src/games/stendhal/server/entity/item/StackableItem.java|StackableItem}} instance or <code>null</code> if not a registered stackable item.

; ''<span style="color:green">entities:createSpeakerNPC</span>(name)''
: Creates an interactive NPC.
: '''''name:''''' (<code>String</code>) Name of new NPC.
: ''returns:'' New [[StendhalScripting/LuaAPI#LuaSpeakerNPC|SpeakerNPC]] instance.

; ''<span style="color:green">entities:createSilentNPC</span>()''
: Creates a non-interactive NPC.
: ''returns:'' New [[StendhalScripting/LuaAPI#LuaSilentNPC|SilentNPC]] instance.

; ''<span style="color:green">entities:setPath</span>(entity, table, loop)''
: '''''DEPRECATED:''' path can now be set by directly calling the NPC's <code>setPath</code> method''
: Helper method for setting an NPC's path.
: '''''entity:''''' (<code>RPEntity</code>) Then entity whose path is being set.
: '''''table:''''' (<code>LuaTable</code>) Table with list of coordinates representing nodes.
: '''''loop:''''' (<code>boolean</code>) If <code>true</code>, the entity's path should loop.

; ''<span style="color:green">entities:setPathAndPosition</span>(entity, table, loop)'' <nowiki>
: '''''DEPRECATED:''' path can now be set by directly calling the NPC's <code>setPath</code> method''
: Helper function for setting an NPC's path & starting position.
: '''''entity:''''' (<code>RPEntity</code>) Then entity whose path is being set.
: '''''table:''''' (<code>LuaTable</code>) Table with list of coordinates representing nodes.
: '''''loop:''''' (<code>boolean</code>) If <code>true</code>, the entity's path should loop.

; ''<span style="color:green">entities:createSign</span>(visible)''
: Creates a new {{StendhalFile|master|src/games/stendhal/server/entity/sign/Sign.java|Sign}} entity.
: '''''visible:''''' (<code>boolean</code>) (optional) If <code>false</code>, the sign will not have a visual representation.
: ''returns:'' New <code>Sign</code> instance.

; ''<span style="color:green">entities:createShopSign</span>(name, title, caption, seller)''
: Creates a new {{StendhalFile|master|src/games/stendhal/server/entity/sign/ShopSign.java|ShopSign}} entity.
: '''''name:''''' (<code>String</code>) The shop name.
: '''''title:''''' (<code>String</code>) The sign title.
: '''''caption:''''' (<code>String</code>) The caption above the table.
: '''''seller:''''' (<code>boolean</code>) <code>true</code>, if this sign is for items sold by an NPC (defaults to <code>true</code> if <code>null</code>).
: ''returns:'' New <code>ShopSign</code> instance.

; ''<span style="color:green;">entities:summonCreature</span>(table)''
: Summons a creature into the area.
: '''''table:''''' Key-value table containing parameters for summoning creature.
:; ''keys:''
:: ''<span style="color:blue;">name:</span>'' (<code>string</code>) Name of creature to be summoned.
:: ''<span style="color:blue;">zone:</span>'' (<code>string</code>) Name of zone where creature should be summoned.
:: ''<span style="color:blue;">x:</span>'' (<code>int</code>) Horizontal position of summon location.
:: ''<span style="color:blue;">y:</span>'' (<code>int</code>) Vertical position of summon location.
:: ''<span style="color:blue;">summoner:</span>'' (<code>string</code>) (optional) Name of entity doing the summoning (used for logging game events).
:: ''<span style="color:blue;">raid:</span>'' (<code>bool</code>) (optional) Whether or not the creature should be a <code>RaidCreature</code> instance (default: true).

=== Lua Entity Classes ===

==== LuaSpeakerNPC ====

* Inherits: [[StendhalAPI#SpeakerNPC|SpeakerNPC]]

Public methods:

{{PublicMethod | add | params=states, triggers, conditions, nextState, reply, actions | desc=Additional method to support passing Lua data types as parameters. | paramlist=
{{MethodParam | states | desc=The conversation state(s) the entity should be in to trigger response. Can be [[StendhalAPI#ConversationStates|ConversationStates enum]] value or <code>LuaTable</code> of ConversationStates. }}
{{MethodParam | triggers | desc=<code>String</code> or <code>LuaTable</code> of strings to trigger response. }}
{{MethodParam | conditions | desc=Conditions to check for this response. Can be [[StendhalAPI#ChatCondition|ChatCondition instance]], a <code>LuaTable</code> of ChatCondition instances, or a function. }}
{{MethodParam | nextState | type=ConversationState | desc=Conversation state to set entity to after response. }}
{{MethodParam | reply | type=String | desc=The NPC's response or <code>null</code>. }}
{{MethodParam | actions | desc=Actions to execute. Can be [[StendhalAPI#ChatAction|ChatAction instance]], a <code>LuaTable</code> of ChatAction instances, or a function. }} }}

{{PublicMethod | setPath | params=table, loop | desc=Set a path for this entity to follow. | paramlist=
{{MethodParam | table | type=table | desc=Table of coordinates to set as path. Example: <code>{{35, 79}, {35, 89}, {40, 89}}</code> }}
{{MethodParam | loop | type=boolean | desc=(optional) If <code>true</code>, entity should loop around to restart path when reaching the end. }} }}

{{PublicMethod | setPathAndPosition | params=table, loop | desc=Set path & starting position for entity. The starting position is the first node in the path. | paramlist=
{{MethodParam | table | type=table | desc=Table of coordinates to set as path. Example: <code>{{35, 79}, {35, 89}, {40, 89}}</code> }}
{{MethodParam | loop | type=boolean | desc=(optional) If <code>true</code>, entity should loop around to restart path when reaching the end. }} }}

==== LuaSilentNPC ====

* Inherits: [[StendhalAPI#SilentNPC|SilentNPC]]

Public methods:

{{PublicMethod | setPath | params=table, loop | desc=Set a path for this entity to follow. | paramlist=
{{MethodParam | table | type=table | desc=Table of coordinates to set as path. Example: <code>{{35, 79}, {35, 89}, {40, 89}}</code> }}
{{MethodParam | loop | type=boolean | desc=(optional) If <code>true</code>, entity should loop around to restart path when reaching the end. }} }}

{{PublicMethod | setPathAndPosition | params=table, loop | desc=Set path & starting position for entity. The starting position is the first node in the path. | paramlist=
{{MethodParam | table | type=table | desc=Table of coordinates to set as path. Example: <code>{{35, 79}, {35, 89}, {40, 89}}</code> }}
{{MethodParam | loop | type=boolean | desc=(optional) If <code>true</code>, entity should loop around to restart path when reaching the end. }} }}

=== entities.manager ===

This is simply the {{StendhalFile|master|src/games/stendhal/server/core/rule/defaultruleset/DefaultEntityManager.java|entity manager}} instance.

Public methods:

'''''TODO'''''


== quests ==
== quests ==
Line 117: Line 321:


Methods:
Methods:

* ''<span style="color:green">quests:createQuest</span>(slotName, name)''
* ''<span style="color:green">quests:load</span>(quest)''
; ''<span style="color:green">quests:create</span>(slotName, name)''
: Creates a new quest.
* ''<span style="color:green">quests:unload</span>(questName)''
: '''''slotName:''''' (optional) The string identifier for the quest.
* ''<span style="color:green">quests:cache</span>(quest)''
: '''''name:''''' (optional) The human-readable name that can be shown in travel log.
* ''<span style="color:green">quests:register</span>(quest)'' Alias for ''<span style="color:green;">quests:cache</span></span>(quest)''.
: ''returns:'' New {{StendhalFile|master|src/games/stendhal/server/core/scripting/lua/QuestHelper.java|games.stendhal.server.core.scripting.lua.QuestHelper.LuaQuest}} instance.
* ''<span style="color:green">quests:isLoaded</span>(quest)''

* ''<span style="color:green">quests:listAll</span>(player)''
* ''<span style="color:green">quests:list</span>(player, questName)''
; ''<span style="color:green">quests:load</span>(quest)''
: Adds a quest to the world.
* ''<span style="color:green">quests:listStates</span>(player)''
: '''''quest:''''' The {{StendhalFile|master|src/games/stendhal/server/maps/quests/IQuest.java|IQuest}} instance to be loaded.
* ''<span style="color:green">quests:getQuest</span>()''

* ''<span style="color:green">quests:getQuestFromSlot</span>(questSlot)''
* ''<span style="color:green">quests:getOpen</span>(player)''
; ''<span style="color:green">quests:unload</span>(questName)''
: Removes a quest from the world.
* ''<span style="color:green">quests:getCompleted</span>(player)''
: '''''questName:''''' String name of the quest to be removed.
* ''<span style="color:green">quests:getIncomplete</span>(player, region)''

* ''<span style="color:green">quests:getRepeatable</span>(player)''
* ''<span style="color:green">quests:getDescription</span>(player, questName)''
; ''<span style="color:green">quests:cache</span>(quest)''
: Caches a quest for loading at server startup.
* ''<span style="color:green">quests:getLevelWarning</span>(player, questeName)''
: '''''quest:''''' {{StendhalFile|master|src/games/stendhal/server/maps/quests/IQuest.java|IQuest}} instance to be loaded.
* ''<span style="color:green">quests:getProgressDetails</span>(player, questeName)''
:; ''aliases:''
* ''<span style="color:green">quests:getNPCNamesForUnstartedInRegionForLevel</span>(player, region)''
* ''<span style="color:green">quests:getDescriptionForUnstartedInRegionFromNPCName</span>(player, region, name)''
:: ''<span style="color:green">quests:register</span>''

; ''<span style="color:green">quests:isLoaded</span>(quest)''
: Checks if a quest has been loaded.
: '''''quest:''''' {{StendhalFile|master|src/games/stendhal/server/maps/quests/IQuest.java|IQuest}} instance to check.
: ''returns:'' <code>true</code> if the instance matches stored quests.

; ''<span style="color:green">quests:listAll</span>(player)''
: List all quests the player knows about.
: '''''player:''''' Player to create the report for.
: ''returns:'' String report.

; ''<span style="color:green">quests:list</span>(player, questName)''
: Creates a report on a specified quest for a player.
: '''''player:''''' Player to create the report for.
: '''''questName:''''' Name of quest to be reported.
: ''returns:'' String report.

; ''<span style="color:green">quests:listStates</span>(player)''
: Dumps the internal quest states for the specified player. This is used for the {{StendhalFile|master|src/games/stendhal/server/action/admin/InspectAction.java|InspectAction}}.
: '''''player:''''' Player to create the report for.
: ''returns:'' String report.

; ''<span style="color:green">quests:getQuest</span>(questName)''
: Retrieves the {{StendhalFile|master|src/games/stendhal/server/maps/quests/IQuest.java|IQuest}} object for a named quest.
: '''''questName:''''' Name of quest.
: ''returns:'' <code>IQuest</code> or <code>null</code> if doesn't exist.

; ''<span style="color:green">quests:getQuestFromSlot</span>(questSlot)''
: Retrieves the {{StendhalFile|master|src/games/stendhal/server/maps/quests/IQuest.java|IQuest}} object for a quest.
: '''''questSlot:''''' Quest identifier string.
: ''returns:'' <code>IQuest</code> or <code>null</code> if doesn't exist.

; ''<span style="color:green">quests:getOpen</span>(player)''
: Retrieves a list of open quests from a player.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: ''returns:'' List of string identifiers for open quests.

; ''<span style="color:green">quests:getCompleted</span>(player)''
: Retrieves a list of completed quests from a player.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: ''returns:'' List of string identifiers for completed quests.

; ''<span style="color:green">quests:getIncomplete</span>(player, region)''
: Retrieves a list of incomplete quests in a specified region.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: '''''region:''''' Region name/identifier.
: ''returns:'' List of string identifiers of incomplete quests in region.

; ''<span style="color:green">quests:getRepeatable</span>(player)''
: Retrieves a list of quests a player has completed, and can now do again.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: ''returns:''

; ''<span style="color:green">quests:getDescription</span>(player, questName)''
: Retrieves the description of a quest.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: '''''questName:''''' Name of the quest.
: ''returns:'' <code>String</code> description.

; ''<span style="color:green">quests:getLevelWarning</span>(player, questName)''
: If the quest is too dangerous, add a warning unless the player has already completed it.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: '''''questName:''''' Name of the quest.
: ''returns:'' <code>String</code>

; ''<span style="color:green">quests:getProgressDetails</span>(player, questeName)''
: Retrieves details on the progress of the quest.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: '''''questName:''''' Name of the quest.
: ''returns:'' <code>List<String></code>

; ''<span style="color:green">quests:getNPCNamesForUnstartedInRegionForLevel</span>(player, region)''
: Retrieves a list of the unique npc names for unstarted quests in a specified region.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: '''''region:''''' Region to check in.
: ''returns:'' <code>List<String></code>

; ''<span style="color:green">quests:getDescriptionForUnstartedInRegionFromNPCName</span>(player, region, name)''
: Retrieves quest descriptions for unstarted quests in a specified region matching a specific NPC name.
: '''''player:''''' {{StendhalFile|master|src/games/stendhal/server/entity/player/Player.java|Player}} instance to be checked.
: '''''region:''''' Region to check in.
: '''''name:''''' Name of NPC.
: ''returns:'' <code>List<String></code>


=== quests.simple ===
=== quests.simple ===
Line 143: Line 430:


Methods:
Methods:

* ''<span style="color:green">quests.simple:create</span></span>(slotName, properName, npcName)''
** <span style="color:darkblue; font-style:italic;">slotName:</span> (string)
; ''<span style="color:green">quests.simple:create</span></span>(slotName, properName, npcName)''
: '''''slotName:''''' <code>String</code> identifier to be used for quest.
** <span style="color:darkblue; font-style:italic;">properName:</span> (string)
: '''''properName:''''' Human-readable name to be displayed in travel log.
** <span style="color:darkblue; font-style:italic;">npcName:</span> (string)
: '''''npcName:''''' The NPC associated with the quest.
** returns: <code>games.stendhal.server.maps.quests.SimpleQuestCreator.SimpleQuest</code> instance.
: ''returns:'' {{StendhalFile|master|src/games/stendhal/server/maps/quests/SimpleQuestCreator.java|SimpleQuest}} instance.


==== SimpleQuest Object ====
==== SimpleQuest Object ====

{{StendhalFile|master|src/games/stendhal/server/maps/quests/SimpleQuestCreator.java|games.stendhal.server.maps.quests.SimpleQuestCreator.SimpleQuest}}

Methods:

; ''<span style="color:green">setDescription</span>(descr)''
:
: '''''descr:''''' (<code>String</code>)

; ''<span style="color:green">setRepeatable</span>(delay)''
:
: '''''delay:''''' (<code>Integer</code>)

; ''<span style="color:green">setItemToCollect</span>(itemName, quantity)''
:
: '''''itemName:''''' (<code>String</code>)
: '''''quantity:''''' (<code>int</code>)

; ''<span style="color:green">setXPReward</span>(xp)''
:
: '''''xp:''''' (<code>int</code>)

; ''<span style="color:green">setKarmaReward</span>(karma)''
:
: '''''karma:''''' (<code>double</code>)

; ''<span style="color:green">setKarmaAcceptReward</span>(karma)''
:
: '''''karma:''''' (<code>double</code>)

; ''<span style="color:green">setKarmaRejectReward</span>(karma)''
:
: '''''karma:''''' (<code>double</code>)

; ''<span style="color:green">addItemReward</span>(itemName, quantity)''
:
: '''''itemName:''''' (<code>String</code>)
: '''''quantity:''''' (<code>int</code>) (optional)

; ''<span style="color:green">addStatReward</span>(id, amount)''
:
: '''''id:''''' (<code>String</code>) See IDs below.
: '''''amount:''''' (<code>int</code>)
:; ''IDs:''
:: '''''xp:'''''
:: '''''def:'''''
:: '''''atk:'''''
:: '''''ratk:'''''

; ''<span style="color:green">setVerboseReward</span>(verbose)''
:
: '''''verbose:''''' (<code>boolean</code>)

; ''<span style="color:green">setReply</span>(id, reply)''
:
: '''''id:''''' (<code>String</code>) See IDs below.
: '''''reply:''''' (<code>String</code>)
:; ''IDs:''
:: '''''request:'''''
:: '''''accept:'''''
:: '''''reject:'''''
:: '''''reward:'''''
:: '''''verbose_reward_prefix:'''''
:: '''''already_active:'''''
:: '''''missing:'''''
:: '''''no_repeat:'''''
:: '''''cooldown_prefix:'''''

; ''<span style="color:green">setRegion</span>(regionName)''
:
: '''''regionName:''''' (<code>String</code>)

Also inherits methods from {{StendhalFile|master|src/games/stendhal/server/maps/quests/AbstractQuest.java|AbstractQuest}}:


Example:
Example:
Line 178: Line 539:


Methods:
Methods:

* ''<span style="color:green;">conditions.create</span>(function)''
* ''<span style="color:green;">conditions.not</span>(condition)''
; ''<span style="color:green;">conditions:create</span>(function)''
: Creates a custom {{StendhalFile|master|src/games/stendhal/server/entity/npc/ChatCondition.java|ChatCondition}}.
* ''<span style="color:green;">conditions.not</span>(value)''
: '''''function:''''' Lua function to be invoked when <code>ChatCondition.fire</code> is called.
* ''<span style="color:green;">conditions.and</span>(conditionList)''
: ''returns:'' New <code>ChatCondition</code> instance.

; ''<span style="color:green;">conditions:notCondition</span>(condition)''
: Creates a {{StendhalFile|master|src/games/stendhal/server/entity/npc/condition/NotCondition.java|NotCondition}}.
: '''''condition:''''' Can be a <code>ChatCondition</code>, <code>LuaValue</code> containing a <code>ChatCondition</code> instance, a Lua table of <code>ChatCondition</code> instances, or a function.
: ''returns:'' New <code>NotCondition</code> instance.

; ''<span style="color:green;">conditions:andCondition</span>(conditionList)''
: Creates an {{StendhalFile|master|src/games/stendhal/server/entity/npc/condition/AndCondition.java|AndCondition}}.
: '''''conditionList:''''' Lua table containing <code>ChatCondition</code> instances.
: ''returns:'' New <code>AndCondition</code> instance.


== actions ==
== actions ==
Line 188: Line 560:


Methods:
Methods:

* ''<span style="color:green;">actions.create</span>(function)''
** <span style="color:darkblue; font-style:italic;">function:</span> A Lua function to be executed when <code>ChatAction.fire</code> is called.
; ''<span style="color:green;">actions:create</span>(function)''
: Creates a custom {{StendhalFile|master|src/games/stendhal/server/entity/npc/ChatAction.java|ChatAction}}.
* ''<span style="color:green;">actions.multiple</span>(actionList)''
: '''''function:''''' A Lua function to be executed when <code>ChatAction.fire</code> is called.
** <span style="color:darkblue; font-style:italic;">actionList:</span> A Lua table containing ChatAction instances.
: ''returns:'' New <code>ChatAction</code> instance.

; ''<span style="color:green;">actions:multiple</span>(actionList)''
: Helper method for creating a {{StendhalFile|master|src/games/stendhal/server/entity/npc/action/MultipleActions.java|MultipleActions}} instance.
: '''''actionList:''''' A Lua table containing ChatAction instances.
: ''returns:'' New <code>MultipleActions</code> instance.


== merchants ==
== merchants ==


Exposes merchant handling classes & functions to Lua.
Exposes merchant handling classes & functions to Lua.

Members:

; ''<span style="color:brown;">merchants.shops</span>''
: This is the {{StendhalFile|master|src/games/stendhal/server/entity/npc/ShopList.java|games.stendhal.server.entity.npc.ShopList}} instance.
: ''public methods: TODO''


Methods:
Methods:

* ''<span style="color:green;">merchants.add</span>(merchantType, npc, prices, addOffer)''
* ''<span style="color:green;">merchants.addSeller</span>(npc, prices, addOffer)''
; ''<span style="color:green;">merchants:add</span>(merchantType, npc, prices, addOffer)''
: Adds merchant behavior to a {{StendhalFile|master|src/games/stendhal/server/entity/npc/SpeakerNPC.java|SpeakerNPC}}.
* ''<span style="color:green;">merchants.addBuyer</span>(npc, prices, addOffer)''
: '''''merchantType:''''' If set to "buyer", will add buyer behavior, otherwise will be "seller".
: '''''npc:''''' The SpeakerNPC to add the behavior to.
: '''''prices:''''' List of items & their prices (can be instance of either Map<String, Integer> or a Lua table).
: '''''addOffer:''''' If <code>true</code>, will add default replies for "offer" (default: <code>true</code>).

; ''<span style="color:green;">merchants:addSeller</span>(npc, prices, addOffer)''
: Adds seller behavior to a {{StendhalFile|master|src/games/stendhal/server/entity/npc/SpeakerNPC.java|SpeakerNPC}}.
: '''''npc:''''' The SpeakerNPC to add the behavior to.
: '''''prices:''''' List of items & their prices (can be instance of either Map<String, Integer> or a Lua table).
: '''''addOffer:''''' If <code>true</code>, will add default replies for "offer" (default: <code>true</code>).

; ''<span style="color:green;">merchants:addBuyer</span>(npc, prices, addOffer)''
: Adds buyer behavior to a {{StendhalFile|master|src/games/stendhal/server/entity/npc/SpeakerNPC.java|SpeakerNPC}}.
: '''''npc:''''' The SpeakerNPC to add the behavior to.
: '''''prices:''''' List of items & their prices (can be instance of either Map<String, Integer> or a Lua table).
: '''''addOffer:''''' If <code>true</code>, will add default replies for "offer" (default: <code>true</code>).


== arrays ==
== arrays ==
Line 207: Line 607:


Methods:
Methods:
* ''<span style="color:green;">arrays.toTable</span>(list)''
; ''<span style="color:green;">arrays:toTable</span>(list)''
** Converts a Java array or list to a Lua table.
: Converts a Java array or list to a Lua table.
: '''''list:''''' Java array or [https://docs.oracle.com/javase/8/docs/api/java/util/List.html list].
** <span style="color:darkblue; font-style:italic;">list:</span> Java array or list.
** returns: New Lua table.
: ''returns:'' New Lua table with contents of <code>list</code> added.


== grammar ==
== grammar ==
Line 221: Line 621:


The {{StendhalFile|master|src/games/stendhal/server/entity/npc/ConversationStates.java|games.stendhal.server.entity.npc.ConversationStates}} enum.
The {{StendhalFile|master|src/games/stendhal/server/entity/npc/ConversationStates.java|games.stendhal.server.entity.npc.ConversationStates}} enum.

Example usage:
<pre>
local npc = entities:createSpeakerNPC("foo")
npc:setCurrentState(ConversationStates.IDLE)
</pre>


== ConversationPhrases ==
== ConversationPhrases ==


The {{StendhalFile|master|src/games/stendhal/server/entity/npc/ConversationPhrases.java|games.stendhal.server.entity.npc.ConversationPhrases}} class.
The {{StendhalFile|master|src/games/stendhal/server/entity/npc/ConversationPhrases.java|games.stendhal.server.entity.npc.ConversationPhrases}} class.

Example usage:
<pre>
local npc = entities:createSpeakerNPC("foo")
npc:add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
nil,
ConversationStates.ATTENDING,
"Hello! How can I help you.",
nil)
</pre>


== CollisionAction ==
== CollisionAction ==


The {{StendhalFile|master|src/games/stendhal/server/entity/CollisionAction.java|games.stendhal.server.entity.CollisionAction}} enum.
The {{StendhalFile|master|src/games/stendhal/server/entity/CollisionAction.java|games.stendhal.server.entity.CollisionAction}} enum.

Example usage:
<pre>
local npc = entities:createSilentNPC()
npc:setCollisionAction(CollisionAction.STOP)
</pre>


== SkinColor ==
== SkinColor ==


The {{StendhalFile|master|src/games/stendhal/common/constants/SkinColor.java|games.stendhal.common.constants.SkinColor}} enum.
The {{StendhalFile|master|src/games/stendhal/common/constants/SkinColor.java|games.stendhal.common.constants.SkinColor}} enum.

Example usage:
<pre>
local npc = entities:createSpeakerNPC("foo")
npc:setOutfit("body=0,head=0,hair=3,dress=5")
npc:setOutfitColor("skin", SkinColor.DARK)
</pre>


== Direction ==
== Direction ==


The {{StendhalFile|master|src/games/stendhal/common/Direction.java|games.stendhal.common.Direction}} enum.
The {{StendhalFile|master|src/games/stendhal/common/Direction.java|games.stendhal.common.Direction}} enum.

Example usage:
<pre>
local npc = entities:createSpeakerNPC("foo")
npc:setDirection(Direction.DOWN)
</pre>


== DaylightPhase ==
== DaylightPhase ==
Line 253: Line 689:


The [https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html java.awt.Color] class.
The [https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html java.awt.Color] class.

Example usage:
<pre>
local npc = entities:createSpeakerNPC("foo")
npc:setOutfit("body=0,head=0,hair=3,dress=5")
npc:setOutfitColor("dress", Color.BLUE)
</pre>


= Supplemental Methods =
= Supplemental Methods =
Line 262: Line 705:
The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.4 string] library.
The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.4 string] library.


* ''<span style="color:green;">string.startsWith</span>(st, prefix)''
; ''<span style="color:green;">string.startsWith</span>(st, prefix)''
** Checks if a string begins with a set of characters.
: Checks if a string begins with a set of characters.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be checked.
: '''''st:''''' The string to be checked.
** <span style="color:darkgreen; text-style=italic;">prefix:</span> The prefix to be compared with.
: '''''prefix:''''' The prefix to be compared with.
** returns: <code>true</code> if <code>prefix</code> matches the beginning characters of <code>st</code>.
: ''returns:'' <code>true</code> if <code>prefix</code> matches the beginning characters of <code>st</code>.
:; ''aliases:''
* ''<span style="color:green;">string.beginsWith</span>(st, prefix)''
:: <span style="color:green; font-style:italic;">string.beginsWith</span>
** This is just an alias for <code>string.startsWith</code>.
* ''<span style="color:green;">string.endsWith</span>(st, suffix)''
** Checks if a string ends with a set of characters.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be checked.
** <span style="color:darkgreen; text-style=italic;">suffix:</span> The suffix to be compared with.
** returns: <code>true</code> if <code>suffix</code> matches then end characters of <code>st</code>.
* ''<span style="color:green;">string.trim</span>(st)''
** Removes leading & trailing whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.
* ''<span style="color:green;">string.ltrim</span>(st)''
** Removes leading whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.
* ''<span style="color:green;">string.rtrim</span>(st)''
** Removes trailing whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.


; ''<span style="color:green;">string.endsWith</span>(st, suffix)''
: Checks if a string ends with a set of characters.
: '''''st:''''' The string to be checked.
: '''''suffix:''''' The suffix to be compared with.
: ''returns:'' <code>true</code> if <code>suffix</code> matches then end characters of <code>st</code>.

; ''<span style="color:green;">string.isNumber</span>(st)''
: Checks if a string contains numeric characters only.
: '''''st:''''' The string to be checked.
: ''returns:'' <code>true</code> if all characters are numeric, <code>false</code> otherwise.
:; ''aliases:''
:: <span style="color:green; font-style:italic;">string.isNumeric</span>

; ''<span style="color:green;">string.trim</span>(st)''
: Removes leading & trailing whitespace from a string.
: '''''st:''''' The string to be trimmed.
: ''returns:'' Trimmed string.

; ''<span style="color:green;">string.ltrim</span>(st)''
: Removes leading whitespace from a string.
: '''''st:''''' The string to be trimmed.
: ''returns:'' Trimmed string.

; ''<span style="color:green;">string.rtrim</span>(st)''
: Removes trailing whitespace from a string.
: '''''st:''''' The string to be trimmed.
: ''returns:'' Trimmed string.

; ''<span style="color:green;">string.builder</span>(st)''
: Creates a new instance of [https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html java.lang.StringBuilder].
: '''''st:''''' (optional) String to append on instantiation.
: ''returns:'' new StringBuilder instance.


== Table Manipulation ==
== Table Manipulation ==
Line 292: Line 750:
The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.6 table] library.
The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.6 table] library.


* ''<span style="color:green;">table.clean</span>(tbl)''
; ''<span style="color:green;">table.concat</span>(tbl1, tbl2)''
: Merges the contents of one table into another.
** Removes <code>nil</code> values from a table.
: '''''tbl1:''''' The table receiving the new content.
** <span style="color:darkgreen; text-style=italic;">tbl:</span> The table to be cleaned.
: '''''tbl2:''''' The table containing the content to be copied.
** returns: Copy of <code>tbl</code> with <code>nil</code> values removed.

* ''<span style="color:green;">table.concat</span>(tbl1, tbl2)''
{{PublicMethod | table.contains | params=table, o | desc=Checks if a table contains a value. | paramlist=
** Merges the contents of one table into another.
{{MethodParam | table | type=table | desc=Table to be checked.}}
** <span style="color:darkgreen; text-style=italic;">tbl1:</span> The table receiving the new content.
{{MethodParam | o | desc=The object to check for.}}
** <span style="color:darkgreen; text-style=italic;">tbl2:</span> The table containing the content to be copied.
| ret=<code>true</code> if <code>o</code> is in <code>table</code>. | rettype=boolean }}

; ''<span style="color:green;">table.clean</span>(tbl)''
: Removes <code>nil</code> values from a table.
: '''''tbl:''''' The table to be cleaned.
: ''returns:'' Copy of <code>tbl</code> with <code>nil</code> values removed.

{{PublicMethod | table.join | params=table, delim | desc=Joins a table of strings into a string. | paramlist=
{{MethodParam | table | type=table | desc=Table to be joined.}}
{{MethodParam | delim | type=string | desc=Character(s) to be used as separator.}}
| ret=The resulting string. | rettype=string }}


= See Also =
= See Also =
Line 305: Line 774:
* [[StendhalScripting/Lua#Lua_Basics|Lua: Basics]]
* [[StendhalScripting/Lua#Lua_Basics|Lua: Basics]]
* [[StendhalScripting/Lua#Stendhal_Application|Lua: Stendhal Application]]
* [[StendhalScripting/Lua#Stendhal_Application|Lua: Stendhal Application]]


[[Category:Stendhal]]
[[Category:Documentation]]
[[Category:API]]
[[Category:Scripting]]
[[Category:Lua]]

Latest revision as of 21:54, 18 January 2022


The following objects & functions are exposed to the Lua engine:

Objects

luajava

This is an object of the LuajavaLib library. It can be used to coerce Java static objects to Lua or create new Java object instances.

Example of exposing a static object & enums to Lua:

-- store a Java enum in a Lua global variable
ConversationStates = luajava.bindClass("games.stendhal.server.entity.npc.ConversationStates")

-- access the enum values like so
ConversationStates.IDLE

Example of creating an object instance:

-- store instance in local variable
local dog = luajava.newInstance("games.stendhal.server.entity.npc.SilentNPC")
-- access object methods like so
dog:setEntityClass("animal/puppy")
dog:setPosition(2, 5)

-- class with constructor using parameters
local speaker = luajava.newInstance("games.stendhal.server.entity.npc.SpeakerNPC", "Frank")
speaker:setOutfit("body=0,head=0,eyes=0,hair=5,dress=5")
speaker:setPosition(2, 6)

To make scripting easier, Stendhal employs a master script & some helper objects & methods to handle the functionality mentioned above. An explanation of these objects & methods follows.

logger

Manages logging in Lua via the org.apache.log4j.Logger class.

Methods:

logger:info(message)
Prints an information level message to the console.
message: Text to be printed.
logger:warn(message)
Prints a warning level message to the console.
message: Text to be printed.
logger:error(message)
Prints an error level message to the console.
message: Text to be printed.

Example usage:

local zone = "0_semos_city"
if game:setZone(zone) then
	-- do something
else
	logger:error("Could not set zone: " .. zone)
end

properties

Defines functions for accessing Java system properties.

Methods:

properties:getValue(p)
Retrieves the value of a property.
p: (string) Property name.
returns: (string) Property value or `nil`.
properties:enabled(p)
Checks if a property is enabed.
p: (string) Property name.
returns: (boolean) `true` if enabled.
properties:equals(p, v)
Checks if a property is set to a specified value.
p: (string) Property name.
v: (string) Value to compare with.
returns: (boolean) `true` if the value of the property is the same as `v`.

Examples usage:

-- example of only executing script contents on test server

if not properties:enabed("stendhal.testserver") then
    do return end
end

game

The main object that handles setting zone & adding entities to game.

Methods:

game:add(object)
Adds an RPObject instance to the current zone.
object: Object to add.
game:add(npc)
Adds an NPC instance to the current zone.
npc: NPC to add.
game:add(creature, x, y)
Adds a Creature instance to the current zone.
creature: Creature to add.
x: Horizontal position of where to add creature.
y: Vertical position of where to add creature.
game:remove(object)
object:
game:remove(npc)
npc:
game:addGameEvent(source, event, params)
Adds a new GameEvent.
source:
event:
params:
game:setZone(name)
Sets the current zone.
name: String identifier for zone to be set as current zone.
returns: true if zone was successfully set.
game:setZone(zone)
Sets the current zone.
zone: StendhalRPZone instance to set as current zone.
returns: true if zone was successfully set.
game:getZone(object)
Retrieves the zone where object is located.
object: The RPObject from which the zone should be retrieved.
returns: StendhalRPZone or null if it doesn't exists
game:getZone(name)
Retrieves a zone by string ID.
zoneName: Name of zone to retrieve.
returns: StendhalRPZone or null if it doesn't exist.
game:setMusic(filename, args)
Sets the music for the currently selected zone.
filename:
File basename excluding .ogg extension.
args:
Lua table of key=value integer values.
Valid keys:
volume: Volume level (default: 100).
x: The X coordinate of the sound source (default: 1).
y: The Y coordinate of the sound source (default: 1).
radius: The radius from which the music can be heard (default: 10000).
game:playerIsInZone(player, zoneName)
player:
zoneName:
returns: boolean
game:getCreatures()
returns: An array of all available creatures.
game:getCreature(clazz)
Retrieves a Creature instance.
clazz: String name of the creature.
returns: Creature or null if doesn't exist.
game:getItems()
returns: Array list of available items.
game:getItem(name)
name:
returns: Item instance or null if doesn't exist.
game:modify(entity)
entity:
game:privateText(player, text)
Sends a private text to a player.
player: Player to receive the message.
text: Message text to send to player.
game:getMessage()
returns: String

entities

See also: StendhalAPI#Entities for public methods that can be performed on Entity objects.

Methods:

entities:getPlayer(name)
Retrieves a logged in Player.
name: (String) Name of player.
returns: Logged in Player or null.
entities:getNPC(name)
Retrieves an existing SpeakerNPC.
name: (String) Name of NPC.
returns: SpeakerNPC instance or null.
entities:getItem(name)
Retrieves a registered Item.
name: (String) Name of the item.
returns: Item instance or null if not a registered item.
entities:getStackableItem(name)
Retrieves a registered StackableItem.
name: (String) Name of the item.
returns: StackableItem instance or null if not a registered stackable item.
entities:createSpeakerNPC(name)
Creates an interactive NPC.
name: (String) Name of new NPC.
returns: New SpeakerNPC instance.
entities:createSilentNPC()
Creates a non-interactive NPC.
returns: New SilentNPC instance.
entities:setPath(entity, table, loop)
DEPRECATED: path can now be set by directly calling the NPC's setPath method
Helper method for setting an NPC's path.
entity: (RPEntity) Then entity whose path is being set.
table: (LuaTable) Table with list of coordinates representing nodes.
loop: (boolean) If true, the entity's path should loop.
entities:setPathAndPosition(entity, table, loop) <nowiki>
DEPRECATED: path can now be set by directly calling the NPC's setPath method
Helper function for setting an NPC's path & starting position.
entity: (RPEntity) Then entity whose path is being set.
table: (LuaTable) Table with list of coordinates representing nodes.
loop: (boolean) If true, the entity's path should loop.
entities:createSign(visible)
Creates a new Sign entity.
visible: (boolean) (optional) If false, the sign will not have a visual representation.
returns: New Sign instance.
entities:createShopSign(name, title, caption, seller)
Creates a new ShopSign entity.
name: (String) The shop name.
title: (String) The sign title.
caption: (String) The caption above the table.
seller: (boolean) true, if this sign is for items sold by an NPC (defaults to true if null).
returns: New ShopSign instance.
entities:summonCreature(table)
Summons a creature into the area.
table: Key-value table containing parameters for summoning creature.
keys:
name: (string) Name of creature to be summoned.
zone: (string) Name of zone where creature should be summoned.
x: (int) Horizontal position of summon location.
y: (int) Vertical position of summon location.
summoner: (string) (optional) Name of entity doing the summoning (used for logging game events).
raid: (bool) (optional) Whether or not the creature should be a RaidCreature instance (default: true).

Lua Entity Classes

LuaSpeakerNPC

Public methods:

add (states, triggers, conditions, nextState, reply, actions)
Additional method to support passing Lua data types as parameters.
states : The conversation state(s) the entity should be in to trigger response. Can be ConversationStates enum value or LuaTable of ConversationStates.
triggers : String or LuaTable of strings to trigger response.
conditions : Conditions to check for this response. Can be ChatCondition instance, a LuaTable of ChatCondition instances, or a function.
nextState : (ConversationState) Conversation state to set entity to after response.
reply : (String) The NPC's response or null.
actions : Actions to execute. Can be ChatAction instance, a LuaTable of ChatAction instances, or a function.
setPath (table, loop)
Set a path for this entity to follow.
table : (table) Table of coordinates to set as path. Example: {{35, 79}, {35, 89}, {40, 89}}
loop : (boolean) (optional) If true, entity should loop around to restart path when reaching the end.
setPathAndPosition (table, loop)
Set path & starting position for entity. The starting position is the first node in the path.
table : (table) Table of coordinates to set as path. Example: {{35, 79}, {35, 89}, {40, 89}}
loop : (boolean) (optional) If true, entity should loop around to restart path when reaching the end.

LuaSilentNPC

Public methods:

setPath (table, loop)
Set a path for this entity to follow.
table : (table) Table of coordinates to set as path. Example: {{35, 79}, {35, 89}, {40, 89}}
loop : (boolean) (optional) If true, entity should loop around to restart path when reaching the end.
setPathAndPosition (table, loop)
Set path & starting position for entity. The starting position is the first node in the path.
table : (table) Table of coordinates to set as path. Example: {{35, 79}, {35, 89}, {40, 89}}
loop : (boolean) (optional) If true, entity should loop around to restart path when reaching the end.

entities.manager

This is simply the entity manager instance.

Public methods:

TODO

quests

Adds helper functions for creating & manipulating quests & exposes select public methods of the games.stendhal.server.core.rp.StendhalQuestSystem class.

Methods:

quests:create(slotName, name)
Creates a new quest.
slotName: (optional) The string identifier for the quest.
name: (optional) The human-readable name that can be shown in travel log.
returns: New games.stendhal.server.core.scripting.lua.QuestHelper.LuaQuest instance.
quests:load(quest)
Adds a quest to the world.
quest: The IQuest instance to be loaded.
quests:unload(questName)
Removes a quest from the world.
questName: String name of the quest to be removed.
quests:cache(quest)
Caches a quest for loading at server startup.
quest: IQuest instance to be loaded.
aliases:
quests:register
quests:isLoaded(quest)
Checks if a quest has been loaded.
quest: IQuest instance to check.
returns: true if the instance matches stored quests.
quests:listAll(player)
List all quests the player knows about.
player: Player to create the report for.
returns: String report.
quests:list(player, questName)
Creates a report on a specified quest for a player.
player: Player to create the report for.
questName: Name of quest to be reported.
returns: String report.
quests:listStates(player)
Dumps the internal quest states for the specified player. This is used for the InspectAction.
player: Player to create the report for.
returns: String report.
quests:getQuest(questName)
Retrieves the IQuest object for a named quest.
questName: Name of quest.
returns: IQuest or null if doesn't exist.
quests:getQuestFromSlot(questSlot)
Retrieves the IQuest object for a quest.
questSlot: Quest identifier string.
returns: IQuest or null if doesn't exist.
quests:getOpen(player)
Retrieves a list of open quests from a player.
player: Player instance to be checked.
returns: List of string identifiers for open quests.
quests:getCompleted(player)
Retrieves a list of completed quests from a player.
player: Player instance to be checked.
returns: List of string identifiers for completed quests.
quests:getIncomplete(player, region)
Retrieves a list of incomplete quests in a specified region.
player: Player instance to be checked.
region: Region name/identifier.
returns: List of string identifiers of incomplete quests in region.
quests:getRepeatable(player)
Retrieves a list of quests a player has completed, and can now do again.
player: Player instance to be checked.
returns:
quests:getDescription(player, questName)
Retrieves the description of a quest.
player: Player instance to be checked.
questName: Name of the quest.
returns: String description.
quests:getLevelWarning(player, questName)
If the quest is too dangerous, add a warning unless the player has already completed it.
player: Player instance to be checked.
questName: Name of the quest.
returns: String
quests:getProgressDetails(player, questeName)
Retrieves details on the progress of the quest.
player: Player instance to be checked.
questName: Name of the quest.
returns: List<String>
quests:getNPCNamesForUnstartedInRegionForLevel(player, region)
Retrieves a list of the unique npc names for unstarted quests in a specified region.
player: Player instance to be checked.
region: Region to check in.
returns: List<String>
quests:getDescriptionForUnstartedInRegionFromNPCName(player, region, name)
Retrieves quest descriptions for unstarted quests in a specified region matching a specific NPC name.
player: Player instance to be checked.
region: Region to check in.
name: Name of NPC.
returns: List<String>

quests.simple

A special class for creating a simple collect single item quest.

Methods:

quests.simple:create(slotName, properName, npcName)
slotName: String identifier to be used for quest.
properName: Human-readable name to be displayed in travel log.
npcName: The NPC associated with the quest.
returns: SimpleQuest instance.

SimpleQuest Object

games.stendhal.server.maps.quests.SimpleQuestCreator.SimpleQuest

Methods:

setDescription(descr)
descr: (String)
setRepeatable(delay)
delay: (Integer)
setItemToCollect(itemName, quantity)
itemName: (String)
quantity: (int)
setXPReward(xp)
xp: (int)
setKarmaReward(karma)
karma: (double)
setKarmaAcceptReward(karma)
karma: (double)
setKarmaRejectReward(karma)
karma: (double)
addItemReward(itemName, quantity)
itemName: (String)
quantity: (int) (optional)
addStatReward(id, amount)
id: (String) See IDs below.
amount: (int)
IDs:
xp:
def:
atk:
ratk:
setVerboseReward(verbose)
verbose: (boolean)
setReply(id, reply)
id: (String) See IDs below.
reply: (String)
IDs:
request:
accept:
reject:
reward:
verbose_reward_prefix:
already_active:
missing:
no_repeat:
cooldown_prefix:
setRegion(regionName)
regionName: (String)

Also inherits methods from AbstractQuest:

Example:

-- create SimpleQuest instance
local quest = simpleQuest:create("wood_for_lua", "Wood for Lua", "Lua")

quest:setDescription("Lua needs help gathering wood.")
quest:setRequestReply("I need help gathering some wood. Will you help me?")
quest:setAcceptReply("Great!")
quest:setRewardReply("Thank a bunch!")
quest:setRejectReply("Fine! I don't need your help anyway.")
quest:setItemToCollect("wood", 5)
quest:setRepeatable(true)
quest:setRepeatDelay(10)
quest:setXPReward(50)
quest:setKarmaReward(5.0)
quest:addItemReward("rose", 3)
quest:addItemReward("money", 100)
quest:setRegion(Region.SEMOS_CITY)

quests:register(quest)

conditions

Object for creating games.stendhal.server.entity.npc.ChatCondition instances.

Methods:

conditions:create(function)
Creates a custom ChatCondition.
function: Lua function to be invoked when ChatCondition.fire is called.
returns: New ChatCondition instance.
conditions:notCondition(condition)
Creates a NotCondition.
condition: Can be a ChatCondition, LuaValue containing a ChatCondition instance, a Lua table of ChatCondition instances, or a function.
returns: New NotCondition instance.
conditions:andCondition(conditionList)
Creates an AndCondition.
conditionList: Lua table containing ChatCondition instances.
returns: New AndCondition instance.

actions

Object for creating games.stendhal.server.entity.npc.ChatAction instances.

Methods:

actions:create(function)
Creates a custom ChatAction.
function: A Lua function to be executed when ChatAction.fire is called.
returns: New ChatAction instance.
actions:multiple(actionList)
Helper method for creating a MultipleActions instance.
actionList: A Lua table containing ChatAction instances.
returns: New MultipleActions instance.

merchants

Exposes merchant handling classes & functions to Lua.

Members:

merchants.shops
This is the games.stendhal.server.entity.npc.ShopList instance.
public methods: TODO

Methods:

merchants:add(merchantType, npc, prices, addOffer)
Adds merchant behavior to a SpeakerNPC.
merchantType: If set to "buyer", will add buyer behavior, otherwise will be "seller".
npc: The SpeakerNPC to add the behavior to.
prices: List of items & their prices (can be instance of either Map<String, Integer> or a Lua table).
addOffer: If true, will add default replies for "offer" (default: true).
merchants:addSeller(npc, prices, addOffer)
Adds seller behavior to a SpeakerNPC.
npc: The SpeakerNPC to add the behavior to.
prices: List of items & their prices (can be instance of either Map<String, Integer> or a Lua table).
addOffer: If true, will add default replies for "offer" (default: true).
merchants:addBuyer(npc, prices, addOffer)
Adds buyer behavior to a SpeakerNPC.
npc: The SpeakerNPC to add the behavior to.
prices: List of items & their prices (can be instance of either Map<String, Integer> or a Lua table).
addOffer: If true, will add default replies for "offer" (default: true).

arrays

Handles some conversion of Java arrays & lists to Lua tables.

Methods:

arrays:toTable(list)
Converts a Java array or list to a Lua table.
list: Java array or list.
returns: New Lua table with contents of list added.

grammar

Exposes the games.stendhal.common.grammar.Grammar parser instance to Lua.

Static Classes & Enumerations

ConversationStates

The games.stendhal.server.entity.npc.ConversationStates enum.

Example usage:

local npc = entities:createSpeakerNPC("foo")
npc:setCurrentState(ConversationStates.IDLE)

ConversationPhrases

The games.stendhal.server.entity.npc.ConversationPhrases class.

Example usage:

local npc = entities:createSpeakerNPC("foo")
npc:add(ConversationStates.IDLE,
	ConversationPhrases.GREETING_MESSAGES,
	nil,
	ConversationStates.ATTENDING,
	"Hello! How can I help you.",
	nil)

CollisionAction

The games.stendhal.server.entity.CollisionAction enum.

Example usage:

local npc = entities:createSilentNPC()
npc:setCollisionAction(CollisionAction.STOP)

SkinColor

The games.stendhal.common.constants.SkinColor enum.

Example usage:

local npc = entities:createSpeakerNPC("foo")
npc:setOutfit("body=0,head=0,hair=3,dress=5")
npc:setOutfitColor("skin", SkinColor.DARK)

Direction

The games.stendhal.common.Direction enum.

Example usage:

local npc = entities:createSpeakerNPC("foo")
npc:setDirection(Direction.DOWN)

DaylightPhase

The games.stendhal.server.core.rp.DaylightPhase enum.

Region

The games.stendhal.server.maps.Region class.

MathHelper

The games.stendhal.common.MathHelper class.

Color

The java.awt.Color class.

Example usage:

local npc = entities:createSpeakerNPC("foo")
npc:setOutfit("body=0,head=0,hair=3,dress=5")
npc:setOutfitColor("dress", Color.BLUE)

Supplemental Methods

A few convenience methods are added to make scripting easier.

String Manipulation

The following methods have been added to the built-in Lua string library.

string.startsWith(st, prefix)
Checks if a string begins with a set of characters.
st: The string to be checked.
prefix: The prefix to be compared with.
returns: true if prefix matches the beginning characters of st.
aliases:
string.beginsWith
string.endsWith(st, suffix)
Checks if a string ends with a set of characters.
st: The string to be checked.
suffix: The suffix to be compared with.
returns: true if suffix matches then end characters of st.
string.isNumber(st)
Checks if a string contains numeric characters only.
st: The string to be checked.
returns: true if all characters are numeric, false otherwise.
aliases:
string.isNumeric
string.trim(st)
Removes leading & trailing whitespace from a string.
st: The string to be trimmed.
returns: Trimmed string.
string.ltrim(st)
Removes leading whitespace from a string.
st: The string to be trimmed.
returns: Trimmed string.
string.rtrim(st)
Removes trailing whitespace from a string.
st: The string to be trimmed.
returns: Trimmed string.
string.builder(st)
Creates a new instance of java.lang.StringBuilder.
st: (optional) String to append on instantiation.
returns: new StringBuilder instance.

Table Manipulation

The following methods have been added to the built-in Lua table library.

table.concat(tbl1, tbl2)
Merges the contents of one table into another.
tbl1: The table receiving the new content.
tbl2: The table containing the content to be copied.
table.contains (table, o)
Checks if a table contains a value.
table : (table) Table to be checked.
o : The object to check for.
returns: (boolean) true if o is in table.
table.clean(tbl)
Removes nil values from a table.
tbl: The table to be cleaned.
returns: Copy of tbl with nil values removed.
table.join (table, delim)
Joins a table of strings into a string.
table : (table) Table to be joined.
delim : (string) Character(s) to be used as separator.
returns: (string) The resulting string.

See Also