• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts Auto eat revscriptsys

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,532
Solutions
27
Reaction score
872
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi! I use TFS 1.5 downgraded by nekiro (8.60) and wonder if someone can help me with this. I need to make this auto-eat script work as a talkaction, that uses the food as soon the player needsto refill, and, for example, use the following talkaction: !autofeed foodName, on/off like its done here. Here's the script I need to change:

https://otland.net/threads/tfs-1-3-revscriptsys-free-lua-scripting-service-post-your-requests-lets-learn-it-together.265794/page-2#post-2569289

Lua:
local foods = {
    [2362] = {5, "Crunch."}, -- carrot
    [2666] = {15, "Munch."}, -- meat
    [2667] = {12, "Munch."}, -- fish
    [2668] = {10, "Mmmm."}, -- salmon
    [2669] = {17, "Munch."}, -- northern pike
    [2670] = {4, "Gulp."}, -- shrimp
    [2671] = {30, "Chomp."}, -- ham
    [2672] = {60, "Chomp."}, -- dragon ham
    [2673] = {5, "Yum."}, -- pear
    [2674] = {6, "Yum."}, -- red apple
    [2675] = {13, "Yum."}, -- orange
    [2676] = {8, "Yum."}, -- banana
    [2677] = {1, "Yum."}, -- blueberry
    [2678] = {18, "Slurp."}, -- coconut
    [2679] = {1, "Yum."}, -- cherry
    [2680] = {2, "Yum."}, -- strawberry
    [2681] = {9, "Yum."}, -- grapes
    [2682] = {20, "Yum."}, -- melon
    [2683] = {17, "Munch."}, -- pumpkin
    [2684] = {5, "Crunch."}, -- carrot
    [2685] = {6, "Munch."}, -- tomato
    [2686] = {9, "Crunch."}, -- corncob
    [2687] = {2, "Crunch."}, -- cookie
    [2688] = {2, "Munch."}, -- candy cane
    [2689] = {10, "Crunch."}, -- bread
    [2690] = {3, "Crunch."}, -- roll
    [2691] = {8, "Crunch."}, -- brown bread
    [2695] = {6, "Gulp."}, -- egg
    [2696] = {9, "Smack."}, -- cheese
    [2787] = {9, "Munch."}, -- white mushroom
    [2788] = {4, "Munch."}, -- red mushroom
    [2789] = {22, "Munch."}, -- brown mushroom
    [2790] = {30, "Munch."}, -- orange mushroom
    [2791] = {9, "Munch."}, -- wood mushroom
    [2792] = {6, "Munch."}, -- dark mushroom
    [2793] = {12, "Munch."}, -- some mushrooms
    [2794] = {3, "Munch."}, -- some mushrooms
    [2795] = {36, "Munch."}, -- fire mushroom
    [2796] = {5, "Munch."}, -- green mushroom
    [5097] = {4, "Yum."}, -- mango
    [6125] = {8, "Gulp."}, -- tortoise egg
    [6278] = {10, "Mmmm."}, -- cake
    [6279] = {15, "Mmmm."}, -- decorated cake
    [6393] = {12, "Mmmm."}, -- valentine's cake
    [6394] = {15, "Mmmm."}, -- cream cake
    [6501] = {20, "Mmmm."}, -- gingerbread man
    [6541] = {6, "Gulp."}, -- coloured egg (yellow)
    [6542] = {6, "Gulp."}, -- coloured egg (red)
    [6543] = {6, "Gulp."}, -- coloured egg (blue)
    [6544] = {6, "Gulp."}, -- coloured egg (green)
    [6545] = {6, "Gulp."}, -- coloured egg (purple)
    [6569] = {1, "Mmmm."}, -- candy
    [6574] = {5, "Mmmm."}, -- bar of chocolate
    [7158] = {15, "Munch."}, -- rainbow trout
    [7159] = {13, "Munch."}, -- green perch
    [7372] = {2, "Yum."}, -- ice cream cone (crispy chocolate chips)
    [7373] = {2, "Yum."}, -- ice cream cone (velvet vanilla)
    [7374] = {2, "Yum."}, -- ice cream cone (sweet strawberry)
    [7375] = {2, "Yum."}, -- ice cream cone (chilly cherry)
    [7376] = {2, "Yum."}, -- ice cream cone (mellow melon)
    [7377] = {2, "Yum."}, -- ice cream cone (blue-barian)
    [7909] = {4, "Crunch."}, -- walnut
    [7910] = {4, "Crunch."}, -- peanut
    [7963] = {60, "Munch."}, -- marlin
    [8112] = {9, "Urgh."}, -- scarab cheese
    [8838] = {10, "Gulp."}, -- potato
    [8839] = {5, "Yum."}, -- plum
    [8840] = {1, "Yum."}, -- raspberry
    [8841] = {1, "Urgh."}, -- lemon
    [8842] = {7, "Munch."}, -- cucumber
    [8843] = {5, "Crunch."}, -- onion
    [8844] = {1, "Gulp."}, -- jalapeño pepper
    [8845] = {5, "Munch."}, -- beetroot
    [8847] = {11, "Yum."}, -- chocolate cake
    [9005] = {7, "Slurp."}, -- yummy gummy worm
    [9114] = {5, "Crunch."}, -- bulb of garlic
    [9996] = {0, "Slurp."}, -- banana chocolate shake
    [10454] = {0, "Your head begins to feel better."}, -- headache pill
    [11246] = {15, "Yum."}, -- rice ball
    [11370] = {3, "Urgh."}, -- terramite eggs
    [11429] = {10, "Mmmm."}, -- crocodile steak
    [12415] = {20, "Yum."}, -- pineapple
    [12416] = {10, "Munch."}, -- aubergine
    [12417] = {8, "Crunch."}, -- broccoli
    [12418] = {9, "Crunch."}, -- cauliflower
    [12637] = {55, "Gulp."}, -- ectoplasmic sushi
    [12638] = {18, "Yum."}, -- dragonfruit
    [12639] = {2, "Munch."}, -- peas
    [13297] = {20, "Crunch."}, -- haunch of boar
    [15405] = {55, "Munch."}, -- sandfish
    [15487] = {14, "Urgh."}, -- larvae
    [15488] = {15, "Munch."}, -- deepling filet
    [16014] = {60, "Mmmm."}, -- anniversary cake
    [18397] = {33, "Munch."}, -- mushroom pie
    [19737] = {10, "Urgh."}, -- insectoid eggs
    [20100] = {15, "Smack."}, -- soft cheese
    [20101] = {12, "Smack."} -- rat cheese
}

