Everyone who has never used our Bots before, can test each one for 2 days without any limitation.
The trial is given automatically when you login on the Bot, but in some cases it wouldn't work (security reasons).
If this happens, send me a private message and i will be checking the failed trials manually and adding it for those who didn't get it.
We are looking for resellers who may accept payment methods different from ours, including classictibia's cash, realesta's cash, mastercores' cash, etc. Interested? Click here at anytime.



Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EatFood from ground bag
#1
Hello. Im trying to make a verry simple script to eat food from backpack to my bedmage script.

local foodBP = 'red backpack'
if connected() then
if reachgrounditem(foodBP, FALSE) then --- THIS WORKS
openitem(foodBP)                        --- WONT OPEN
eatfood()
  end       
end

I do not want to add XYZ to this since i make a universal script for all houses. Possible?
Reply

#2
Hello.

You MUST specify the XYZ to open a container on ground, but you don't need to do it manually. You can use gettiles() to find if there's a container (any or a specific one) around your character after using reachgrounditem() and then open it.

Something like this:
local FOOD_BP_ID = 1234 -- BP id

if connected() then
    if reachgrounditem(FOOD_BP_ID, FALSE) then
        local tiles = gettiles()
        local player_x = posx()
        local player_y = posy()
        local player_z = posz()

        local food_location = { x = 0, y = 0 }

        for _, tile in ipairs(tiles) do
            if math.abs(tile.posx - player_x) <= 1 and math.abs(tile.posy - player_y) and tile.posz == player_z and tile.itemcount > 1 then
                for __, item in ipairs(tile.items) do
                    if item.id == FOOD_BP_ID then
                        food_location.x = tile.posx
                        food_location.y = tile.posy
                        break
                    end
                end
            end

            if food_location.x > 0 then
                break
            end
        end


        openitem(FOOD_BP_ID, ground(food_location.x, food_location.y, player_z))
        wait(500, 800)
        eatfood()
    end      
end
Reply

#3
Thanks for quick support.
|Only Registered members can see download links. | Click here to buy subscription or here to register.
|Only Registered members can see download links. | Click here to buy subscription or here to register.alt="Smile" title="Smile" class="smilie smilie_1" />
Reply

#4
Can I change the player_Z for the character to stay 1 sqm north of the food? it is standing inside the door at PZ. I would liek it in front. Thanks!

local FOOD_BP_ID = 2853 -- BP id

if connected() then
    if reachgrounditem(FOOD_BP_ID, FALSE) then
        local tiles = gettiles()
        local player_x = posx()
        local player_y = posy()
        local player_z = posz()


        local food_location = { x = 0, y = 0 }

        for _, tile in ipairs(tiles) do
            if math.abs(tile.posx - player_x) <= 1 and math.abs(tile.posy - player_y) and tile.posz == player_z and tile.itemcount > 1 then
                for __, item in ipairs(tile.items) do
                    if item.id == FOOD_BP_ID then
                        food_location.x = tile.posx
                        food_location.y = tile.posy
                        break
                    end
                end
            end

            if food_location.x > 1 then
                break
            end
        end


        openitem(FOOD_BP_ID, ground(food_location.x, food_location.y, player_z))
        wait(500, 800)
        eatfood()
    end     
end
Reply

#5
player_Z is about floor.

The script above will not eat food directly from ground, but open a backpack that's around the character.

But this script may it eat food directly from ground/floor. It will search for one of the listed foods on the sqms around your character.
local FOODS = { 3578, 3582, 3577, 3725 } -- List of food ids.
local EAT_TIME = { Min = 300, Max = 480, } -- In SECONDS. Time to wait after eating food to eat again.
local EAT_TRIES = { Min = 3, Max = 8, } -- How tries to eat
local STOP_FULL = true -- Stop if you are full msg appears.

NEXT_EAT_TIME = NEXT_EAT_TIME or 1

if connected() and runningtime() >= NEXT_EAT_TIME then
    local tiles = gettiles()
    local player_x = posx()
    local player_y = posy()
    local player_z = posz()

    local food_location = { id = 0, x = 0, y = 0 }

    for _, tile in ipairs(tiles) do
        if math.abs(tile.posx - player_x) <= 1 and math.abs(tile.posy - player_y) and tile.posz == player_z and tile.itemcount > 1 then
            for __, item in ipairs(tile.items) do
                if table.find(FOODS, item.id) ~= nil then
                    food_location.id = item.id
                    food_location.x = tile.posx
                    food_location.y = tile.posy
                    break
                end
            end
        end

        if food_location.x > 0 then
            break
        end
    end

    if food_location.x > 0 then
        for i = 1, random(EAT_TRIES.Min, EAT_TRIES.Max) do
            useitem(food_location.id, ground(food_location.x, food_location.y, player_z))
            wait(400, 800)
            if STOP_FULL and statusmessage() == 'You are full.' then
                break
            end
        end
        NEXT_EAT_TIME = runningtime() + random(EAT_TIME.Min, EAT_TIME.Max)
    end
end
Reply

#6
Good Evening Arkilys,

i check that script above (realesta otbot v1.0.18 - realera.org), changed id for correct food (brown mushrooms id 3725) and just working one time when loading this script after nothing,

i have food front of me (north) on the ground 
can u help me please, check for me this, or what i do wrong.

Thank you for ur hard work, !
Merry Christmas!
Reply

#7
Hello.

The script works fine.
As it’s written, it will search for food around you and eat every X seconds according the settings.

Make sure you are running on Persistents, so it will run the script from time to time.
The Id 3725 is already on list, so you didn’t had to add it or so.

Notice it will only detect those ids on FOODS as a food.
Reply

#8
|Only Registered members can see download links. | Click here to buy subscription or here to register.
Reply



Forum Jump:



Forum software by © MyBB Theme © iAndrew 2016