Jump to content

GetTime() problems


ScripterQQ
 Share

Recommended Posts

Hello, it's been a while since I don't post here. But I'm kinda back, so I'm working again on some profiles.

One is at a good point, but the rotation program (you know the name I dont need to write it so it appears on google and stuff), is too fast, even if I put max delay, I want to set my "reaction" in a more human way and less suspicious.

So let's assume someone in Arena/BG gets a Polymorph, I can dispel it, but that can be istant if I'm not on GCD, or max 1sec delay. Either way it raises some suspects if someone keeps watching me.

So I was thinking about dispel only after X seconds of the debuff

and there is LUA:

local _,_,_,_,_,_,expiration = UnitDebuff("target","Polymorph")

First 6 arguments are -useless- so I'll use the 7th (expiration) becasue I need that one specifically.

By using a simple

/run local _,_,_,_,_,_,expiration = UnitDebuff("target","Polymorph"); print(expiration-GetTime())

you get in your chat the exact amount of seconds remaining before the debuff disappears.

So my first attempt to automatize the dispel was just
 

if expiration - GetTime() <= 8

then

CastSpellByName("Dispel Magic-Cleanse-Whatever","target")

end

and after 2 seconds of 10 seconds Polymorph it correctly dispels the target, simulating a human delay.

 

But what if the Poly is in DR? The duration is now 5 seconds not 10, so the script will trigger istantly because 5 is <= 8, thus it doesn't wait those 2 seconds.

Ok, easy I thought:
 

if expiration - GetTime() < expiration - GetTime() - 2

then

CastSpellByName("Dispel Magic-Cleanse-Whatever","target")

end

In this way, the Polymorph in DR lasting 5 seconds should be dispelled at 3, exactly after 2 seconds.

Guess what? It doesn't work.

 

But if I do a

print(expiration-GetTime()-2)

or any other number, the seconds are correctly delayed so it's not a syntax problem, expiration is a number, GetTime is a number and 2 is a number. Im not mixing banans with apples.

Why when using the " if " statement I can't substract seconds and the script doesn't work, but the print command can add and substract numbers to GetTime()?

 

What am I missing? Greetings, have a nice day!

Link to comment
Share on other sites

What do you mean, "it doesn't work"? Is there a Lua error or is your condition just faulty and never gets hit?
Because if you think about it, GetTime() always changes. You need to know when the buff/debuff started. 

Yes, you know when it expires, but you don't know when it started unless you take the duration into account. You're not calculating "timeLeft" you're calculating "timeAlreadyPassed".

 

local timeLeft = expiration - GetTime()
local timeAlreadyPassed = duration - timeLeft

if (timeAlreadyPassed > 2) then
	CastSpellByName('Simple Logic')
end

 

Link to comment
Share on other sites

@Matenia No lua error, the condition is never met.

GetTime() changes, that's why instead of putting a number like

if expiration - GetTime() <= 6 

I want a number that can change so

if expiration - GetTime() <= expiration - GetTime() - 2

Should do the trick?

 

As already said, I don't think I'm mixing apples with bananas, in fact if I just ignore the rotation, and apply a debuff on myself, and then print a

expiration - GetTime() - 2

I get the exact second remaining of that Debuff, but with -2 offset:

expiration - GetTime() would print out 9.9, but since I added a -2, it prints out 7.9 correctly

 

So the syntax is correct, but the rotation program somehow doesn't recognize the if statement if put like that.

I can compare expiration - GetTime() only to a number of seconds, not to "itself modified"

I already tried to set a variable like

local duration = expiration - GetTime()

and then

if expiration - GetTime() <= duration -2

still doesn't work, I can't understand.

I know for sure that expiration - GetTime() will give out a number, so why adding or removing a certain amount of seconds won't make trigger the if statement, but siomehow the print function works?

I will check about the start time, but Im afraid I need to use a Frame and register combat log events? That would be annoying.