local autoFeed = CreatureEvent("AutoFeed")

function autoFeed.onThink(player, interval)
    local foundFood, removeFood
    for itemid, food in pairs(foods) do
        if player:getItemCount(itemid) > 0 then
            foundFood, removeFood = food, itemid
            break
        end
    end
    if not foundFood then
        return true
    end
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and math.floor(condition:getTicks() / 1000 + foundFood[1] * 12) < 1200 then
        player:feed(foundFood[1] * 12)
        player:say(foundFood[2], TALKTYPE_MONSTER_SAY)
        player:removeItem(removeFood, 1)
    end
    return true
end

autoFeed:register()

local login = CreatureEvent("RegisterAutoFeed")

function login.onLogin(player)
    player:registerEvent("AutoFeed")
    return true
end

login:register()

Regards! and thanks in advance :)
 
Solution
This should work... Just type !autofeed name

Lua:
local foods = {
    --Name, foodValue, itemid, words--
    ["carrot"] = {5, 2362, "Crunch."}, -- carrot ( CHANGE ALL VALUES TO BE LIKE THIS ) --
 
 
    [2666] = {15, "Munch."}, -- meat
    [2667] = {12, "Munch."}, -- fish
    [2668] = {10, "Mmmm."}, -- salmon
    [2669] = {17, "Munch."}, -- northern pike
    [2670] = {4, "Gulp."}, -- shrimp
    [2671] = {30, "Chomp."}, -- ham
    [2672] = {60, "Chomp."}, -- dragon ham
    [2673] = {5, "Yum."}, -- pear
    [2674] = {6, "Yum."}, -- red apple
    [2675] = {13, "Yum."}, -- orange
    [2676] = {8, "Yum."}, -- banana
    [2677] = {1, "Yum."}, -- blueberry
    [2678] = {18, "Slurp."}, -- coconut
    [2679] = {1, "Yum."}, -- cherry
    [2680] = {2, "Yum."}, -- strawberry
    [2681] =...
This should work... Just type !autofeed name

Lua:
local foods = {
    --Name, foodValue, itemid, words--
    ["carrot"] = {5, 2362, "Crunch."}, -- carrot ( CHANGE ALL VALUES TO BE LIKE THIS ) --
 
 
    [2666] = {15, "Munch."}, -- meat
    [2667] = {12, "Munch."}, -- fish
    [2668] = {10, "Mmmm."}, -- salmon
    [2669] = {17, "Munch."}, -- northern pike
    [2670] = {4, "Gulp."}, -- shrimp
    [2671] = {30, "Chomp."}, -- ham
    [2672] = {60, "Chomp."}, -- dragon ham
    [2673] = {5, "Yum."}, -- pear
    [2674] = {6, "Yum."}, -- red apple
    [2675] = {13, "Yum."}, -- orange
    [2676] = {8, "Yum."}, -- banana
    [2677] = {1, "Yum."}, -- blueberry
    [2678] = {18, "Slurp."}, -- coconut
    [2679] = {1, "Yum."}, -- cherry
    [2680] = {2, "Yum."}, -- strawberry
    [2681] = {9, "Yum."}, -- grapes
    [2682] = {20, "Yum."}, -- melon
    [2683] = {17, "Munch."}, -- pumpkin
    [2684] = {5, "Crunch."}, -- carrot
    [2685] = {6, "Munch."}, -- tomato
    [2686] = {9, "Crunch."}, -- corncob
    [2687] = {2, "Crunch."}, -- cookie
    [2688] = {2, "Munch."}, -- candy cane
    [2689] = {10, "Crunch."}, -- bread
    [2690] = {3, "Crunch."}, -- roll
    [2691] = {8, "Crunch."}, -- brown bread
    [2695] = {6, "Gulp."}, -- egg
    [2696] = {9, "Smack."}, -- cheese
    [2787] = {9, "Munch."}, -- white mushroom
    [2788] = {4, "Munch."}, -- red mushroom
    [2789] = {22, "Munch."}, -- brown mushroom
    [2790] = {30, "Munch."}, -- orange mushroom
    [2791] = {9, "Munch."}, -- wood mushroom
    [2792] = {6, "Munch."}, -- dark mushroom
    [2793] = {12, "Munch."}, -- some mushrooms
    [2794] = {3, "Munch."}, -- some mushrooms
    [2795] = {36, "Munch."}, -- fire mushroom
    [2796] = {5, "Munch."}, -- green mushroom
    [5097] = {4, "Yum."}, -- mango
    [6125] = {8, "Gulp."}, -- tortoise egg
    [6278] = {10, "Mmmm."}, -- cake
    [6279] = {15, "Mmmm."}, -- decorated cake
    [6393] = {12, "Mmmm."}, -- valentine's cake
    [6394] = {15, "Mmmm."}, -- cream cake
    [6501] = {20, "Mmmm."}, -- gingerbread man
    [6541] = {6, "Gulp."}, -- coloured egg (yellow)
    [6542] = {6, "Gulp."}, -- coloured egg (red)
    [6543] = {6, "Gulp."}, -- coloured egg (blue)
    [6544] = {6, "Gulp."}, -- coloured egg (green)
    [6545] = {6, "Gulp."}, -- coloured egg (purple)
    [6569] = {1, "Mmmm."}, -- candy
    [6574] = {5, "Mmmm."}, -- bar of chocolate
    [7158] = {15, "Munch."}, -- rainbow trout
    [7159] = {13, "Munch."}, -- green perch
    [7372] = {2, "Yum."}, -- ice cream cone (crispy chocolate chips)
    [7373] = {2, "Yum."}, -- ice cream cone (velvet vanilla)
    [7374] = {2, "Yum."}, -- ice cream cone (sweet strawberry)
    [7375] = {2, "Yum."}, -- ice cream cone (chilly cherry)
    [7376] = {2, "Yum."}, -- ice cream cone (mellow melon)
    [7377] = {2, "Yum."}, -- ice cream cone (blue-barian)
    [7909] = {4, "Crunch."}, -- walnut
    [7910] = {4, "Crunch."}, -- peanut
    [7963] = {60, "Munch."}, -- marlin
    [8112] = {9, "Urgh."}, -- scarab cheese
    [8838] = {10, "Gulp."}, -- potato
    [8839] = {5, "Yum."}, -- plum
    [8840] = {1, "Yum."}, -- raspberry
    [8841] = {1, "Urgh."}, -- lemon
    [8842] = {7, "Munch."}, -- cucumber
    [8843] = {5, "Crunch."}, -- onion
    [8844] = {1, "Gulp."}, -- jalapeño pepper
    [8845] = {5, "Munch."}, -- beetroot
    [8847] = {11, "Yum."}, -- chocolate cake
    [9005] = {7, "Slurp."}, -- yummy gummy worm
    [9114] = {5, "Crunch."}, -- bulb of garlic
    [9996] = {0, "Slurp."}, -- banana chocolate shake
    [10454] = {0, "Your head begins to feel better."}, -- headache pill
    [11246] = {15, "Yum."}, -- rice ball
    [11370] = {3, "Urgh."}, -- terramite eggs
    [11429] = {10, "Mmmm."}, -- crocodile steak
    [12415] = {20, "Yum."}, -- pineapple
    [12416] = {10, "Munch."}, -- aubergine
    [12417] = {8, "Crunch."}, -- broccoli
    [12418] = {9, "Crunch."}, -- cauliflower
    [12637] = {55, "Gulp."}, -- ectoplasmic sushi
    [12638] = {18, "Yum."}, -- dragonfruit
    [12639] = {2, "Munch."}, -- peas
    [13297] = {20, "Crunch."}, -- haunch of boar
    [15405] = {55, "Munch."}, -- sandfish
    [15487] = {14, "Urgh."}, -- larvae
    [15488] = {15, "Munch."}, -- deepling filet
    [16014] = {60, "Mmmm."}, -- anniversary cake
    [18397] = {33, "Munch."}, -- mushroom pie
    [19737] = {10, "Urgh."}, -- insectoid eggs
    [20100] = {15, "Smack."}, -- soft cheese
    [20101] = {12, "Smack."} -- rat cheese
}

local AUTOFEEDING = {}

local autoFeed = Talkaction("!autofeed")

function autoFeed.onSay(player, words, param)
    param = param:lower()
    local FOOD = foods[param]
 
    if not FOOD then
        player:sendCancelMessage("Food name invalid.")
        return false
    end
 
    if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][param] then
        AUTOFEEDING[player:getName()][param] = nil
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer auto eating "..param..".")
        return false
    end
 
    AUTOFEEDING[player:getName()][param] = true
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now auto eat "..param..".")
 
    if AUTOFEEDING[player:getName()] and not AUTOFEEDING[player:getName()]["isFeeding"] then
        AUTOFEEDING[player:getName()]["isFeeding"] = true
        feedPlayer(player:getName())
    end
 
    return false
