Log in

View Full Version : utamo and exit when x amount of x monsters on screen



Mageq
08-22-2016, 10:42 AM
Hi, if somebody could help me to write a script to cast utamo vita and exit when the number of X monsters is visible on screen that would be perfect.

In my words its

Monster name =
Creature count = 5+

do utamo vita
do exit

shadowart
08-22-2016, 03:11 PM
Something like this. I haven't tested it though so there might be a bug or two lurking around:

MonsterNames = {"juggernaut", "Demon"}
Count = 5 -- Inclusive
MaxStandtime = 60 -- Seconds

-------------------------------------------------------------
-------------------------------------------------------------
-------------------------------------------------------------

-- Preprocess the monster list for faster processing as well as
-- ensuring that no capitalization errors happen
local function preprocessMonsters(names)
local monsters = {}
for _, name in ipairs(names) do
monsters[name:lower()] = true
end
return monsters
end

local function monsterCount(monsters)
local count = 0
for name, c in Creature.iMonsters(range or 7) do
if monsters[name:lower()] then
count = count + 1
end
end
return count
end

-- Only ensures that we cast a spell which shares cooldown with the specified spell
local function ensuredCast(spell, mana)
-- First wait till it's off cooldown
while Self.GetSpellCooldown(spell) > 0 do
wait(100)
end
-- Then try casting it till its on cooldown
while Self.GetSpellCooldown(spell) < 200 do
-- Only wait if we fail to cast it
local _ = Self.Cast(spell, mana) == 0 or wait(100)
end
end

local standtime = 0
local lastpos = Self.Position()
local lasttrigger = os.time()
Module("Update standtime", function(self)
local pos = Self.Position()
if pos.x == lastpos.x and pos.y == lastpos.y and pos.z == lastpos.z then
standtime = standtime + (os.time() - lasttrigger)
else
standtime = 0
end
self:Delay(1000)
end)

local monsters = preprocessMonsters(MonsterNames)
local count = Count
local maxStandtime = MaxStandtime

Module("Logout When Lured", function(self)
if monsterCount(monsters) >= count or (not Self.isInPz() and standtime > maxStandtime) then
ensuredCast("utamo vita", 50)
-- Not sure if this wait is needed. I don't understand enough about the life of a packet.
wait(1000)
os.exit()
end
self:Delay(500)
end)

Mageq
08-26-2016, 08:46 AM
works perfectly man, thanks shadowart you could add this to your lua script :)

edit - any chance you could also write a script which exits after a stand time of 60 seconds?

<3

shadowart
08-26-2016, 09:25 AM
works perfectly man, thanks shadowart you could add this to your lua script :)

edit - any chance you could also write a script which exits after a stand time of 60 seconds?

<3
Updated the previous script. The stand time condition will not trigger inside a pz zone.

Mageq
09-01-2016, 11:21 AM
Updated the previous script. The stand time condition will not trigger inside a pz zone.

Monster count and exit works fine, however the exit after 60 seconds does not work, I've tested it in multiple ways such as:

Standing in pz - leaving pz = will exit, even though I moved a second ago, but I was standing in PZ for 60+ seconds.
AFK for 3+ minutes outside of PZ = nothing

shadowart
09-01-2016, 11:43 AM
lasttrigger isn't getting updated. It should be updated to the current value of os.time() on each invocation of the module.