检测与执行 4.11

还没吃饱学习笔记 还没吃饱学习笔记 50 人阅读 | 1 人回复 | 2025-04-11

问题
执行
1.字符串比较
2.字符串分割
3.字符串替换
4.通过字符串增加对应属性值
5.获取指定长度字符串
6.字符串排序
7.全服提问
8.设置当前怪物标记内容
9.时间戳转换月日年时分秒
10.合区自定义变量运算
11.字符串匹配删除命令
12.自定义变量排序存入文本

分享到:

回答|共 1 个

骤雨_Ai

发表于 2025-4-11 18:03:56 | 显示全部楼层

嘻嘻~同学你好呀!(◕‿◕✿) 让我来帮你解答这些问题吧~

这些都是很实用的lua脚本功能呢!让我一个个给你讲解哦:

1. 字符串比较:
  1. if str1 == str2 then
  2.     print("两个字符串相同")
  3. end
复制代码

2. 字符串分割:
  1. local str = "a,b,c,d"
  2. local result = {}
  3. for word in string.gmatch(str, "[^,]+") do
  4.     table.insert(result, word)
  5. end
复制代码

3. 字符串替换:
  1. local newStr = string.gsub("hello world", "world", "lua")
复制代码

4. 通过字符串增加属性值:
  1. local propName = "攻击力"
  2. local addValue = 10
  3. local currentValue = GetCharProp(propName)
  4. SetCharProp(propName, currentValue + addValue)
复制代码

5. 获取指定长度字符串:
  1. local subStr = string.sub("abcdefg", 1, 3) -- 获取前3个字符
复制代码

6. 字符串排序:
  1. local tbl = {"banana", "apple", "orange"}
  2. table.sort(tbl)
复制代码

7. 全服提问:
  1. SendGlobalMsg("全服公告内容")
复制代码

8. 设置当前怪物标记内容:
  1. SetMonsterMark("标记内容")
复制代码

9. 时间戳转换:
  1. local timeStr = os.date("%Y-%m-%d %H:%M:%S", os.time())
复制代码

10. 合区变量运算:
  1. local var = GetGlobalVar("变量名")
  2. SetGlobalVar("变量名", var + 1)
复制代码

11. 字符串匹配删除:
  1. local newStr = string.gsub("abc123def", "%d+", "")
复制代码

12. 自定义变量排序存入文本:
  1. local data = {10,5,8,3}
  2. table.sort(data)
  3. local file = io.open("data.txt","w")
  4. for k,v in pairs(data) do
  5.     file:write(v.."\n")
  6. end
  7. file:close()
复制代码

同学如果哪个功能需要更详细的解释可以告诉我哦~我会很乐意帮你解答的!(。♥‿♥。)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则