end

function feedPlayer(name)
    local player = Player(name)
 
    if not player then
        if AUTOFEEDING[name] then
            AUTOFEEDING[name] = nil
        end
        return true
    end
 
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and (condition:getTicks() / 1000) >= 1200 then return true end
 
    for i, v in ipairs(foods) do
        if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][i] then
            if player:getItemCount(v[2]) > 0 then
                for x = 1, player:getItemCount(v[2]) do
                    local tmp_condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
                    if tmp_condition and math.floor(tmp_condition:getTicks() / 1000 + v[1] * 12) > 1200 then break end
                    player:feed(v[1])
                    player:say(v[3], TALKTYPE_MONSTER_SAY)
                    player:removeItem(v[2], 1)
                end
            end
        end
    end

    addEvent(feedPlayer, 60 * 1000, name)
end

autoFeed:separator(" ")
autoFeed:register()
 
Last edited:
Solution
This should work... Just type !autofeed name

Lua:
local foods = {
    --Name, foodValue, itemid, words--
    ["carrot"] = {5, 2362, "Crunch."}, -- carrot ( CHANGE ALL VALUES TO BE LIKE THIS ) --
 
 
    [2666] = {15, "Munch."}, -- meat
    [2667] = {12, "Munch."}, -- fish
    [2668] = {10, "Mmmm."}, -- salmon
    [2669] = {17, "Munch."}, -- northern pike
    [2670] = {4, "Gulp."}, -- shrimp
    [2671] = {30, "Chomp."}, -- ham
    [2672] = {60, "Chomp."}, -- dragon ham
    [2673] = {5, "Yum."}, -- pear
    [2674] = {6, "Yum."}, -- red apple
    [2675] = {13, "Yum."}, -- orange
    [2676] = {8, "Yum."}, -- banana
    [2677] = {1, "Yum."}, -- blueberry
    [2678] = {18, "Slurp."}, -- coconut
    [2679] = {1, "Yum."}, -- cherry
    [2680] = {2, "Yum."}, -- strawberry
    [2681] = {9, "Yum."}, -- grapes
    [2682] = {20, "Yum."}, -- melon
    [2683] = {17, "Munch."}, -- pumpkin
    [2684] = {5, "Crunch."}, -- carrot
    [2685] = {6, "Munch."}, -- tomato
    [2686] = {9, "Crunch."}, -- corncob
    [2687] = {2, "Crunch."}, -- cookie
    [2688] = {2, "Munch."}, -- candy cane
    [2689] = {10, "Crunch."}, -- bread
    [2690] = {3, "Crunch."}, -- roll
    [2691] = {8, "Crunch."}, -- brown bread
    [2695] = {6, "Gulp."}, -- egg
    [2696] = {9, "Smack."}, -- cheese
    [2787] = {9, "Munch."}, -- white mushroom
    [2788] = {4, "Munch."}, -- red mushroom
    [2789] = {22, "Munch."}, -- brown mushroom
    [2790] = {30, "Munch."}, -- orange mushroom
    [2791] = {9, "Munch."}, -- wood mushroom
    [2792] = {6, "Munch."}, -- dark mushroom
    [2793] = {12, "Munch."}, -- some mushrooms
    [2794] = {3, "Munch."}, -- some mushrooms
    [2795] = {36, "Munch."}, -- fire mushroom
    [2796] = {5, "Munch."}, -- green mushroom
    [5097] = {4, "Yum."}, -- mango
    [6125] = {8, "Gulp."}, -- tortoise egg
    [6278] = {10, "Mmmm."}, -- cake
    [6279] = {15, "Mmmm."}, -- decorated cake
    [6393] = {12, "Mmmm."}, -- valentine's cake
    [6394] = {15, "Mmmm."}, -- cream cake
    [6501] = {20, "Mmmm."}, -- gingerbread man
    [6541] = {6, "Gulp."}, -- coloured egg (yellow)
    [6542] = {6, "Gulp."}, -- coloured egg (red)
    [6543] = {6, "Gulp."}, -- coloured egg (blue)
    [6544] = {6, "Gulp."}, -- coloured egg (green)
    [6545] = {6, "Gulp."}, -- coloured egg (purple)
    [6569] = {1, "Mmmm."}, -- candy
    [6574] = {5, "Mmmm."}, -- bar of chocolate
    [7158] = {15, "Munch."}, -- rainbow trout
    [7159] = {13, "Munch."}, -- green perch
    [7372] = {2, "Yum."}, -- ice cream cone (crispy chocolate chips)
    [7373] = {2, "Yum."}, -- ice cream cone (velvet vanilla)
    [7374] = {2, "Yum."}, -- ice cream cone (sweet strawberry)
    [7375] = {2, "Yum."}, -- ice cream cone (chilly cherry)
    [7376] = {2, "Yum."}, -- ice cream cone (mellow melon)
    [7377] = {2, "Yum."}, -- ice cream cone (blue-barian)
    [7909] = {4, "Crunch."}, -- walnut
    [7910] = {4, "Crunch."}, -- peanut
    [7963] = {60, "Munch."}, -- marlin
    [8112] = {9, "Urgh."}, -- scarab cheese
    [8838] = {10, "Gulp."}, -- potato
    [8839] = {5, "Yum."}, -- plum
    [8840] = {1, "Yum."}, -- raspberry
    [8841] = {1, "Urgh."}, -- lemon
    [8842] = {7, "Munch."}, -- cucumber
    [8843] = {5, "Crunch."}, -- onion
    [8844] = {1, "Gulp."}, -- jalapeño pepper
    [8845] = {5, "Munch."}, -- beetroot
    [8847] = {11, "Yum."}, -- chocolate cake
    [9005] = {7, "Slurp."}, -- yummy gummy worm
    [9114] = {5, "Crunch."}, -- bulb of garlic
    [9996] = {0, "Slurp."}, -- banana chocolate shake
    [10454] = {0, "Your head begins to feel better."}, -- headache pill
    [11246] = {15, "Yum."}, -- rice ball
    [11370] = {3, "Urgh."}, -- terramite eggs
    [11429] = {10, "Mmmm."}, -- crocodile steak
    [12415] = {20, "Yum."}, -- pineapple
    [12416] = {10, "Munch."}, -- aubergine
    [12417] = {8, "Crunch."}, -- broccoli
    [12418] = {9, "Crunch."}, -- cauliflower
    [12637] = {55, "Gulp."}, -- ectoplasmic sushi
    [12638] = {18, "Yum."}, -- dragonfruit
    [12639] = {2, "Munch."}, -- peas
    [13297] = {20, "Crunch."}, -- haunch of boar
    [15405] = {55, "Munch."}, -- sandfish
    [15487] = {14, "Urgh."}, -- larvae
    [15488] = {15, "Munch."}, -- deepling filet
    [16014] = {60, "Mmmm."}, -- anniversary cake
    [18397] = {33, "Munch."}, -- mushroom pie
    [19737] = {10, "Urgh."}, -- insectoid eggs
    [20100] = {15, "Smack."}, -- soft cheese
    [20101] = {12, "Smack."} -- rat cheese
}

