编辑“︁
StendhalScripting/Lua
”︁(章节)
跳转到导航
跳转到搜索
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
== Adding Entities == === Signs === Signs can be created with <code>entities:createSign</code> and <code>entities:createShopSign</code>: <pre> local zone = "0_semos_city" if game:setZone(zone) then -- create the sign instance local sign = entities:createSign() sign:setEntityClass("signpost") sign:setPosition(12, 55) sign:setText("Meet Lua!") -- Add it to the world game:add(sign) else logger:error("Could not set zone: " .. zone) end </pre> === NPCs === Use the <code>entities:createSpeakerNPC</code> method to create an interactive NPC: <pre> local zone = "0_semos_city" if game:setZone(zone) then -- Use helper object to create a new NPC local npc = entities:createSpeakerNPC("Lua") npc:setEntityClass("littlegirlnpc") npc:setPosition(10, 55) npc:setBaseSpeed(0.1) npc:setCollisionAction(CollisionAction.STOP) local nodes = { {10, 55}, {11, 55}, {11, 56}, {10, 56}, } npc:setPath(nodes) -- Dialogue npc:addJob("Actually, I am jobless.") npc:addGoodbye(); -- Add to the world game:add(npc) else logger:error("Could not set zone: " .. zone) end </pre> ==== Adding Transitions ==== A simple example of adding a chat transition can be done without any special functionality: <pre> local frank = entities:createSpeakerNPC("Frank") frank:add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES, nil, ConversationStates.ATTENDING, "Hello.", nil) </pre> 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>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> frank:add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES, conditions:create("PlayerHasItemWithHimCondition", {"money"}), ConversationStates.ATTENDING, "Hello.", nil) </pre> 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>actions:notCondition</code> method: Example usage: <pre> local condition = conditions.notCondition(conditions:create("PlayerHasItemWithHimCondition", {"money"}) </pre> To add a ChatAction, we use the <code>actions:create</code> method. Its usage is identical to <code>conditions:create</code>. Example: <pre> frank:add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES, conditions:create("PlayerHasItemWithHimCondition", {"money"}), ConversationStates.ATTENDING, "Hello.", actions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false})) </pre> Lua tables can be used to add multiple conditions or actions: <pre> frank:add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES, { conditions:create("PlayerHasItemWithHimCondition", {"money"}), conditions:notCondition(conditions:create("NakedCondition")), }, ConversationStates.ATTENDING, nil, { actions:create("SayTextAction", {"Hello."}), actions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}), }) </pre> In this scenario, the NPC will respond if the player has money & is not naked. Nested tables are supported as well: <pre> local conditions = { conditions:create("PlayerHasItemWithHimCondition", {"money"}), { conditions:notCondition(conditions:create("NakedCondition")), }, } frank:add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES, conditions, ConversationStates.ATTENDING, nil, { actions:create("SayTextAction", {"Hello."}), actions:create("NPCEmoteAction", {"looks greedily at your pouch of money.", false}), }) </pre> ==== Adding Merchant Behavior ==== The <code>merchants</code> object is used for adding merchant behavior (buying/selling) to an NPC. Example of adding seller behavior to an NPC: <pre> if game:setZone("0_semos_city") then local frank = entities.createSpeakerNPC("Frank") merchants:addSeller(frank, merchants.shops:get("shopname"), true) game:add(frank) end </pre> To create a custom shop list, you can use a Lua table (there are multiple ways to add elements to a Lua table): Method 1: <pre> local priceList = { meat = 50, ["ham"] = 70, } </pre> Method 2: <pre> local priceList = {} priceList.meat = 50 priceList["ham"] = 70 </pre> The helper methods have special handling for underscore characters as well (the following are all the same): <pre> local priceList = { smoked_ham = 100, ["smoked ham"] = 100, } priceList.smoked_ham = 100 priceList["smoked ham"] = 100 </pre> Then add the seller behavior using the custom list: <pre> merchants:addSeller(frank, priceList, true) </pre>
摘要:
请注意,所有对gamedev的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Gamedev:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
页面
讨论
不转换
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
臺灣正體
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息