tianheng 发表于 2011-12-3 09:22:20

新学lua,打坐吐纳,欢迎拍砖

local info = {}

info.job = "tn" -- or tn
info.job0 = nil --保存工作状态
info.double = false --是否双倍内力
info.eforce = 10 --有效内功的十分之一
info.qx = 0 --气血
info.qxmax = 0
info.js = 0
info.jsmax = 0
info.jl = 0
info.jlmax = 0
info.nl = 0
info.nlmax = 0
info.food = "ganliang"
info.water = "jiudai"
info.sleep_to = ""
info.sleep_back = ""

function test(name, line, wildcards)
print("name:" .. name);
print("line:" .. line);
for i, v in ipairs(wildcards) do
print("wcs[" .. i .. "]:" .. v);
end
end

function gethp(name, line, wildcards)
SetVariable ( "exp" , wildcards );
SetVariable ( "pot" , wildcards );
SetVariable ( "nlmax" , wildcards );
SetVariable ( "nl" , wildcards );
SetVariable ( "jlmax" , wildcards );
SetVariable ( "jl" , wildcards );
SetVariable ( "qxmax" , wildcards );
SetVariable ( "qx" , wildcards );
SetVariable ( "jsmax" , wildcards );
SetVariable ( "js" , wildcards );
end

function info_init()
info.qx = tonumber (GetVariable ("qx"))
info.qxmax = tonumber (GetVariable ("qxmax"))
info.js = tonumber (GetVariable ("js"))
info.jsmax = tonumber (GetVariable ("jsmax"))
info.jl = tonumber (GetVariable ("jl"))
info.jlmax = tonumber (GetVariable ("jlmax"))
info.nl = tonumber (GetVariable ("nl"))
info.nlmax = tonumber (GetVariable ("nlmax"))
info.enforce = tonumber (GetVariable ("enforce"))
info.job = GetVariable ("job")
if info.job == nil then
SetVariable ("job", "dz")
info.job = "dz"
end
end

function check(name, line, wildcards)
if wildcards == "正" then
--DoAfterSpecial (1, 'SendNoEcho("checkbusy")', 12)
AddTimer ("my_timer", 0, 0, 1, "", 1 + 4 + 1024 + 16384, "busy")
end
if wildcards == "不" then
Send("hpbrief")
Send("set job on")
end
end

function dojob(name, line, wildcards)
AddTimer ("my_timer_fadai", 0, 8, 30, "", 1 + 4 + 1024 + 16384, "busy")
Send("eat " .. info.food)
Send("drink " .. info.water)
if info.job == 'dz' then
dz()
end
if info.job == 'tn' then
tn()
end
end

function dz()
info_init()

if info.nl < 100 then
print("内力不够啊,等待30秒恢复")
--DoAfterSpecial (30, 'SendNoEcho("checkbusy")', 12)
AddTimer ("my_timer", 0, 0, 30, "", 1 + 4 + 1024 + 16384, "busy")
return
end

local diff = 2 * info.nlmax - info.nl + 1
diff = (info.nlmax < 1000) and math.ceil(diff/2) or diff

if info.double then
if diff <= info.qx then
local _diff = (info.nlmax < 1000) and diff*2 or diff
print("_diff:" .. _diff)
if _diff + info.nl > info.nlmax * 2 then
info.job = info.job0
info.job0 = nil
info.double = nil
print("双倍内力恢复完成,继续未完成的工作:" .. info.job)
SendNoEcho("checkbusy")
return
end
end
end

if info.js < info.jsmax * 0.6 then
print("精神不佳啊,恢复(exert regenerate)")
--Send("exert regenerate")
--DoAfterSpecial (15, 'SendNoEcho("checkbusy")', 12)
AddTimer ("my_timer", 0, 0, 15, "", 1 + 4 + 1024 + 16384, "busy")
return
end

if info.qx < info.qxmax * 0.3 then
print("气血不佳啊,恢复(exert recover)")
--Send("exert recover")
--DoAfterSpecial (15, 'SendNoEcho("checkbusy")', 12)
AddTimer ("my_timer", 0, 0, 15, "", 1 + 4 + 1024 + 16384, "busy")
return
end

diff = (diff > info.qx * 0.8) and (math.floor((info.qx / info.enforce) / 2) * info.enforce) or diff

diff = (diff < 10) and 10 or diff

Send("dazuo " .. diff)
SendNoEcho("checkbusy")

end

function tn()
info_init()

if info.nl < 100 then
print("内力不够啊,等待30秒恢复")
info.job0 = info.job
info.job = "dz"
info.double = true
--DoAfterSpecial (30, 'SendNoEcho("checkbusy")', 12)
AddTimer ("my_timer", 0, 0, 30, "", 1 + 4 + 1024 + 16384, "busy")
return
end

local diff = 2 * info.jlmax - info.jl + 1
diff = (info.jlmax < 1000) and math.ceil(diff/2) or diff

if info.qx < info.qxmax * 0.6 then
print("气血不佳啊,恢复(exert recover)")
--Send("exert recover")
--DoAfterSpecial (15, 'SendNoEcho("checkbusy")', 12)
AddTimer ("my_timer", 0, 0, 15, "", 1 + 4 + 1024 + 16384, "busy")
return
end

if info.js < info.jsmax * 0.3 then
print("精神不佳啊,恢复(exert regenerate)")
Send("exert regenerate")
--DoAfterSpecial (1, 'SendNoEcho("checkbusy")', 12)
AddTimer ("my_timer", 0, 0, 1, "", 1 + 4 + 1024 + 16384, "busy")
return
end

diff = (diff > info.js * 0.8) and (math.floor((info.js / info.enforce) / 2) * info.enforce) or diff

diff = (diff < 10) and 10 or diff

Send("tuna " .. diff)
SendNoEcho("checkbusy")

end

function busy()
SendNoEcho("checkbusy")
end

function start()
EnableTriggerGroup ("dztn", true)
Send("checkbusy")
end

function stop()
DeleteTimer("my_timer")
DeleteTimer("my_timer_fadai")
EnableTriggerGroup ("dztn", false)
end

北大侠客行MUD,中国最好的MUD

tianheng 发表于 2011-12-3 09:41:15

使用起来很简单啊

npckill 发表于 2011-12-3 09:41:22

yct7

zyj 发表于 2019-3-20 09:32:45

hzu
页: [1]
查看完整版本: 新学lua,打坐吐纳,欢迎拍砖