local AUTOFEEDING = {}

local autoFeed = Talkaction("!autofeed")

function autoFeed.onSay(player, words, param)
    param = param:lower()
    local FOOD = foods[param]
 
    if not FOOD then
        player:sendCancelMessage("Food name invalid.")
        return false
    end
 
    if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][param] then
        AUTOFEEDING[player:getName()][param] = nil
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer auto eating "..param..".")
        return false
    end
 
    AUTOFEEDING[player:getName()][param] = true
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now auto eat "..param..".")
 
    if AUTOFEEDING[player:getName()] and not AUTOFEEDING[player:getName()]["isFeeding"] then
        AUTOFEEDING[player:getName()]["isFeeding"] = true
        feedPlayer(player:getName())
    end
 
    return false
end

function feedPlayer(name)
    local player = Player(name)
 
    if not player then
        if AUTOFEEDING[player:getName()] then
            AUTOFEEDING[player:getName()] = nil
        end
        return true
    end
 
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and (condition:getTicks() / 1000) >= 1200 then return true end
 
    for i, v in ipairs(foods) do
        if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][i] then
            if player:getItemCount(v[2]) > 0 then
                for x = 1, player:getItemCount(v[2]) do
                    local tmp_condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
                    if tmp_condition and math.floor(tmp_condition:getTicks() / 1000 + v[1] * 12) > 1200 then break end
                    player:feed(v[1])
                    player:say(v[3], TALKTYPE_MONSTER_SAY)
                    player:removeItem(v[2], 1)
                end
            end
        end
    end

    addEvent(feedPlayer, 60 * 1000, name)
