forked from Ascerr/Lua-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttack Monster with most HP.lua
More file actions
108 lines (86 loc) · 3.5 KB
/
Attack Monster with most HP.lua
File metadata and controls
108 lines (86 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--[[
Script Name: Attack Monster with most HP
Description: Switch target to monster with most hp.
Author: Ascer - example
]]
local TARGET_LIST = {"Snake", "Rat"} -- list of all possible monsters to switch attack with Capital letter.
local RANGE = 1 -- max distance to search creatures.
local COUNT = 3 -- minimal monsters count to active.
local HP_TYPE = 0 -- type of identify creatures 0 - the highest percent, 1 - the lowest percent
-- DON'T EDIT BELOW THIS LINE
-- convert list o lower case
TARGET_LIST = table.lower(TARGET_LIST)
----------------------------------------------------------------------------------------------------------------------------------------------------------
--> Function: getCreatureWithHighestHp(list, range)
--> Description: Get table with creature of most hpperc to attack.
--> Params:
--> @list table with creature names
--> @range number max distance between you and creature
--> Return: #1 table with monster info or -1 if not found. #2 count of monsters
----------------------------------------------------------------------------------------------------------------------------------------------------------
function getCreatureWithHighestHp(list, range)
local creatures = Creature.iMonsters(range, false)
local lastHpperc, c, count = -1, -1, 0
for i = 1, #creatures do
local creature = creatures[i]
if table.find(list, string.lower(creature.name)) then
if creature.hpperc > lastHpperc then
c = creature
lastHpperc = creature.hpperc
end
count = count + 1
end
end
return c, count
end
----------------------------------------------------------------------------------------------------------------------------------------------------------
--> Function: getCreatureWithLowestHp(list, range)
--> Description: Get table with creature of lowest hpperc to attack.
--> Params:
--> @list table with creature names
--> @range number max distance between you and creature
--> Return: #1 table with monster info or -1 if not found. #2 count of monsters
----------------------------------------------------------------------------------------------------------------------------------------------------------
function getCreatureWithLowestHp(list, range)
local creatures = Creature.iMonsters(range, false)
local lastHpperc, c, count = 101, -1, 0
for i = 1, #creatures do
local creature = creatures[i]
if table.find(list, string.lower(creature.name)) then
if creature.hpperc < lastHpperc then
c = creature
lastHpperc = creature.hpperc
end
count = count + 1
end
end
return c, count
end
-- module to run function
Module.New("Attack Monster with most HP", function (mod)
-- when we are connected
if Self.isConnected() then
-- set param
local mob, amount
-- depent on HP_TYPE read creature with lowest or highest hpperc
if HP_TYPE == 0 then
-- load current creature.
mob, amount = getCreatureWithHighestHp(TARGET_LIST, RANGE)
else
-- load current creature.
mob, amount = getCreatureWithLowestHp(TARGET_LIST, RANGE)
end
-- when mob is different than -1
if table.count(mob) > 1 and amount >= COUNT then
-- when current target is different then creature.
if Self.TargetID() ~= mob.id then
-- attack creature.
Creature.Attack(mob.id)
-- wait some time.
wait(200, 500)
end
end
end
-- module execution delay.
mod:Delay(200, 500)
end)