Jump to content


Photo

How to release and re-summon a trust?


    3 replies to this topic

    #1 midareashi

    midareashi

      Newbie

    • Members
    • Pip
    • 2 posts

      Posted 20 November 2015 - 04:54 PM

      This is just my first day writing addons so I know my code can use a lot of cleanup. Right now I'm checking for trust's current mp, then I want to release and re-summon them if their mp is below a certain threshold (90% just for testing). I'm getting them to release, but it won't re-summon them. Any idea what's wrong?

       

      _addon.command = 'fedex'
      
      windower.register_event('addon command',function()
      	local party = windower.ffxi.get_party()
      	if party.p4 ~= nil then
      		local mpp	= party.p4.mpp
      		local name	= party.p4.name
      		if mpp ~= 0 and mpp < 90 then
      			windower.send_command('input /refa '..name..';wait 1;/ma '..name..' <me>')
      		end
      	end
      	if party.p3 ~= nil then
      		local mpp	= party.p3.mpp
      		local name	= party.p3.name
      		if mpp ~= 0 and mpp < 90 then
      			windower.send_command('input /refa '..name..';wait 1;/ma '..name..' <me>')
      		end
      	end
      end)
      
      

       



      #2 midareashi

      midareashi

        Newbie

      • Members
      • Pip
      • 2 posts

        Posted 20 November 2015 - 05:08 PM

        Also, how do I get the first if statement to wait to finish before the second one runs? Right now if both trusts have low mp only 1 will release for each time I run the command.



        #3 Iryoku

        Iryoku

          Advanced Member

        • Windower Staff
        • 488 posts

          Posted 21 November 2015 - 04:54 AM

          There are a few ways to do this, but the simplest is probably something like this:

          local party = windower.ffxi.get_party()
          if party.p4 ~= nil then
              local mpp = party.p4.mpp
              local name = party.p4.name
              if mpp ~= 0 and mpp < 90 then
                  windower.send_command('input /refa ' .. name)
                  coroutine.sleep(1)
                  windower.send_command('input /ma ' .. name .. ' <me>')
                  coroutine.sleep(3.5) -- may need to adjust this delay
              end
          end
          if party.p3 ~= nil then
              local mpp = party.p3.mpp
              local name = party.p3.name
              if mpp ~= 0 and mpp < 90 then
                  windower.send_command('input /refa ' .. name)
                  coroutine.sleep(1)
                  windower.send_command('input /ma ' .. name .. ' <me>')
                  coroutine.sleep(3.5) -- ditto
              end
          end
          

          Note that this will fail if p3 or p4 are not trusts. A more robust solution is something like this:

          local party = windower.ffxi.get_party()
          local first = true
          for i = 1, 5 do
              local member = party['p' .. i]
              if member and member.mob and member.mob.is_npc and member.mp ~= 0 and member.mpp < 90 then
                  if not first then
                      coroutine.sleep(3.5) -- may need to adjust this delay
                  end
                  first = true
                  windower.send_command('input /refa ' .. member.name)
                  coroutine.sleep(1)
                  windower.send_command('input /ma ' .. member.name .. ' <me>')
              end
          end
          

          Improving on this further would likely require using packets to detect when casting finishes.



          #4 Arcon

          Arcon

            Advanced Member

          • Windower Staff
          • 1189 posts
          • LocationMunich, Germany

          Posted 21 November 2015 - 09:22 AM

          Can also use windower.chat.input instead of windower.send_command. The former is used for entering FFXI commands, the second is used for entering Windower commands. Since you're sending FFXI commands, the first is more appropriate. It won't make much of a difference, it just makes your intent clearer, which makes the code easier to read.






          1 user(s) are reading this topic

          0 members, 1 guests, 0 anonymous users