end

autoFeed:separator(" ")
autoFeed:register()

AUTOFEEDING[player:getName()][param]

Ah I really like this.
I wouldn't of thought to allow different foods to all be autofed simultaneously.

I would probably add a /autofeed stop or /autofeed clear and /autofeed all, to get rid of all foods / add all foods, so the player isn't forced to type out every food to stop/start, if they don't care about customizing it.
 
AUTOFEEDING[player:getName()][param]

Ah I really like this.
I wouldn't of thought to allow different foods to all be autofed simultaneously.

I would probably add a /autofeed stop or /autofeed clear and /autofeed all, to get rid of all foods / add all foods, so the player isn't forced to type out every food to stop/start, if they don't care about customizing it.
Not that it would be a huge performance hit but all of this is being stored in memory and having 100 players with all these values in the cache and all of it being ran through the loop would take a bit. Would be best to make sure only certain foods are in this system but its up to whoever uses it.
 
Last edited:
I made a small change to the playerFeed(name) function. Make sure you update it as it will cause problems if not fixed.
 
@ralke
Auto-eat script already almost killed one OTS!
At server start/test server it was not a problem, but 2-3 weeks after server start this script started using 99% of CPU!


I see that @Itutorial version has some fix for that - addEvent with 60 seconds delay.
In old version, it executed every second with onThink event. DO NOT use version with onThink.

