local players = {}
local eat = {}
local foods = {
{8, "Crunch.", 2362},
{15, "Munch.", 2666},
{12, "Munch.", 2667},
{10, "Mmmm.", 2668},
{17, "Munch.", 2669},
{4, "Gulp.", 2670},
{30, "Chomp.", 2671},
{60, "Chomp.", 2672},
{5, "Yum.", 2673},
{6, "Yum.", 2674},
{13, "Yum.", 2675},
{8, "Yum.", 2676},
{1, "Yum.", 2677},
{18, "Slurp.", 2678},
{1, "Yum.", 2679},
{2, "Yum.", 2680},
{9, "Yum.", 2681},
{20, "Yum.", 2682},
{17, "Munch.", 2683},
{8, "Crunch.", 2684},
{6, "Munch.", 2685},
{9, "Crunch.", 2686},
{2, "Crunch.", 2687},
{9, "Munch.", 2688},
{10, "Crunch.", 2689},
{3, "Crunch.", 2690},
{8, "Crunch.", 2691},
{6, "Munch.", 2792},
{9, "Munch.", 2793},
{6, "Gulp.", 2695},
{9, "Smack.", 2696},
{9, "Munch.", 2787},
{4, "Munch.", 2788},
{22, "Munch.", 2789},
{30, "Munch.", 2790},
{30, "Munch.", 2791},
{6, "Munch.", 2792},
{3, "Munch.", 2794},
{36, "Munch.", 2795},
{5, "Munch.", 2796},
{9, "Munch.", 2793},
{4, "Yum.", 5097},
{8, "Gulp.", 6125},
{10, "Mmmm.", 6278},
{15, "Mmmm.", 6279},
{12, "Mmmm.", 6393},
{15, "Mmmm.", 6394},
{20, "Mmmm.", 6501},
{6, "Gulp.", 6541},
{6, "Gulp.", 6542},
{6, "Gulp.", 6543},
{6, "Gulp.", 6544},
{6, "Gulp.", 6545},
{1, "Mmmm.", 6569},
{4, "Mmmm.", 6574},
{15, "Munch.", 7158},
{13, "Munch.", 7159},
{7, "Yum.", 7372},
{7, "Yum.", 7373},
{7, "Yum.", 7374},
{7, "Yum.", 7375},
{7, "Yum.", 7376},
{7, "Yum.", 7377},
{4, "Crunch.", 7909},
{7, "Gulp.", 8838},
{5, "Yum.", 8839},
{2, "Yum.", 8840},
{3, "Urgh.", 8841},
{3, "Munch.", 8842},
{3, "Crunch.", 8843},
{3, "Gulp.", 8844},
{2, "Munch.", 8845},
{11, "Yum.", 8447}
}
function autoEat(cid)
local food = nil
for _, v in ipairs(foods) do
if getPlayerItemCount(cid, v[3]) > 0 then
food = v
break
end
end
if food ~= nil then
if((getPlayerFood(cid) + food[1]) >= 400) then
doPlayerSendCancel(cid, "You are full.")
eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
return
end
doPlayerFeed(cid, food[1] * 4)
doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
doPlayerRemoveItem(cid, food[3], 1)
end
eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
return true
end
local function trainMana(cid, startTime)
if not isPlayer(cid) then
players[cid] = nil
return
end
if not players[cid] or players[cid][3] ~= startTime then
return
end
if getCreatureMana(cid) >= players[cid][2] then
doPlayerCastSpell(cid, players[cid][1])
end
addEvent(trainMana, 1000, cid, startTime)
end
local function showSpellList(cid)
local t = {}
for i = 0, getPlayerInstantSpellCount(cid) - 1 do
local spell = getPlayerInstantSpellInfo(cid, i)
if(spell.level ~= 0) then
if(spell.manapercent > 0) then
spell.mana = spell.manapercent .. "%"
end
table.insert(t, spell)
end
end
table.sort(t, function(a, b) return a.level < b.level end)
local text, prevLevel = "", -1
for i, spell in ipairs(t) do
local line = ""
if(prevLevel ~= spell.level) then
if(i ~= 1) then
line = "\n"
end
line = line .. "Spells for Level " .. spell.level .. "\n"
prevLevel = spell.level
end
text = text .. line .. " " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .."\n"
end
doShowTextDialog(cid, 2175, text)
end
function onSay(cid, words, param, channel)
if players[cid] then
if players[cid][3] == os.time() then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
return true
end
players[cid] = nil
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
return true
end
if param == "" then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells")
return true
elseif param == "list" then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
showSpellList(cid)
return true
end
local t = string.explode(param, ",")
if t[1] == nil or t[2] == nil then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
return true
end
t[1] = t[1]:lower()
--if not getPlayerLearnedInstantSpell(cid, t[1]) then
-- doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell name (" .. t[1] .. ") either does not exist, or you do not own this spell.")
-- return true
--end
local manaThreshold = tonumber(t[2])
if manaThreshold == nil then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is not a known number. Mana threshold has been set to your maximum mana.")
manaThreshold = getCreatureMaxMana(cid)
end
manaThreshold = math.floor(manaThreshold) -- to get rid of any decimals player might have thrown in
if manaThreshold < 0 or manaThreshold < getInstantSpellInfo(cid, t[1]).mana then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is lower then the spell cost of the spell (" .. t[1] .. "). Mana threshold has been set to your maximum mana.")
manaThreshold = getCreatureMaxMana(cid)
elseif manaThreshold > getCreatureMaxMana(cid) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
manaThreshold = getCreatureMaxMana(cid)
end
players[cid] = {getInstantSpellInfo(cid, t[1]).words, manaThreshold, os.time()}
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. t[1] .. "), Mana Threshold: " .. manaThreshold .. "")
trainMana(cid, os.time())
autoEat(cid)
return true
end