[關於mushclient]匹配模式
getitem=function(s)function isin(s,t)
for i, v in ipairs(t) do
if(v==s)then
return true
end -- if
end -- for
end -- isin
local item_table = {"補天石","冰蠶絲","玄冰寒鐵","龍血","金塊","烏金絲","青龍彩晶","名號:.*","武曲","文曲","晶砂","(.*)骷髏\頭",".*寶石.*","丹","符文","天隕","冰柱","寒鋼","丸"} --骷髏頭有吃字
if isin (s,item_table) then
Execute("get "..s.."")
end -- if
end -- getitem
以上是用來觸發掉落物品的
mud訊息如下:
物品中文 = 物品英文
觸發
^(\S+)\s+\=.*$
我的問題是可以正確抓到%1
也可以比對到item_table裡,但是因為有些item的中文名字會有變動
譬如會有
名號:XXXX 名號:yyyy之類的
我以為是要改成"名號(%S+)"
但是比對不出來,想請問高手
謝謝大家
小弟初學mushclient和lua
北大侠客行MUD,中国最好的MUD 自問自答第一次的v==s只是找一不一樣
有人幫我提示用string.find
string.find就直接找到部份相同就可以了
getitem=function(s)
function isin(s,t)
for i, v in ipairs(t) do
if string.find(s,v)then
return true
end -- if
end -- for
end -- isin
local item_table = {"補天石","冰蠶絲","玄冰寒鐵","龍血","金塊","烏金絲","青龍彩晶","名號","武曲","文曲","晶砂","骷髏\頭","寶石","丹","符文","天隕","冰柱","寒鋼","丸"}
if isin (s,item_table) then
Execute("get "..s.."")
end -- if
end -- getitem
页:
[1]