Lua:
    for itemid, food in pairs(foods) do
        if player:getItemCount(itemid) > 0 then
            foundFood, removeFood = food, itemid
            break
        end
    end
This loop searches for 97 IDs of food items. Using onThink version, it will check all items in all backpacks of all players 97 times per second.
When you get more players online and they get high level, it will start using a lot of CPU.
 
@ralke
Auto-eat script already almost killed one OTS!
At server start/test server it was not a problem, but 2-3 weeks after server start this script started using 99% of CPU!


I see that @Itutorial version has some fix for that - addEvent with 60 seconds delay.
In old version, it executed every second with onThink event. DO NOT use version with onThink.

Lua:
    for itemid, food in pairs(foods) do
        if player:getItemCount(itemid) > 0 then
            foundFood, removeFood = food, itemid
            break
        end
    end
This loop searches for 97 IDs of food items. Using onThink version, it will check all items in all backpacks of all players 97 times per second.
When you get more players online and they get high level, it will start using a lot of CPU.
This is why having high rate servers (or not limiting cap) is such an issue. This code for a standard game where players cant have 500000 backpacks wont ever be too big of a consumption problem. Even with 200 players as long as you allow only certain foods to be autofed shouldn't have any problem.

Some of the food in that food table isn't actual food, I didn't mess with the table other than to modify the one he posted first value to show how the table needs to be set up.

