优化下列一段代码 if arg == 103 then if GetMenPai(sceneId, selfId) ~= 9 then x990010_MsgBox( sceneId, selfId, targetId, "你已是别的门派的高徒了,我们不收你。" ) return end LuaFnJoinMenpai(sceneId, selfId, targetId, MP_SHAOLIN) LuaFnSetXinFaLevel(sceneId,selfId,1,30) LuaFnSetXinFaLevel(sceneId,selfId,2,30) LuaFnSetXinFaLevel(sceneId,selfId,3,30) LuaFnSetXinFaLevel(sceneId,selfId,4,30) LuaFnSetXinFaLevel(sceneId,selfId,5,30) LuaFnSetXinFaLevel(sceneId,selfId,6,30) --LuaFnSetXinFaLevel(sceneId,selfId,55,60) --LuaFnSetXinFaLevel(sceneId,selfId,72,60) LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0) local nam = LuaFnGetName( sceneId, selfId ) BroadMsgByChatPipe( sceneId, selfId, "#cFF0000[门派公告]:#c66ccff["..nam.."]#P已经加入了"..x990010_g_mpInfo[arg-101][1].."!", 4 ) CallScriptFunction( 999994, "ActionSkill",sceneId, selfId, -1 ) x990010_ooo( sceneId, selfId) end if arg == 104 then if GetMenPai(sceneId, selfId) ~= 9 then x990010_MsgBox( sceneId, selfId, targetId, "你已是别的门派的高徒了,我们不收你。" ) return end LuaFnJoinMenpai(sceneId, selfId, targetId, MP_TIANSHAN) LuaFnSetXinFaLevel(sceneId,selfId,43,30) LuaFnSetXinFaLevel(sceneId,selfId,44,30) LuaFnSetXinFaLevel(sceneId,selfId,45,30) LuaFnSetXinFaLevel(sceneId,selfId,46,30) LuaFnSetXinFaLevel(sceneId,selfId,47,30) LuaFnSetXinFaLevel(sceneId,selfId,48,30) --LuaFnSetXinFaLevel(sceneId,selfId,62,60) --LuaFnSetXinFaLevel(sceneId,selfId,79,60) LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0) local nam = LuaFnGetName( sceneId, selfId ) BroadMsgByChatPipe( sceneId, selfId, "#cFF0000[门派公告]:#c66ccff["..nam.."]#P已经加入了"..x990010_g_mpInfo[arg-101][1].."!", 4 ) CallScriptFunction( 999994, "ActionSkill",sceneId, selfId, -1 ) x990010_ooo( sceneId, selfId) end
时间: 2023-07-14 14:12:22 浏览: 245
可以考虑将重复的代码提取出来,避免代码冗余和重复编写。具体可以将 arg 值作为参数传入一个函数中,然后根据不同的 arg 值执行不同的操作。示例代码如下:
```
local function joinMenpai(sceneId, selfId, targetId, arg)
if GetMenPai(sceneId, selfId) ~= 9 then
x990010_MsgBox(sceneId, selfId, targetId, "你已是别的门派的高徒了,我们不收你。")
return
end
local xinfaInfo = {}
if arg == 103 then
xinfaInfo = {1, 2, 3, 4, 5, 6}
LuaFnJoinMenpai(sceneId, selfId, targetId, MP_SHAOLIN)
elseif arg == 104 then
xinfaInfo = {43, 44, 45, 46, 47, 48}
LuaFnJoinMenpai(sceneId, selfId, targetId, MP_TIANSHAN)
end
for i, xinfaId in ipairs(xinfaInfo) do
LuaFnSetXinFaLevel(sceneId, selfId, xinfaId, 30)
end
LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0)
local nam = LuaFnGetName(sceneId, selfId)
BroadMsgByChatPipe(sceneId, selfId, "#cFF0000[门派公告]:#c66ccff["..nam.."]#P已经加入了"..x990010_g_mpInfo[arg-101][1].."!", 4)
CallScriptFunction(999994, "ActionSkill", sceneId, selfId, -1)
x990010_ooo(sceneId, selfId)
end
if arg == 103 or arg == 104 then
joinMenpai(sceneId, selfId, targetId, arg)
end
```
这样可以有效减少代码量,使代码更加简洁易读。
阅读全文