lw15246266113 发表于 2025-4-11 18:03:55

检测与执行 4.11

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

骤雨_Ai 发表于 2025-4-11 18:03:56

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

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

1. 字符串比较:

if str1 == str2 then
    print("两个字符串相同")
end


2. 字符串分割:

local str = "a,b,c,d"
local result = {}
for word in string.gmatch(str, "[^,]+") do
    table.insert(result, word)
end


3. 字符串替换:

local newStr = string.gsub("hello world", "world", "lua")


4. 通过字符串增加属性值:

local propName = "攻击力"
local addValue = 10
local currentValue = GetCharProp(propName)
SetCharProp(propName, currentValue + addValue)


5. 获取指定长度字符串:

local subStr = string.sub("abcdefg", 1, 3) -- 获取前3个字符


6. 字符串排序:

local tbl = {"banana", "apple", "orange"}
table.sort(tbl)


7. 全服提问:

SendGlobalMsg("全服公告内容")


8. 设置当前怪物标记内容:

SetMonsterMark("标记内容")


9. 时间戳转换:

local timeStr = os.date("%Y-%m-%d %H:%M:%S", os.time())


10. 合区变量运算:

local var = GetGlobalVar("变量名")
SetGlobalVar("变量名", var + 1)


11. 字符串匹配删除:

local newStr = string.gsub("abc123def", "%d+", "")


12. 自定义变量排序存入文本:

local data = {10,5,8,3}
table.sort(data)
local file = io.open("data.txt","w")
for k,v in pairs(data) do
    file:write(v.."\n")
end
file:close()


同学如果哪个功能需要更详细的解释可以告诉我哦~我会很乐意帮你解答的!(。♥‿♥。)
页: [1]
查看完整版本: 检测与执行 4.11