A way to fix this could be to have some type of food deposit system saved in storage and loaded into memory.
 
Even with 200 players as long as you allow only certain foods to be autofed shouldn't have any problem.
It's more like problem on low exp. Where players care about loot and carry a lot of items in BP. On 'evo high exp', they don't pick items from monsters and often cast spells, not use runes.
Biggest problem is on protocols < 8.1, where potions/runes are not stackable and people go hunt with 2k items - potions for sorcs - on 200 lvl knight.
 
All this information is great! I will avoid the usage of onThink events for stuff like this. Had a little issue, guess can be easily fixed but I prefer to ask what's wrong :) @Itutorial
1648311518294.png

Lua:
local foods = {
    --Name, foodValue, itemid, words--
    ["carrot"] = {5, 2362, "Crunch."}, -- carrot ( CHANGE ALL VALUES TO BE LIKE THIS ) --
    ["meat"] = {15, 2666, "Munch."}, 
    ["fish"] = {12, 2667, "Munch."}, 
    ["brown mushroom"] = {22, 2789, "Munch."}, 
    ["ham"] = {30, 2671, "Chomp."}, 
    ["dragon ham"] = {60, 2672, "Chomp."}
}

local AUTOFEEDING = {}

local autoFeed = Talkaction("!autofeed")

function autoFeed.onSay(player, words, param)
    param = param:lower()
    local FOOD = foods[param]
 
    if not FOOD then
        player:sendCancelMessage("Food name invalid.")
        return false
    end
 
    if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][param] then
        AUTOFEEDING[player:getName()][param] = nil
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer auto eating "..param..".")
        return false
    end
 
    AUTOFEEDING[player:getName()][param] = true
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now auto eat "..param..".")
 
    if AUTOFEEDING[player:getName()] and not AUTOFEEDING[player:getName()]["isFeeding"] then
        AUTOFEEDING[player:getName()]["isFeeding"] = true
        feedPlayer(player:getName())
    end
 
    return false
end

function feedPlayer(name)
    local player = Player(name)
 
    if not player then
        if AUTOFEEDING[name] then
            AUTOFEEDING[name] = nil
        end
        return true
    end
 
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and (condition:getTicks() / 1000) >= 1200 then return true end
 
    for i, v in ipairs(foods) do
        if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][i] then
            if player:getItemCount(v[2]) > 0 then
                for x = 1, player:getItemCount(v[2]) do
                    local tmp_condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
                    if tmp_condition and math.floor(tmp_condition:getTicks() / 1000 + v[1] * 12) > 1200 then break end
                    player:feed(v[1])
                    player:say(v[3], TALKTYPE_MONSTER_SAY)
                    player:removeItem(v[2], 1)
                end
            end
        end
    end

    addEvent(feedPlayer, 60 * 1000, name)
end

autoFeed:separator(" ")
autoFeed:register()
 
