StendhalScripting/Lua: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>AntumDeluge
Add Zone Music: "setZoneMusic" replaced with "game:setMusic"
imported>AntumDeluge
add categories
 
(3 intermediate revisions by the same user not shown)
Line 337: Line 337:
}
}


npc:setPath(nodes)
-- Use helper object to create NPC path
entities:setPath(npc, nodes)


-- Dialogue
-- Dialogue
Line 366: Line 365:
This simply adds a response to saying "hello" & sets the NPC to attend to the player (equivalent of <code>frank:addGreeting("Hello")</code>).
This simply adds a response to saying "hello" & sets the NPC to attend to the player (equivalent of <code>frank:addGreeting("Hello")</code>).


For more complicated behavior, we need to use some helper methods. If we want to check a condition we use the <code>newCondition</code> global function:
For more complicated behavior, we need to use some helper methods. If we want to check a condition we use the <code>conditions:create</code> method. The first parameter is the string name of the ChatCondition we want to instantiate. The second parameter is a table that contains the values that should be passed to the ChatCondition constructor.

Example:
<pre>
<pre>
frank:add(ConversationStates.IDLE,
frank:add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
ConversationPhrases.GREETING_MESSAGES,
newCondition("PlayerHasItemWithHimCondition", "money"),
conditions:create("PlayerHasItemWithHimCondition", {"money"}),
ConversationStates.ATTENDING,
ConversationStates.ATTENDING,
"Hello.",
"Hello.",
Line 378: Line 379:
In this scenario, the NPC will only respond if the player is carrying <item>money</item>.
In this scenario, the NPC will only respond if the player is carrying <item>money</item>.


A NotCondition instance can be created with the <code>newNotCondition</code> global function or using the <code>conditions.not</code> method:
A NotCondition instance can be created with the <code>actions:notCondition</code> method:


Example usage:
Example usage:
<pre>
<pre>
local condition = conditions.notCondition(conditions:create("PlayerHasItemWithHimCondition", {"money"})
-- using newNotCondition
local condition = newNotCondition("PlayerHasItemWithHimCondition", "money")

-- using conditions.not
local condition = conditions.not(newCondition("PlayerHasItemWithHimCondition", "money")
</pre>
</pre>


To add a ChatAction, we use the <code>newAction</code> global function:
To add a ChatAction, we use the <code>actions:create</code> method. Its usage is identical to <code>conditions:create</code>.

Example:
<pre>
<pre>
frank:add(ConversationStates.IDLE,
frank:add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
ConversationPhrases.GREETING_MESSAGES,
newCondition("PlayerHasItemWithHimCondition", "money"),
conditions:create("PlayerHasItemWithHimCondition", {"money"}),
ConversationStates.ATTENDING,
ConversationStates.ATTENDING,
"Hello.",
"Hello.",
newAction("NPCEmoteAction", "looks greedily at your pouch of money.", false))
actions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}))
</pre>
</pre>


Line 404: Line 403:
ConversationPhrases.GREETING_MESSAGES,
ConversationPhrases.GREETING_MESSAGES,
{
{
newCondition("PlayerHasItemWithHimCondition", "money"),
conditions:create("PlayerHasItemWithHimCondition", {"money"}),
newNotCondition(newCondition("NakedCondition")),
conditions:notCondition(conditions:create("NakedCondition")),
},
},
ConversationStates.ATTENDING,
ConversationStates.ATTENDING,
nil,
nil,
{
{
newAction("SayTextAction", "Hello."),
actions:create("SayTextAction", {"Hello."}),
newAction("NPCEmoteAction", "looks greedily at your pouch of money.", false),
actions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}),
})
})
</pre>
</pre>
Line 420: Line 419:
<pre>
<pre>
local conditions = {
local conditions = {
newCondition("PlayerHasItemWithHimCondition", "money"),
conditions:create("PlayerHasItemWithHimCondition", {"money"}),
{
{
newNotCondition(newCondition("NakedCondition")),
conditions:notCondition(conditions:create("NakedCondition")),
},
},
}
}
Line 432: Line 431:
nil,
nil,
{
{
newAction("SayTextAction", "Hello."),
actions:create("SayTextAction", {"Hello."}),
newAction("NPCEmoteAction", "looks greedily at your pouch of money.", false),
actions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}),
})
})

</pre>
</pre>


Line 534: Line 532:


* [[StendhalScripting/LuaAPI|Lua API]]
* [[StendhalScripting/LuaAPI|Lua API]]


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