Hello.
First... I didn't tested any of the codes below. So watch out and test it!
There are many ways to achieve that... The easiest way is: Use Persistent + Cavebot to check and walk!
Persistent will check whenever a player is attacking you, make Cavebot go to specific waypoint and enable Cavebot.
Cavebot will walk to pz by following the path you created, wait the desired time and disable itself.
Persistent will run again and check that Cavebot is disabled and no players are attacking you, so it will make Cavebot go to specific waypoint to leave pz and enable Cavebot.
After walking back to pzone, Cavebot should disable itself again.
000 Stand (label: go_pz)
001 Stand
002 Stand
003 Action (make sure you create the Action on the very same location, because it will check if you are on that specific position)
if not islocation() then
gotolabel('go_pz')
else
wait(1000 * 60 * 5) -- waits 5 minutes
setsettings('Cavebot/Enabled', false) -- Disable cavebot
end
004 Stand (label: leave_pz)
005 Ladder
006 Stand
007 Action (make sure you create the Action on the very same location, because it will check if you are on that specific position)
if not islocation() then
gotolabel('leave_pz')
else
setsettings('Cavebot/Enabled', false) -- Disable cavebot
end
Persistent script:
local CONFIG = {
GO_PZ_LABEL = 'go_pz',
LEAVE_PZ_LABEL = 'leave_pz'
}
if IS_WALKING_PZ == nil then
IS_WALKING_PZ = false
end
if connected() then
local isSomePlayerAttacking = attackingme(2000, 'p') > 0
if isSomePlayerAttacking and IS_WALKING_PZ == false then
IS_WALKING_PZ = true
gotolabel(CONFIG.GO_PZ_LABEL)
if getsettings('Cavebot/Enabled') == false then
setsettings('Cavebot/Enabled', true)
end
elseif isSomePlayerAttacking == false and cavebotstatus() == false then
IS_WALKING_PZ = false
gotolabel(CONFIG.LEAVE_PZ_LABEL)
setsettings('Cavebot/Enabled', true)
end
end
There's another way using Persistents only, but you will need to place each location manually. So the persistent will try to walk on every location you setup.
local CONFIG = {
TimeWalkBack = 300, -- In seconds. How long should wait on GO_PZ place before walking LEAVE_PZ?
GO_PZ = { -- Locations to walk when player is attacking you.
{ X = 12345, Y = 12345, Z = 6, Use = false },
{ X = 12345, Y = 12345, Z = 6, Use = false }
},
LEAVE_PZ = { -- Locations to walk when player is attacking you.
{ X = 12345, Y = 12345, Z = 6, Use = false },
{ X = 12345, Y = 12345, Z = 6, Use = true }
},
}
if CONFIG ~= nil and CONFIG.GO_PZ ~= nil and CONFIG.GO_PZ ~= nil and connected() then
local isSomePlayerAttacking = attackingme(2000, 'p') > 0
local player_x = posx()
local player_y = posy()
local player_z = posz()
if walklocs == nil then
function walklocs(locations, name)
local result = true
for _, loc in ipairs(locations) do
result = false
local flag = false
local tries = 0
while flag == false do
tries = tries + 1
if loc.Use then
flag = reachlocation(loc.X, loc.Y, loc.Z, false, true)
if flag then
flag = useitem(0, ground(loc.X, loc.Y, loc.Z))
end
else
flag = reachlocation(loc.X, loc.Y, loc.Z, true, true)
end
if tries >= 3 then
break
elseif flag == false then
wait(200, 300)
end
end
if not flag then
playsound('default')
flashclient()
print('Failed to reach a location on: ' .. name .. ' -> ' .. loc)
else
result = true
end
end
return result
end
end
if isSomePlayerAttacking and (player_x ~= CONFIG.GO_PZ[#CONFIG.GO_PZ].X or player_y ~= CONFIG.GO_PZ[#CONFIG.GO_PZ].Y or player_z ~= CONFIG.GO_PZ[#CONFIG.GO_PZ].Z) then
walklocs(CONFIG.GO_PZ, 'GO_PZ')
elseif isSomePlayerAttacking == false and (player_x ~= CONFIG.LEAVE_PZ[#CONFIG.LEAVE_PZ].X or player_y ~= CONFIG.LEAVE_PZ[#CONFIG.LEAVE_PZ].Y or player_z ~= CONFIG.LEAVE_PZ[#CONFIG.LEAVE_PZ].Z) then
walklocs(CONFIG.LEAVE_PZ, 'LEAVE_PZ')
end
end