本帖最后由 nrm 于 2020-11-19 10:07 AM 编辑
最近技术板块都快长草了。俩版主也没啥动作,批评一下。
考虑到最近新人不少,很多人又是选择了mush作为客户端。作为一名老玩家,为了对各位表示欢迎,把我自己常用到的几个mush函数,在这里分享出来大家讨论讨论,算是激活一下技术板块的人气。
这些内容都很小儿科,老bt们请绕行。
首先是汉字的数字转换成阿拉伯数字的函数:
_nums={}
_nums["一"]=1
_nums["二"]=2
_nums["三"]=3
_nums["四"]=4
_nums["五"]=5
_nums["六"]=6
_nums["七"]=7
_nums["八"]=8
_nums["九"]=9
ctonum=function(str)
if (#str % 2) ==1 then
return 0
end
result=0
wan=1
unit=1
for i=#str -2 ,0,-2 do
char=string.sub(str,i+1,i+2)
if (char=="十") then
unit=10*wan
if (i==0) then
result=result+unit
elseif _nums[string.sub(str,i-1,i)]==nil then
result=result+unit
end
elseif (char=="百") then
unit=100*wan
elseif (char=="千") then
unit=1000*wan
elseif (char=="万") then
unit=10000*wan
wan=10000
else
if _nums[char]~=nil then
result=result+_nums[char]*unit
end
end
end
return result
end
这个应用最广泛,机器中大量用到。
同时,你如果做个计时器啥的,还会用到时间的转换。
function timetonum(text) ----中文时间转成秒
local text=string.gsub(text,"天",",")
text=string.gsub(text,"小时",",")
text=string.gsub(text,"分",",")
text=string.gsub(text,"秒","")
local timelist=Split(text,",")
local timelist2={}
for i,v in ipairs(timelist) do--转成第一个元素为秒,往后排
table.insert(timelist2,1,v)
end
local time_sec=0
for i,v in ipairs(timelist2) do
if i==1 then time_sec=time_sec+ctonum(v) end
if i==2 then time_sec=time_sec+ctonum(v)*60 end
if i==3 then time_sec=time_sec+ctonum(v)*3600 end
if i==4 then time_sec=time_sec+ctonum(v)*3600*24 end
end
return time_sec
end--endfunction
再然后呢,有时候你需要将汉字的方向转换成命令,比如“东”你想转换成“east",这其实最简单
function cnfx(fx)
local fx=fx
if fx=="上" then return "up" end
if fx=="下" then return "down" end
if fx=="南" then return "south" end
if fx=="东" then return "east" end
if fx=="西" then return "west" end
if fx=="北" then return "north" end
if fx=="南上" then return "southup" end
if fx=="南下" then return "southdown" end
if fx=="西上" then return "westup" end
if fx=="西下" then return "westdown" end
if fx=="东上" then return "eastup" end
if fx=="东下" then return "eastdown" end
if fx=="北上" then return "northup" end
if fx=="北下" then return "northdown" end
if fx=="西北" then return "northwest" end
if fx=="东北" then return "northeast" end
if fx=="西南" then return "southwest" end
if fx=="东南" then return "southeast" end
if fx=="小道" then return "xiaodao" end
if fx=="小路" then return "xiaolu" end
return fx
end
至于用途嘛,自己研究,老玩家都懂的。
还有时候呢,你想把地区信息分开来处理,比如”扬州南大街“你想得到”扬州“和”南大街“,那好,用这个函数:
areas={"中原","西湖梅庄","曲阜","信阳","泰山","长江南岸","长江","长江北岸","黄河南岸","黄河北岸","嘉兴","泉州","江州","牙山","临安府","西湖","福州","南昌","镇江","苏州","归云庄","小山村","张家口","麒麟村","大理城中","昆明","平西王府","桃源","岳阳","成都","建康府南城","建康府北城","北京","康亲王府","天坛","紫禁城","洛阳","灵州","晋阳","日月神教","神龙岛","襄阳","丝绸之路","长安","扬州","杀手帮","丐帮","岳王墓","姑苏慕容","桃花岛","峨嵋","天龙寺","武当山","华山","全真","古墓","少林寺","白驼山","星宿","明教","灵鹫","凌霄城","大轮寺","兰州","无量山","峨眉后山","杭州提督府","天地会"}
function get_place(str)
local place={}
for i=1,table.getn(areas) do
str_l=string.len(areas)
if areas==string.sub(str,1,str_l) then
place.area=areas -----区域名车
place.room=string.sub(str,str_l+1,string.len(str)) -----房间名称
break
end
end
return place
end
返回的place是一个table,place.area就是区域,类似”扬州“,place.room是房间,类似”南大街"
以上内容全部来自论坛,我只是根据自己习惯稍加修改,在这里做了个汇总。你根据自己的习惯和需求再去修改修改。
好了,这一期就到这里吧。
btw:很多人跟我要少林新手机器,我只能说,这东西是不能分享的,而且拿来主义没意思,等有时间单开个帖子跟大家分享一下少林新手机器制作过程中的几个难点以及处理方式吧。
引用 icer 老大的一句话:此处授之以渔,mud本质其实是个社交平台。不要把练功当成最终目的,否则你会很失落的。
北大侠客行MUD,中国最好的MUD
复制粘贴会丢内容,干脆把这几个常用函数做了个附件。 |