Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Am I on the right track?
#1
For just getting to know the API I made a simple button for my summoner to keep dots up when I am feeling lazy.

One problem I found was it wanting to cast miama over and over because it doesn't seen the debuff on the mob before the next cast.

My solution is to track the last spell I was casting and not to cast the same spell again if I was casting it recently.

Any advice in my general API usage before I move on to bigger things?

Code:
-- Create a new table for our code:
mymodule= { }
-- Some local variables we use in our module:
mymodule.running = true
mymodule.lastticks = 0
mymodule.lastchannelid = 0
mymodule.lastchanneltargetid = 0
mymodule.lastchannelticks = 0

-- Initializing function, we create a new Window for our module that has 1 button and 1 field to display data:
function mymodule.ModuleInit()
    GUI_NewWindow("MyNewWindow",50,50,100,50);
    GUI_NewButton("MyNewWindow","Toggle","MYMODULE.TOGGLE");
end

-- The function that gets called when the button is pressed:
function mymodule.ToggleRun()
    mymodule.running = not mymodule.running
end

-- The Mainloop function, gets called all the time by FFXIVMinion:
function mymodule.OnUpdateHandler( Event, ticks )
    if ( mymodule.running and ticks - mymodule.lastticks > 200 ) then
        mymodule.lastticks = ticks
        
        --Track last thing it saw me doing and when.
        if (Player.castinginfo and Player.castinginfo.channelingid ~=0 ) then
            mymodule.lastchannelid = Player.castinginfo.channelingid
            mymodule.lastchanneltargetid = Player.castinginfo.channeltargetid
            mymodule.lastchannelticks = ticks
        end
        
        --See if I need aetherflow and do it
        local afbuff = false
        if ( Player.buffs ) then
            for i, buff in pairs(Player.buffs) do
                if (buff.id ==  304) then
                    afbuff = true
                end
            end
        end        
        if (not afbuff) then
            local afspell = ActionList:Get(166)
            if (afspell.isready) then
                afspell:Cast()
            end
        end
        
        
        if ( MeshManager:IsKeyPressed(4)) then
            local target = Player:GetTarget()

            local ruin = ActionList:Get(163)
            local bio = ActionList:Get(164)
            local miasma = ActionList:Get(168)
            local bio2 = ActionList:Get(178)

            local bioduration = 0
            local miasmaduration = 0
            local bio2duration = 0
            
            --todo, make this account for spell speed
            local gcd = ruin.casttime
            
            -- Scan buffs on target and their remaining duration
            for i, buff in pairs(target.buffs) do
                if (buff and buff.id == 179 and buff.ownerid == Player.id) then
                   bioduration = buff.duration
                end
                if (buff and buff.id == 180 and buff.ownerid == Player.id) then
                   miasmaduration = buff.duration
                end
                if (buff and buff.id == 189 and buff.ownerid == Player.id) then
                   bio2duration = buff.duration
                end
            end
            
            --Don't use this if I was seen channeling this attack in the last second on the same target
            if (miasma.isready and (miasmaduration < (gcd + miasma.casttime)) and not
                ( mymodule.lastchannelid == 168 and mymodule.lastchanneltargetid == target.id and (ticks - mymodule.lastchannelticks) < 1000)) then
                miasma:Cast(target.id)
                return
            end
            
            d(tostring(bio2duration).. " < ".. tostring(gcd).. " + ".. bio2.casttime)
            if (bio2.isready and (bio2duration < (gcd + bio2.casttime)) and not
                ( mymodule.lastchannelid == 178 and mymodule.lastchanneltargetid == target.id and (ticks - mymodule.lastchannelticks) < 1000)) then
                bio2:Cast(target.id)
                return
            end
            
            if (bio.isready and bioduration < gcd) then
                bio:Cast(target.id)
                return
            end
            
            if (ruin.isready) then
                ruin:Cast(target.id)
                return
            end
        end
    end        
end

-- Registering the Events
RegisterEventHandler("Gameloop.Update",mymodule.OnUpdateHandler) -- the normal pulse from the gameloop
RegisterEventHandler("MYMODULE.TOGGLE", mymodule.ToggleRun) -- the function that gets called when our button is pressed
RegisterEventHandler("Module.Initalize",mymodule.ModuleInit) -- the initialization function, gets called only once at startup of the game
Reply
#2
Do ticks behave well when the program bogs down? Or at least well enough for me to measure significant periods of time?

I assume you're using the same value the game engine is using for its main loop.
Reply
 


Forum Jump:


Users browsing this thread: 6 Guest(s)

We help you win the game.

FFXIV Bot and More.

 

Products