@TheSmokie No the program is fine and I run it at 1000ms delay, no spells are skipped the rotation is flawless I just wanted to make it more human and less bottish ?

 

Link to comment
Share on other sites

My solution still stands. GetTime() is a timestamp of sorts. It ALWAYS changes.
That's why you need to calculate the time that has already passed since the spell was applied, which is its full duration MINUS the in which it's going to end. And THAT needs to be larger than 2.

Link to comment
Share on other sites

Yes it changes, but why do you think it matters exactly?

Look:

if X = X - 2

I don't care if X (expiration - GetTime()) changes, because the offset (-2) doesnt change

if 10 = 10-2 the result witll be 8

if 25 = 25-2 the result witll be 23

This is what I had in my head.

 

I had to read the combat log to get the time applied, there is no other way as far as I know, not with LUA at least.

 

EDIT: Strikethrough because it was not correct, see posts below.

Link to comment
Share on other sites

Can you just use my code example and see if it works?
Another example:

ExpirationDate = 2020-11-11 18:48:30 (static point in time)
CurrentTime = 2020-11-11 18:48:20 (this obviously changes)
FullBuffDuration = 10 seconds
TimeLeft = ExpirationDate - CurrentTime (this will get lower and lower with time, at the start here, it's 10 seconds)
TimeAlreadyPassed = FullBuffDuration - TimeLeft (this is 10-10 = 0)

Now as time passes on, the result of TimeAlreadyPassed gets HIGHER and HIGHER until it reaches 10 eventually. 
So if you look at my condition in my original post, you will see that I validated TimeAlreadyPassed for GREATER THAN 2.

If you still haven't read the documentation, please do.

Link to comment
Share on other sites

I just figured out why it doesnt work my way:

doing if expiration < 8 a normal poly would be dispelled with a 2 seconds delay

doing if expiration <= expiration - GetTime() - 2 won't work, because its like writing

if 5 <= 3 so thats why it doesnt dispel...Simple maths..

Sometimes I trip over banal things and I think this is one of them.

 

You are correct the only way is getting the start duration and substract the expiration! Later I do some tests

Link to comment
Share on other sites

@ScripterQQ i found this, might help ya ! 

		-- Tabled Cast Time Checking for When you Last Cast Something.
	CheckCastTime = {}
	Nova_CheckLastCast = nil
	function Nova_CheckLastCast(spellid, ytime) -- SpellID of Spell To Check, How long of a gap are you looking for?
		if ytime > 0 then
			if #CheckCastTime > 0 then
				for i=1, #CheckCastTime do
					if CheckCastTime[i].SpellID == spellid then
						if GetTime() - CheckCastTime[i].CastTime > ytime then
							CheckCastTime[i].CastTime = GetTime()
							return true
						else
							return false
						end
					end
				end
			end
			table.insert(CheckCastTime, { SpellID = spellid, CastTime = GetTime() } )
			return true
		elseif ytime <= 0 then
			return true
		end
		return false
	end

 

Link to comment
Share on other sites

I dont get this code. Where is supposed to be located the starting duration of the debuff applied by arena1/2/3 (example: Polymorph)

As far as I know, the only way is listening to combat log events and grab the start duration from there. And then eventually do the maths.

 

EDIT: Strikethrough because it was not correct, see posts below.

Link to comment
Share on other sites

On 11/26/2020 at 9:04 AM, Matenia said:

I literally gave you the full solution. You have the time left, you have the full duration. From that you can do the math to get the the starting time in GetTime() value. 

Wait sorry Im doing confusion again.

The LUA Api of UnitDebuff doesn't provide itself when the debuff has been applied, it only gives duration "10" which is the static default duration of the debuff (Polymorph, no matter if Full or DR), and expiration, which (combined to GetTime()) gives the remaining seconds when the debuff has been applied.

So basically I have a static 10 seconds that tells me that the Poly is supposed to last max 10 seconds. This duration doesnt tell me where or when or how, its just a static number, kinda like a SpellID. This 10 will NEVER change.

And then a value that changes which is the expiration, it can be 10 if full, 5 if first DR and so on.

I dont see any connection with the starting time, the UnitDebuff just tells me "The poly should last 10 seconds. but in this moment, it lasts 5 seconds", or "The poly should last 10 seconds. but in this moment, it lasts 2.5 seconds". As already said, the 10 doesnt change, only the "expiration" changes.

Again, unless I track the combat log and grab the start duration from there, the time where the target actually got the debuff,  I cant understand your last message. Maybe time to go to school or something...

 

EDIT: Strikethrough because it was not correct, see posts below.

 

 

 

Link to comment
Share on other sites

Duration is always a fixed number (dont recall if 10 seconds for pvp, or 2min for pve), it doesnt change based on DR

 

 
Quote

 

duration 
Number - The full duration of the debuff in seconds; nil if the debuff was not cast by the player.

 

Thats the first thing I tested and I clearly remembered that it was always showing the "ideal duration", despite the debuff being full, dr, or even immune. Thats why its written "full duration"

But even in the case I am completely wrong and I have a bad memory (I dont have time now to test the command again), it clearly says "nil if the debuff was NOT cast by the player", means that if arena1/2/3 cast Polymoprh, "duration" will always return nil. So again, the only information I can gather from that is the expiration time. Other stuff must be grabbed from the combat log.

 

 

EDIT: Strikethrough because it was not correct, see posts below.

 

 

Link to comment
Share on other sites

UPDATE: I just tried the command and I am still confused because

1) It actually shows the duration 10/5/2.5, not always 10 as I was insisting, so I messed up there somehow

