Posts: 3
Threads: 2
Joined: Apr 2020
Reputation:
0
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?
Posts: 2,911
Threads: 481
Joined: Jul 2018
Reputation:
82
10-28-2020, 07:07 PM
(This post was last modified: 10-28-2020, 07:08 PM by Arkilys.)
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
Posts: 3
Threads: 2
Joined: Apr 2020
Reputation:
0
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" />
Posts: 9
Threads: 2
Joined: Mar 2020
Reputation:
0
12-15-2020, 11:12 AM
(This post was last modified: 12-15-2020, 11:13 AM by Rakkkk.)
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
Posts: 2,911
Threads: 481
Joined: Jul 2018
Reputation:
82
12-15-2020, 02:30 PM
(This post was last modified: 12-20-2020, 12:14 AM by Arkilys.)
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
Posts: 5
Threads: 0
Joined: Oct 2020
Reputation:
0
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!
Posts: 2,911
Threads: 481
Joined: Jul 2018
Reputation:
82
12-24-2020, 09:55 PM
(This post was last modified: 12-24-2020, 09:56 PM by Arkilys.)
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.
Posts: 5
Threads: 0
Joined: Oct 2020
Reputation:
0
|Only Registered members can see download links. | Click here to buy subscription or here to register.
|