Add

Lua:
AUTOFEEDING[player:getName()] = {}

above

Code:
AUTOFEEDING[player:getName()][param] = true
line 29

I don't think that will work but I don't know the problem so we can start there.
 
I first tried by adding
Lua:
AUTOFEEDING[player:getName()] = {}
It works, it says "you will now auto eat". But unfurtunately player never starts eating.

Also tried

Lua:
if not AUTOFEEDING[player:getName()] then 
    AUTOFEEDING[player:getName()] = {}
end

Above

Lua:
AUTOFEEDING[player:getName()][param] = true

But it's the same, no errors, the message "you will now auto eat..." appears, but player never starts eating.
 
You waited the full minute it takes?

try changing

Lua:
addEvent(feedPlayer, 60 * 1000, name)

to just 1000


No errors in console?


Try using this.. I modified it a bit so players can just type !autofeed and it will start autofeeding if its not started. You can use this to test also...

It will also save their autoeating configuration now until shutdown. They will just have to type !autofeed as I said before to start it again when they log in.

Lua:
local foods = {
    --Name, foodValue, itemid, words--
    ["carrot"] = {5, 2362, "Crunch."}, -- carrot ( CHANGE ALL VALUES TO BE LIKE THIS ) --
    ["meat"] = {15, 2666, "Munch."},
    ["fish"] = {12, 2667, "Munch."},
    ["brown mushroom"] = {22, 2789, "Munch."},
    ["ham"] = {30, 2671, "Chomp."},
    ["dragon ham"] = {60, 2672, "Chomp."}
}

local AUTOFEEDING = {}

local autoFeed = TalkAction("!autofeed")

function autoFeed.onSay(player, words, param)
    param = param:lower()
    local FOOD = foods[param]
   
    if not param or param == "" then
        if AUTOFEEDING[player:getName()] and not AUTOFEEDING[player:getName()]["isFeeding"] then
            AUTOFEEDING[player:getName()]["isFeeding"] = true
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are now auto eating.")
            feedPlayer(player:getName())
            return false
        end
    end
   
    if not FOOD then
        player:sendCancelMessage("Food name invalid.")
        return false
    end
 
    if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][param] then
        AUTOFEEDING[player:getName()][param] = nil
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer auto eating "..param..".")
        return false
    end
 
    if not AUTOFEEDING[player:getName()] then
        AUTOFEEDING[player:getName()] = {}
    end
 
    AUTOFEEDING[player:getName()][param] = true
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now auto eat "..param..".")
 
    if AUTOFEEDING[player:getName()] and not AUTOFEEDING[player:getName()]["isFeeding"] then
        AUTOFEEDING[player:getName()]["isFeeding"] = true
        feedPlayer(player:getName())
    end
 
    return false
end

function feedPlayer(name)
    local player = Player(name)
 
    if not player then
        if AUTOFEEDING[name] then
            AUTOFEEDING[name]["isFeeding"] = false
        end
        return true
    end
 
    local condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition and (condition:getTicks() / 1000) >= 1200 then return true end
 
    for i, v in ipairs(foods) do
        if AUTOFEEDING[player:getName()] and AUTOFEEDING[player:getName()][i] then
            if player:getItemCount(v[2]) > 0 then
                for x = 1, player:getItemCount(v[2]) do
                    local tmp_condition = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
                    if tmp_condition and math.floor(tmp_condition:getTicks() / 1000 + v[1] * 12) > 1200 then break end
                    player:feed(v[1])
                    player:say(v[3], TALKTYPE_MONSTER_SAY)
                    player:removeItem(v[2], 1)
                end
            end
        end
    end

    addEvent(feedPlayer, 60 * 1000, name)
end

autoFeed:separator(" ")
autoFeed:register()
 
Last edited:
Hi there,
My man just ate 44 brown mushrooms at once. Damn he must have been really hungry. Jokes aside, if someone is wondering what's wrong:
Line 73
Lua:
                    player:feed(v[1])
Change into:
Lua:
player:feed(v[1]*12)
It is rather proper 'feed' calculation which can be even noticed in upper condition calculation:
Lua:
tmp_condition:getTicks() / 1000 + v[1] * 12

Passed value is way too low and it results with enormous appetite.


Thanks guys you did good job with this script.
 
Back
Top