2) That being said, I was expecting to not get any duration result if the debuff was NOT casted by me, so I logged a 3rd char and used the command to see the duration of the poly casted from my mage towards my paladin, and well, it was still saying the duration, despite the debuff being NOT applied by me (I was on Priest, and not even in a group with them)

So first of all I apologize for the confusion, second, the LUA API is not updated, or the server I am playihng is bugging, or again, I miss some brain cells lol.

anyway for those who wants to try it this is the command I used

/run local _, _, _, _, _, duration, expires = UnitDebuff("target","Polymorph") print("Duration: "..duration.." Expires: "..expires-GetTime())

 

I will do further tests, im not sure if it will give the duration if the poly is casted by arena1/2/3

 

EDIT: Tried in duel zone, apparently it works, need to test it in Arena, but its very weird, I mean the API clearly says it should return "nil" if not casted by me, so idk..Maybe I miss something..Sorry again for the confusion (and not my intention to sound arrogant or c*cky I was just trying to understand)

 

This is the full test script:

--test
if UnitDebuff("player","Polymorph")
then
	local _, _, _, _, _, duration, expires = UnitDebuff("player","Polymorph")
	if expires-GetTime() <= duration - 2
	then
		print("2 seconds has passed since the debuff")
	end
end

 

Link to comment
Share on other sites

The API docs are outdated or incorrect and that sentence is a reference to TBC, where you couldn't see ANY durations (no timeLeft either) if it's not casted by you. I thought it was pretty common knowledge that in WotLK you can see all durations at all times. This is exactly what the default UI does - how do you think it draws cooldown frames or addons like OmniCC wrap timers over them?

So to take my original post from weeks ago:

 

local _, _, _, _, _, duration, expiration = UnitDebuff("player", "Polymorph")
local timeLeft = expiration - GetTime() -- timeLeft in seconds
local timeAlreadyPassed = duration - timeLeft -- time the debuff has been applied to the target in seconds

if (timeAlreadyPassed > 2) then
	CastSpellByName('Simple Logic')
end

 

Edited by Matenia
Link to comment
Share on other sites

@MateniaYeah the fact is I had that API page in my bookmarks since years and I always used it, I never thought it was so outdated since I never encountered any problems, again I apologize... kind feel stupid relying on a TBC page while experts here are telling me some LUA basics... /facepalm

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...