StendhalScripting/Lua: Difference between revisions

Content deleted Content added
imported>AntumDeluge
Add Zone Music: "setZoneMusic" replaced with "game:setMusic"
imported>AntumDeluge
Adding Transitions: "newAction", "newCondition", & "newNotCondition" replaced by member methods of "actions" & "conditions" objects
Line 366:
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>newConditionconditions:create</code> globalmethod. function: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>
frank:add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
newConditionconditions:create("PlayerHasItemWithHimCondition", {"money"}),
ConversationStates.ATTENDING,
"Hello.",
Line 378 ⟶ 380:
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.notactions:notCondition</code> method:
 
Example usage:
<pre>
local condition = conditions.notnotCondition(newConditionconditions:create("PlayerHasItemWithHimCondition", {"money"})
-- using newNotCondition
local condition = newNotCondition("PlayerHasItemWithHimCondition", "money")
 
-- using conditions.not
local condition = conditions.not(newCondition("PlayerHasItemWithHimCondition", "money")
</pre>
 
To add a ChatAction, we use the <code>newActionactions:create</code> globalmethod. functionIts usage is identical to <code>conditions:create</code>.
 
Example:
<pre>
frank:add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
newConditionconditions:create("PlayerHasItemWithHimCondition", {"money"}),
ConversationStates.ATTENDING,
"Hello.",
newActionactions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}))
</pre>
 
Line 404:
ConversationPhrases.GREETING_MESSAGES,
{
newConditionconditions:create("PlayerHasItemWithHimCondition", {"money"}),
newNotConditionconditions:notCondition(newConditionconditions:create("NakedCondition")),
},
ConversationStates.ATTENDING,
nil,
{
newActionactions:create("SayTextAction", {"Hello."}),
newActionactions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}),
})
</pre>
Line 420:
<pre>
local conditions = {
newConditionconditions:create("PlayerHasItemWithHimCondition", {"money"}),
{
newNotConditionconditions:notCondition(newConditionconditions:create("NakedCondition")),
},
}
Line 432:
nil,
{
newActionactions:create("SayTextAction", {"Hello."}),
newActionactions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}),
})
 
</pre>