05-28-2022, 08:28 PM
This script will disable "Must attack me" of the listed creatures on Targeting if there's no player on screen. If a player appears, it will enable back only if you are not attacking anything, because a player could show up when you are killing something and Targeting would stop attack it.
local MONSTERS = { 'Demon', 'Goblin', 'Wolf' }
local DIST_ATTACK = 4
table.lower(MONSTERS)
local creatures = getcreatures('pmfs')
local PLAYER_FOUND = false
for _, creature in ipairs(creatures) do
if creature.isplayer then
PLAYER_FOUND = true
end
end
if PLAYER_FOUND == false then
for _, creature in ipairs(creatures) do
if table.find(MONSTERS, creature.name:lower()) ~= nil and creature.ismonster and creature.dist <= DIST_ATTACK then
setsettings('Targeting/' .. creature.name .. '/Setting1/Must attack me', false)
end
end
else
local attacking_creature = attacked()
if attacking_creature.id == 0 then
for _, monster in ipairs(MONSTERS) do
setsettings('Targeting/' .. monster .. '/Setting1/Must attack me', true)
end
end
end