Okay, so I run MUSH versus Mudlet. Only reason is because my system's too old, need to upgrade. Anyway, for MUSH, I wrote an auto-sipper(written in Lua). Works fairly well, except for one thing: As soon as health or mana hits X% (X being the percent I set it, in the case 75% health, 65% Mana), it sips without regard to the sip balance. Now, I've no actually coding expereince (got the help of a friend who codes for a living), so I don't know what the issue is within the code, or how to fix it. Any help would be appreciated.
The code is as follows:
SetVariable('WorldScriptCompiled', "False")
function sleep(sec)
socket.select(nil, nil, sec)
end
Health = "health"
Vitality = "vitality"
Mana = "mana"
Mentality = "mentality"
dbg = function(t,m)
if core.Debug() then
ColourNote("red", "black", "sipper::" .. t .. ": " .. m)
end
end
HeartBeatInterval = tonumber(GetVariable('HeartBeatInterval'))
if HeartBeatInterval < 1 then
HeartBeatInterval = 10
SetVariable('HeartBeatInterval', 10)
end
-- Heartbeat routines
stats = {
healthText = "health",
manaText = "mana",
healthHeal = 0.75,
manaHeal = 0.85,
}
potions = {
BG = "Indigo",
Warn = "Yellow",
Out = "Red",
types = {
Health,
Vitality,
Mana,
Mentality,
}
}
UseHealth = "usehealth"
UseMana = "usemana"
potions[Health] = 0
potions[Vitality] = 0
potions[Mana] = 0
potions[Mentality] = 0
potions[UseHealth] = Vitality
potions[UseMana] = Mentality
potions.set = function (h, v, ma, me)
potions[Health] = h
potions[Vitality] = v
potions[Mana] = ma
potions[Mentality] = me
end
potions.setcount = function(typeof, amount)
potions[typeof] = amount
end
potions.inc = function(typeof)
potions[typeof] = potions[typeof] + 1
end
potions.add = function(typeof, count)
potions[typeof] = potions[typeof] + tonumber(count)
end
potions.dec = function(typeof)
potions[typeof] = potions[typeof] - 1
end
potions.clear = function(typeof, amount)
potions[Health] = 0
potions[Vitality] = 0
potions[Mana] = 0
potions[Mentality] = 0
end
potions.setpotions = function(primary, secondary, setof)
potions[setof] = 0
if (potions[primary] > 0) then
potions[setof] = primary
elseif (potions[secondary] > 0) then
ColourNote(potions.Warn, potions.BG, "You are out of primary " .. primary .. ", using " .. secondary)
potions[setof] = secondary
else
ColourNote(potions.Out, potions.BG, "You are OUT OF " .. primary .. " and " .. secondary .. " potions!")
end
return potions[setof]
end
potions.count = function()
for typeof = 1, #potions.types do
ColourNote("green", "black", potions.types[typeof] .. " left: " .. potions[potions.types[typeof]])
end
end
potions.list = function()
SendImmediate("elist")
end
core = {
paused = false,
interval = HeartBeatInterval,
current = HeartBeatInterval,
priority = Health,
}
core.sethb = function(val)
core.paused = false
if val == true then
core.paused = true
end
end
core.debugflag = false
core.Debug = function()
return core.debugflag
end
core.togglehb = function ()
if (core.paused == true) then
dbg ("core::togglebh", "Setting pause to false")
core.sethb(false)
return
end
dbg ("core::togglebh", "Setting pause to true")
core.sethb (true)
end
core.setinterval = function(int)
core.interval = int
core.current = int
end
core.tick = function()
core.current = core.current - 1
if core.current < 1 then
core.current = core.interval
return true
end
return false
end
core.elixBal = true;
-- curing functions
heartbeat = function (health, mana)
if core.paused then
return
end
if core.tick() then
check.hm(health, mana)
end
dbg("heartbeat", "Interval is now " .. core.current)
end -- func
check = {
-- check stats, fix if necessary
stats = function (current, maxa, percent, typeof)
dbg ("check::stats", "Checking " .. typeof .. "...");
if (core.elixBal) and (current < maxa*percent) then
if potions[typeof] > 0 then
dbg("check::stats:", current .. "<" .. maxa*percent)
Send ("sip " .. typeof)
ColourNote("red", "#555555", typeof .. " potion was sipped")
potions.dec(typeof)
return true
end
end
return false
end
,
hm = function (health, mana)
mh = tonumber(GetVariable('MaximumHealth'))
mm = tonumber(GetVariable('MaximumMana'))
stats.manaText = potions[UseMana]
stats.healthText = potions[UseHealth]
dbg ("check::hm", stats.manaText)
dbg ("check::hm", stats.healthText)
potions.setpotions(Vitality, Health, UseHealth);
potions.setpotions(Mentality, Mana, UseMana);
if core.priority == Mana then
if check.stats(mana, mm, stats.manaHeal, stats.manaText) == false then
check.stats(health, mh, stats.healthHeal, stats.healthText)
end
else
-- fallthrough to health, default
if check.stats(health, mh, stats.healthHeal, stats.healthText) == false then
check.stats(mana, mm, stats.manaHeal, stats.manaText)
end
end
potions.count()
end
}
dbg ("nil", "core.paused=" .. tostring(core.paused))
SetVariable('WorldScriptCompiled', "True")
-- ColourNote("white", "black", "World script sipper is ready.")
potions.list()
Send("elist")
--The tonic heals and soothes you.
--Walnut vial457551 a tonic of mentality 166 30
0
Comments