WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Simple tracking scrips (https://www.wowinterface.com/forums/showthread.php?t=57940)

Kurtain 04-16-20 03:06 AM

Simple tracking scrips
 
Im making an automatic tracker for an alt with both herbalism and mining! This is my first WoW addon, and got no experience with LUA or wow API before this.

In my LUA code ive got a a function that repeats every 4 seconds, which work perfectly until i login in a rested zone (inn or capital).

this is the function:
Code:

local function tracking()
    if UnitIsEnemy("player","target") then
    else
        if IsResting() then
        else
            if i == 0 then
                CastSpellByID(2580);
                i = i + 1;
            elseif i == 1 then
                CastSpellByID(2383);
                i = i - 1;
            end
        end
    end
end

As you can see Ive made it so if im targeting a hostile monster it shouldnt loop, so i dont get GCDs when Im fighting, ive also added so i dont use it while getting rested, to not screw with me while doing stuff in capitals.

the way I run the function is:

Code:

if IsSpellKnown(2580) and IsSpellKnown(2383) then
    C_Timer.NewTicker(4, tracking)
end

This works if I login out in the wilds, when entring an inn It will not do any new tracking, and when exiting it will continue the trackingloop.
When I login into the same inn the tracking will not change after leaving the inn and do a /reload

Are there any obvious things Ive missed?

Seerah 04-16-20 11:48 AM

Where's the rest of your code?

Kurtain 04-17-20 07:52 AM

Other than my .toc file there are nothing else, except a decleration of i, in the global scope.

Fizzlemizz 04-17-20 09:02 AM

The global space is shared by the entire Blizzard UI and all the 3rd party addons you have installed. Naming a global variable "i" is not a great idea as it's too easy for it to be "trampled" by someone missing a "local" declaration by accident.

Code:

local Mining, Herbing = 2580, 2383
local FindHerbs
local function tracking()
        if not UnitIsEnemy("player","target") and not IsResting() then
                FindHerbs = not FindHerbs
                if FindHerbs then
                        CastSpellByID(Herbing)
                else
                        CastSpellByID(Mining)
                end
        end
end


Kurtain 04-17-20 03:24 PM

ok, i probably misspoke; i declared i as:
Code:

local var i = 0;
I will however try your code and see if that would work tomorrow! thanks! :)

Seerah 04-18-20 11:46 AM

Do you mean this? What you put above is not proper syntax.
Lua Code:
  1. local i = 0


All times are GMT -6. The time now is 03:39 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI