What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

How to get the remaining cast time of a CHANNELED spell?

fpsware

Community Developer
Joined
Jan 15, 2010
Messages
5,287
Reaction score
133
I'm trying to get the remaining cast time in milliseconds of a channeled spell. I can do this for a CAST spell but not a CHANNELED spell.

Eg... if Mind Flay has a total channeled time for 2000ms, and its been channeling for 1500ms I want to see there is only 500ms remaining.
 
This does not work for channeled spells, it always returns 0. For cast spells it correctly returns the cast time remaining.

I believe you can determine that from using this: UnitChannelInfo - World of Warcraft Programming: A Guide and Reference for Creating WoW Addons

Quickly Thrown Together, should work?
Code:
        public static TimeSpan GetChannelTimeLeft()
        {
            var retVal = new TimeSpan();
            using (new FrameLock())
            {
                if (StyxWoW.Me.IsCasting)
                {
                    var channelEndTime = Lua.GetReturnValues("return UnitChannelInfo(\"player\"").ElementAt(5))
                    ;
                    if (channelEndTime != null && Convert.ToInt32(channelEndTime) != 0)
                    {
                        var currentTime = Lua.GetReturnVal<int>("return GetTime();", 0)*1000;
                        var timeLeft = Convert.ToInt32(channelEndTime) - currentTime;
                        retVal = new TimeSpan(0, 0, 0, 0, timeLeft);
                    }
                }
            }
            return retVal;
        }
 
Last edited:
the information you need is already there in the api, StartTime EndTime i mean he COULD do some math and figure it out, but i think the api is a bit broken, it shouldnt always be returning 0
 
the information you need is already there in the api, StartTime EndTime i mean he COULD do some math and figure it out, but i think the api is a bit broken, it shouldnt always be returning 0

Is Start/End Time is consistent through both a basic Cast and Channeled spell, is the question?
 
Is Start/End Time is consistent through both a basic Cast and Channeled spell, is the question?
if its instant cast, like most spells are, then it should have the same start and end date, if its a channeled spell like drain life there should be a diffrence there
 
I believe you can determine that from using this: UnitChannelInfo - World of Warcraft Programming: A Guide and Reference for Creating WoW Addons

Quickly Thrown Together, should work?
Code:
        public static TimeSpan GetChannelTimeLeft()
        {
            var retVal = new TimeSpan();
            using (new FrameLock())
            {
                if (StyxWoW.Me.IsCasting)
                {
                    var channelEndTime = Lua.GetReturnValues("return UnitChannelInfo(\"player\"").ElementAt(5))
                    ;
                    if (channelEndTime != null && Convert.ToInt32(channelEndTime) != 0)
                    {
                        var currentTime = Lua.GetReturnVal<int>("return GetTime();", 0)*1000;
                        var timeLeft = Convert.ToInt32(channelEndTime) - currentTime;
                        retVal = new TimeSpan(0, 0, 0, 0, timeLeft);
                    }
                }
            }
            return retVal;
        }


Thanks so much for this, its greatly appreciated.

This is what I have.....

Code:
public static TimeSpan GetChannelTimeLeft()
        {
            var retVal = new TimeSpan();
            using (new FrameLock())
            {
                if (StyxWoW.Me.IsCasting)
                {
                    var channelEndTime = Lua.GetReturnValues("return UnitChannelInfo(\"player\"","lua.lua").ElementAt(5);
                    if (channelEndTime != null && Convert.ToInt32(channelEndTime) != 0)
                    {
                        var currentTime = Lua.GetReturnVal<int>("return GetTime();", 0)*1000;
                        var timeLeft = Convert.ToInt32(channelEndTime) - currentTime;
                        retVal = new TimeSpan(0, 0, 0, 0, timeLeft);
                    }
                }
            }
            return retVal;
        }


This is the error...

Code:
[4:29:28 a.m.:100] System.ArgumentNullException: Value cannot be null.
Parameter name: source   at System.Linq.Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index)  at FpswareCC.FSRE.GetChannelTimeLeft() in c:\HB\CustomClasses\Fpsware Template\Class Specific\Logic\FSRE.cs:line 132

Line 132 puts the error in this line:
var channelEndTime = Lua.GetReturnValues("return UnitChannelInfo(\"player\"","lua.lua").ElementAt(5);

