Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'actions'
- require 'socket'
- --inspect = require 'inspect'
- autoshot = 0
- ranged_hit_struct = {
- hit = true,
- crit = false,
- start_time = 0,
- end_time = 0,
- diff_time = 0,
- ammo_delay = 240,
- weapon_delay = 582,
- rapidshot = 0,
- snapshot = 15,
- weapon_type = 'Annihilator',
- job = 'rng/war',
- damage = 0,
- charname = '',
- mob = '',
- flurry = true,
- flurry2 = false,
- }
- ranged_rows = {}
- counter = 1
- function log_hit(ranged)
- local ouf = assert(io.open("D:/Program Files (x86)/Windower4/testsuite_data.sql", "a"))
- str = "insert into ranged_log(id,hit,crit,start_time,end_time,diff_time,ammo_delay,weapon_delay,rapidshot,snapshot,weapon_type,job,damage,charname,mob,flurry,flurry2) values (null,"..
- tostring(ranged.hit)..","..tostring(ranged.crit)..","..ranged.start_time..","..ranged.end_time..","..ranged.diff_time..","..ranged.ammo_delay..","..ranged.weapon_delay..","..ranged.rapidshot..","..
- ranged.snapshot..",'"..ranged.weapon_type.."','"..ranged.job.."',"..ranged.damage..",'"..ranged.charname.."','"..ranged.mob.."',"..tostring(ranged.flurry)..","..tostring(ranged.flurry2)..
- ");"
- print(ranged.diff_time)
- if ouf then
- ouf:write(tostring(str))
- ouf:write("\n")
- io.close(ouf)
- --print('wrote to file')
- else
- --print('could not open file to write')
- end
- end
- function table.shallow_copy(t)
- local t2 = {}
- for k,v in pairs(t) do
- t2[k] = v
- end
- return t2
- end
- ranged_hit = table.shallow_copy(ranged_hit_struct)
- function log_data_structure(data_object)
- str = inspect(data_object)
- local ouf = assert(io.open("D:/Program Files (x86)/Windower4/file_log.txt", "a"))
- if ouf then
- ouf:write(tostring(str))
- ouf:write("\n")
- io.close(ouf)
- --print('wrote to file')
- else
- --print('could not open file to write')
- end
- end
- function find_pet_owner_name(actionpacket)
- local pet = windower.ffxi.get_mob_by_id(actionpacket:get_id())
- local party = windower.ffxi.get_party()
- local name = nil
- for _, member in pairs(party) do
- if type(member) == 'table' and member.mob then
- if member.mob.pet_index and member.mob.pet_index> 0 and pet.index == member.mob.pet_index then
- name = member.mob.name
- break
- end
- end
- end
- return name
- end
- r_start = 0
- function event_action(raw_actionpacket)
- local actionpacket = ActionPacket.new(raw_actionpacket)
- actionstr = actionpacket:get_category_string()
- if actionstr == 'ranged_begin' then
- for target in actionpacket:get_targets() do
- for subactionpacket in target:get_actions() do
- --log_data_structure(subactionpacket)
- r_start = socket.gettime()*1000
- end
- end
- end
- if actionstr == 'ranged_finish' then
- for target in actionpacket:get_targets() do
- for subactionpacket in target:get_actions() do
- if (mob_is_ally(actionpacket.raw.actor_id) and not mob_is_ally(target.raw.id)) then
- --log_data_structure(subactionpacket)
- ranged_hit = table.shallow_copy(ranged_hit_struct)
- ranged_hit.start_time = r_start
- ranged_hit.end_time = socket.gettime()*1000
- ranged_hit.diff_time = ranged_hit.end_time - ranged_hit.start_time
- ranged_hit.charname = actionpacket:get_actor_name()
- ranged_hit.mob = target:get_name()
- if subactionpacket.message_id == 353 then
- ranged_hit.crit = true
- ranged_hit.damage = subactionpacket.param
- elseif T{157, 352, 576, 577}:contains(subactionpacket.message_id) then
- ranged_hit.damage = subactionpacket.param
- elseif subactionpacket.message_id == 354 then
- ranged_hit.hit = false
- end
- --log_data_structure(ranged_hit)
- log_hit(ranged_hit)
- end
- end
- end
- end
- -- print out all melee hits to the console
- -- if actionstr == 'ranged_begin' then
- -- for target in actionpacket:get_targets() do -- target iterator
- -- for action in target:get_actions() do -- subaction iterator
- -- if action.message == 1 then -- 1 is the code for messages
- -- print(string.format("%s hit %s for %d damage",
- -- actionpacket:get_actor_name(), target:get_name(), action.param))
- -- end
- -- end
- -- end
- -- end
- -- if actionstr == 'ranged_finish' then
- -- for target in actionpacket:get_targets() do -- target iterator
- -- for action in target:get_actions() do -- subaction iterator
- -- log_data_structure(action)
- -- if action.message == 1 then -- 1 is the code for messages
- -- print(string.format("%s hit %s for %d damage",
- -- actionpacket:get_actor_name(), target:get_name(), action.param))
- -- end
- -- end
- -- end
- -- end
- end
- function recorder(raw_actionpacket)
- local actionpacket = ActionPacket.new(raw_actionpacket)
- local category = actionpacket:get_category_string()
- local player = windower.ffxi.get_player()
- if player ~= nil then
- local player_mob = windower.ffxi.get_mob_by_id(player.id)
- end
- if not player or not (windower.ffxi.get_player().in_combat) then
- print('no player found, exiting')
- return
- end
- for target in actionpacket:get_targets() do
- for subactionpacket in target:get_actions() do
- if (mob_is_ally(actionpacket.raw.actor_id) and not mob_is_ally(target.raw.id)) then
- local main = subactionpacket:get_basic_info()
- ranged_hit.end_time = os.time()
- if T{157, 352, 576, 577}:contains(main.message_id) then
- dps_db:add_r_hit(target:get_name(), create_mob_name(actionpacket), main.param)
- elseif main.message_id == 353 then
- dps_db:add_r_crit(target:get_name(), create_mob_name(actionpacket), main.param)
- elseif main.message_id == 354 then
- dps_db:incr_r_misses(target:get_name(), create_mob_name(actionpacket))
- end
- counter = counter + 1
- end
- end
- end
- end
- --ActionPacket.open_listener(recorder)
- ActionPacket.open_listener(event_action)
- function record_shot()
- start_time = os.time()
- ranged_hit = table.shallow_copy(ranged_hit_struct)
- ranged_hit.start_time = start_time
- windower.send_command('input /ra <t>')
- end
- -- Returns all mob IDs for anyone in your alliance, including their pets.
- function get_ally_mob_ids()
- local allies = T{}
- local party = windower.ffxi.get_party()
- for _, member in pairs(party) do
- if type(member) == 'table' and member.mob then
- allies:append(member.mob.id)
- if member.mob.pet_index and member.mob.pet_index> 0 and windower.ffxi.get_mob_by_index(member.mob.pet_index) then
- allies:append(windower.ffxi.get_mob_by_index(member.mob.pet_index).id)
- end
- end
- end
- if settings.showfellow then
- local fellow = windower.ffxi.get_mob_by_target("ft")
- if fellow ~= nil then
- allies:append(fellow.id)
- end
- end
- return allies
- end
- -- Returns all mob IDs for anyone in your alliance, including their pets.
- function get_ally_mob_ids()
- local allies = T{}
- local party = windower.ffxi.get_party()
- for _, member in pairs(party) do
- if type(member) == 'table' and member.mob then
- allies:append(member.mob.id)
- if member.mob.pet_index and member.mob.pet_index> 0 and windower.ffxi.get_mob_by_index(member.mob.pet_index) then
- allies:append(windower.ffxi.get_mob_by_index(member.mob.pet_index).id)
- end
- end
- end
- return allies
- end
- -- Returns true if is someone (or a pet of someone) in your alliance.
- function mob_is_ally(mob_id)
- -- get zone-local ids of all allies and their pets
- return get_ally_mob_ids():contains(mob_id)
- end
- --function Player:add_r_hit(damage)
- -- -- increment hits
- -- self.r_hits = self.r_hits + 1
- --
- -- -- update min/max/avg melee values
- -- self.r_min = math.min(self.r_min, damage)
- -- self.r_max = math.max(self.r_max, damage)
- -- self.r_avg = self.r_avg * (self.r_hits - 1)/self.r_hits + damage/self.r_hits
- --
- -- -- accumulate damage
- -- self.damage = self.damage + damage
- --end
- --
- --
- --function Player:add_r_crit(damage)
- -- -- increment crits
- -- self.r_crits = self.r_crits + 1
- --
- -- -- update min/max/avg melee values
- -- self.r_crit_min = math.min(self.r_crit_min, damage)
- -- self.r_crit_max = math.max(self.r_crit_max, damage)
- -- self.r_crit_avg = self.r_crit_avg * (self.r_crits - 1)/self.r_crits + damage/self.r_crits
- --
- -- -- accumulate damage
- -- self.damage = self.damage + damage
- --end
- --
- --
- --function Player:incr_r_misses() self.r_misses = self.r_misses + 1 end
- reg = {}
- --windower.register_event('incoming chunk',function(id,original,modified,is_injected,is_blocked)
- -- if id == 0x01A then
- -- local packet = packets.parse('incoming', data)
- -- log_data_structure(packet)
- -- end
- --end)
- packets = require('packets')
- windower.register_event('outgoing chunk',function(id,data)
- if id == 0x01A then
- --if id ~= 0x015 then
- local packet = packets.parse('outgoing', data)
- --log_data_structure(packet)
- end
- -- if id == 0x0B6 then
- -- local packet = packets.parse('outgoing', data)
- -- print(packet['Target Name'], packet['Message'])
- -- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement