Lua写一个npc对话
时间: 2024-05-14 15:17:22 浏览: 97
好的,以下是一个简单的Lua NPC对话示例:
```
-- 定义一个NPC对话函数
function npc_talk()
print("你好,我是NPC。欢迎来到我的小店。")
print("请问你需要什么?")
local answer = io.read() -- 等待玩家输入
if answer == "购买" then
print("好的,这是我们店里的商品列表:")
print("1. 铁剑 - 50金币")
print("2. 铁盾 - 30金币")
print("3. 短弓 - 70金币")
print("请问你想要购买哪个?")
local choice = io.read()
if choice == "1" then
print("感谢您的购买!请拿好您的铁剑。")
elseif choice == "2" then
print("感谢您的购买!请拿好您的铁盾。")
elseif choice == "3" then
print("感谢您的购买!请拿好您的短弓。")
else
print("抱歉,我们没有这个商品。")
end
elseif answer == "问候" then
print("您好,有什么需要帮助的吗?")
elseif answer == "退出" then
print("欢迎下次再来!")
else
print("抱歉,我不明白您的意思。")
end
end
-- 调用NPC对话函数
npc_talk()
```
这个例子中,NPC会向玩家展示商品列表并询问玩家想要购买什么。玩家可以选择要购买的商品,或者选择问候或退出。如果玩家输入的内容NPC无法理解,NPC会告诉玩家不明白他的意思。
阅读全文
相关推荐


















