I made sth like that
local friendName = "Player Name"
local friendPos
local creatureToAttack
local creature
local function findFriendAndCreatureToAttack()
for _, friend in pairs(g_game.getCreatures()) do
if friend:isPlayer() and friend:getName() == friendName then
friendPos = friend:getPosition()
break
end
end
if friendPos then
for _, creature in pairs(g_game.getCreatures()) do
if not creature:isPlayer() and not creature:isNpc() and friendPos:isInRange(creature:getPosition(), 2, 2) and creature:getHealthPercent() < 99 then
creatureToAttack = creature
end
end
end
end
local function attackCreature()
if not g_game.isAttacking() and creatureToAttack then
g_game.attack(creatureToAttack)
end
end
local function findAndFollowFriend()
for _, potentialFriend in pairs(g_game.getCreatures()) do
if potentialFriend:getName() == friendName and potentialFriend:isPlayer() then
creature = potentialFriend
break
end
end
if not g_game.isAttacking() and not g_game.isFollowing() and creature then
g_game.follow(creature)
end
end
findFriendAndCreatureToAttack()
attackCreature()
findAndFollowFriend()
auto(250, 350)