View difference between Paste ID: h60R9LjB and U4ftG7LB
SHOW: | | - or go back to the newest paste.
1
timeit = require 'timeit'
2
3
windower.register_event('addon command',function (...)
4
    command = table.concat({...},' ')
5
    if command:lower() == 'test' then
6
        if testmode then
7
            testmode = false
8
            table.sort(timearray)
9
            local basetime = 25
10
            windower.add_to_chat(8,'------ Delays ------')
11
            for i,v in ipairs(timearray) do
12
                windower.add_to_chat(8,tostring(v))
13
                if v < basetime then
14
                    basetime = v
15
                end
16
            end
17
            windower.add_to_chat(121,'TP Delay should be set to about: '..basetime-0.4) -- 0.3 seconds longer than necessary.
18
        else
19
            testmode = true
20
            timearray = {}
21
            windower.add_to_chat(121,'Start shooting as fast as you possibly can.\7 Really try to spam the shit out of it.')
22
        end
23
    end
24
end)
25
26
windower.register_event('load',function ()
27
--- You edit this ---
28
    pause_for_ws = false
29
    TPdelay = 0.35
30
    preshot_script = 'preshot.txt'
31
    midshot_script = 'midshot.txt'
32
    aftershot_script = 'aftershot.txt'
33
    
34
    
35
--- Don't edit this ---
36
    testmode = false
37
    failurelimit = 3
38
    
39
    autoshot = false
40
    failurecount = 0
41
    radelay = 0.7
42
    wsdelay = 1.7
43
    Cancel_delay = 1
44
    windower.send_command('bind ^d lua i makeshot startshooting')
45
    windower.send_command('alias ms lua c makeshot')
46
end)
47
48
windower.register_event('unload', function ()
49
    windower.send_command('unalias ms')
50
    windower.send_command('unbind ^d')
51
end)
52
53
windower.register_event('action',function (act)
54
    local player = windower.ffxi.get_player()
55
    if player['id'] ~= act['actor_id'] then return end
56
    
57
    if act['category'] == 12 and act['param'] == 24931 then
58
--        windower.add_to_chat(121,'Aiming a ranged attack!')
59
        if windower.file_exists(windower.windower_path .. 'scripts/'..midshot_script) then
60
            windower.send_command('exec '..midshot_script)
61
        end
62
        if testmode and ttime then
63
            timearray[#timearray+1] = ttime:stop()
64
        end
65
    elseif act['category'] == 12 and act['param'] == 28787 then
66
        if autoshot then
67
            failurecount = failurecount +1
68
            if failurecount >= 3 then
69
                autoshot = false
70
                failurecount = 0
71
                windower.add_to_chat(5,'3 Shot failures. Autoshot Canceled. Control D to restart')
72
            else
73
                windower.send_command('wait '..Cancel_delay..';lua i makeshot checktp')
74
            end
75
        end
76
        if windower.file_exists(windower.windower_path .. 'scripts/'..aftershot_script) then
77
            windower.send_command('exec '..aftershot_script)
78
        end
79
    elseif act['category'] == 2 then -- Shot Landing
80
        failurecount = 0
81
        if autoshot then
82
            windower.send_command('wait '..TPdelay..';lua i makeshot checktp')
83
        end
84
        if testmode then
85
            ttime = timeit.new()
86
            ttime:start()
87
        end
88
        if windower.file_exists(windower.windower_path .. 'scripts/'..aftershot_script) then
89
            windower.send_command('exec '..aftershot_script)
90
        end
91
    elseif act['category'] == 3 and pause_for_ws then -- WS Landing
92
        if autoshot then
93
            windower.add_to_chat(121,'Autoshot resumed!')
94
            windower.send_command('wait '..(wsdelay+TPdelay)..';lua i makeshot checktp')
95
        end
96
    end
97
end)
98
99
function startshooting()
100
    if autoshot or not windower.ffxi.get_mob_by_target('<t>') then
101
        autoshot = false
102
    else
103
        autoshot = true
104
        if windower.file_exists(windower.windower_path .. 'scripts/'..preshot_script) then
105
            windower.send_command('exec '..preshot_script)
106
        end
107
        windower.send_command('wait '..radelay..';input /ra <t>;')
108
    end
109
end
110
111
function checktp()
112
    local player = windower.ffxi.get_player()
113
    if (player.vitals.tp < 100 and autoshot) or (not pause_for_ws and autoshot) then
114
        if windower.file_exists(windower.windower_path .. 'scripts/'..preshot_script) then
115
            windower.send_command('exec '..preshot_script)
116
        end
117
        windower.send_command('wait '..radelay..';input /ra <t>')
118
    elseif player.vitals.tp >= 100 and autoshot and pause_for_ws then
119
        windower.add_to_chat(121,'Autoshot canceled, WS away!')
120
    end
121
end
122
123
windower.register_event('action message',function (actor_id,target_id,actor_index,target_index,message_id,param_1,param_2,param_3)
124
    if message_id == 94 then
125
        if autoshot then
126
            failurecount = failurecount +1
127
            if failurecount >= 3 then
128
                autoshot = false
129
                failurecount = 0
130
                windower.add_to_chat(5,j..'3 Shot failures. Autoshot Canceled. Control D to restart')
131
            else
132
                windower.send_command('wait '..Cancel_delay..';input /ra <t>;')
133
--                windower.send_command('wait '..Cancel_delay..';lua i makeshot checktp')
134
            end
135
        end
136
        if windower.file_exists(windower.windower_path .. 'scripts/'..aftershot_script) then
137
            windower.send_command('exec '..aftershot_script)
138
        end
139
    elseif message_id == 216 then
140
        send_command('@input /equip ammo "Dart" <me>;wait 1;input /ra <t>;')
141
    end
142
end)