-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoTarget.lua
More file actions
70 lines (58 loc) · 1.95 KB
/
Copy pathAutoTarget.lua
File metadata and controls
70 lines (58 loc) · 1.95 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
-- This is an addon for Ashita v4 that disables autotarget on zonechange
-- Define addon information
addon.name = 'AutoTarget'
addon.author = 'Zaldas'
addon.version = '0.1'
addon.desc = 'Control AutoTarget on zone change'
addon.link = 'https://github.com/Zaldas/AutoTarget'
-- Import necessary modules and libraries
require('common') -- Import a common utility module
local chat = require("chat")
local settings = require('settings') -- Module for managing settings
-- AutoTarget settings and cache
local defaultSettings = T{
value = 'on',
};
local cache = {
settings = nil;
};
-- Register events to load and unload the addon
ashita.events.register('load', 'autotaget_load', function()
cache.settings = settings.load(defaultSettings) -- Load settings with default values
settings.register('settings', 'settings_update', function(s)
if (s ~= nil) then
cache.settings = s
end
end)
end)
ashita.events.register('unload', 'autotarget_unload', function()
end)
local function RunCommand()
AshitaCore:GetChatManager():QueueCommand(-1, '/autotarget ' .. cache.settings.value);
end
-- Register a packet_in event to handle zone change information
ashita.events.register('packet_in', 'autotarget_packet_in', function(event)
if event.id == 0x0A then -- Check if it's a zone change packet
coroutine.sleep(1);
RunCommand();
end
end)
ashita.events.register('command', 'autotarget_command', function (e)
-- Parse the command arguments..
local args = e.command:args()
if (#args == 0 or args[1] ~= '/at') then
return
end
-- Block all AutoTarget related commands..
e.blocked = true
if (#args == 1 and args[1] == '/at') then
print(chat.header(addon.name):append('Usage: /at [on/off]'));
return
end
if (#args == 2 and args[2]:any('on', 'off')) then
cache.settings.value = args[2];
settings.save();
RunCommand();
return;
end
end)