</int>
 
(\"player\"","lua.lua") -- Notice Anything?

I corrected this, and added some sanity:
Code:
        public static TimeSpan GetChannelTimeLeft()
        {
            var retVal = new TimeSpan();
            using (new FrameLock())
            {
                if (StyxWoW.Me.IsCasting)
                {
                    var channelInfo = Lua.GetReturnValues("return UnitChannelInfo(\"player\");");
                    if (channelInfo.Count > 1)
                    {
                        var channelEndTime = channelInfo[5];
                        if (channelEndTime != null && Convert.ToInt32(channelEndTime) != 0)
                        {
                            var currentTime = Lua.GetReturnVal<int>("return GetTime();", 0)*1000;
                            var timeLeft = Convert.ToInt32(channelEndTime) - currentTime;
                            retVal = new TimeSpan(0, 0, 0, 0, timeLeft);
                        }
                    }
                }
            }
            return retVal;
        }
 
Thanks, now that is going to be extremely hand in the future!

Again, thanks very much!
 
(\"player\"","lua.lua") -- Notice Anything?

I corrected this, and added some sanity:
Code:
        public static TimeSpan GetChannelTimeLeft()
        {
            var retVal = new TimeSpan();
            using (new FrameLock())
            {
                if (StyxWoW.Me.IsCasting)
                {
                    var channelInfo = Lua.GetReturnValues("return UnitChannelInfo(\"player\");");
                    if (channelInfo.Count > 1)
                    {
                        var channelEndTime = channelInfo[5];
                        if (channelEndTime != null && Convert.ToInt32(channelEndTime) != 0)
                        {
                            var currentTime = Lua.GetReturnVal<int>("return GetTime();", 0)*1000;
                            var timeLeft = Convert.ToInt32(channelEndTime) - currentTime;
                            retVal = new TimeSpan(0, 0, 0, 0, timeLeft);
                        }
                    }
                }
            }
            return retVal;
        }


Its still returning an error :)

[9:39:45 a.m.:965] System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index)
at FpswareCC.Library.Spells.GetChannelTimeLeft() in c:\HB\CustomClasses\Fpsware Template\Library\FLib.cs:line 378


At line...
var channelInfo = Lua.GetReturnValues("return UnitChannelInfo(\"player\");");

</int>
 
Copy this entire function, and overwrite yours, you still were missing the type for GetReturnVal later in the code too. Try this, not sure why it is null.
Code:
        public static TimeSpan GetChannelTimeLeft()
        {
            var retVal = new TimeSpan();
            using (new FrameLock())
            {
                if (StyxWoW.Me.IsCasting)
                {
                    List<string> channelInfo = Lua.GetReturnValues("return UnitChannelInfo(\"player\");");
                    if (channelInfo != null && channelInfo.Count > 1)
                    {
                        var channelEndTime = channelInfo[5];
                        if (channelEndTime != null && Convert.ToInt32(channelEndTime) != 0)
                        {
                            var currentTime = Lua.GetReturnVal<int>("return GetTime();", 0) * 1000;
                            var timeLeft = Convert.ToInt32(channelEndTime) - currentTime;
                            retVal = new TimeSpan(0, 0, 0, 0, timeLeft);
                        }
                    }
                }
            }
            return retVal;
        }
 
edit: the code tag from the forum removes some code u'll need for this

try this
PHP:
        public static TimeSpan GetChannelTimeLeft()
        {
            var retVal = new TimeSpan();
            using (new FrameLock())
            {
                if (StyxWoW.Me.ChanneledCastingSpellId != 0)
                {
                    List<string> channelInfo = Lua.GetReturnValues("return UnitChannelInfo(\"player\");");
                    if (channelInfo != null && channelInfo.Count > 1)
                    {
                        var channelEndTime = channelInfo[5];
                        if (channelEndTime != null && Convert.ToInt32(channelEndTime) != 0)
                        {
                            var currentTime = Lua.GetReturnVal<int>("return GetTime();", 0) * 1000;
                            var timeLeft = Convert.ToInt32(channelEndTime) - currentTime;
                            retVal = new TimeSpan(0, 0, 0, 0, timeLeft);
                        }
                    }
                }
            }
            return retVal;
        }
 
Last edited:
Back
Top