Page 1 of 1
How to set a timer routine correctly ?!?
Posted: March 26th, 2007, 9:31 am
by kumpel100
all time i have same problem to set timers for buffs in VGExtreme.
here a little example of my bot to see if i doing it correct:
Code: Select all
'*************************************************************************'
'*''''''''''''''''''''''''''' MAIN LOOP ''''''''''''''''''''''''''''''''*'
'************************************************************************'
Dim CurrentTime
Dim Timer15 ' Ward
Dim Diff15
Dim Timer30 'Renewal
Dim Diff30
Dim Timer60 ' all other buffs
Dim Diff60
Dim Timer61 ' all other buffs
Dim Diff61
CurrentTime = Minute(Now)
Timer15 = Minute(Now)
Timer30 = Minute(Now)
Timer60 = Minute(Now)
Timer61 = Minute(Now)
....
....
....
....
Check_Buffs
also in the main checking for buffs..
now the buff section:
Code: Select all
'*************************************************************************'
'*''''''''''''''''''''''''''''''''' Buffs ''''''''''''''''''''''''''''''*'
'*************************************************************************'
function CHECK_BUFFS
Diff15 = Minute(Now) - Timer15 'Ward
If (Diff15 >= 1) then
Sleep 3000
Log.DebugLog " Buffing Ward_Shield"
VGSEndText HOTKEY_Ward
Sleep 3000
Timer15 = Minute(Now)
end if
Diff30 = Minute(Now) - Timer30 'Renewal
If (Diff30 >= 10) then
Sleep 3000
Log.DebugLog " Buffing Renewal"
VGSEndText BUFF_Renewal ' Reneval III
Sleep 3000
Timer30 = Minute(Now)
end if
Diff60 = Minute(Now) - Timer60 'ALL other buffs
If (Diff60 >= 20) then
Log.DebugLog " Buffing Bestowal"
VGSEndText BUFF_Bestowal ' Buffs I
Sleep 3000
Log.DebugLog " Buffing Resolution"
VGSEndText BUFF_Resolution ' Buffs II
Sleep 3000
Log.DebugLog " Buffing Endowment"
VGSEndText BUFF_Endowment ' Buffs III
Sleep 3000
Log.DebugLog " Buffing Spirit_Ressist"
VGSEndText BUFF_Spirit_Ressist ' Buffs IIII
Sleep 3000
Timer60 = Minute(Now)
end if
Diff61 = Minute(Now) - Timer61 'ALL other buffs
If (Diff60 >= 21) then
Sleep 3000
Log.DebugLog " Buffing_Power_of_Reprisal "
VGSEndText BUFF_Power_of_Reprisal
Sleep 2000
Timer61 = Minute(Now)
end if
end function
also my problem is sometimes work and sometimes not, WHY !!!
i getting crazy from test and test and test from test.
Posted: March 26th, 2007, 10:14 am
by binafus
Set the first time during setup.
This is what you would check every time you want to see if it is time to buff.
Code: Select all
DIFF_TIME = Minute(Now) - START_TIME + 1
If DIFF_TIME < 1 Then
DIFF_TIME = DIFF_TIME + 60
End If
Then when DIFF_TIME gets to the time that you wan to buff, buff then set
The thing that is messing you up I'm pretty sure is that lets say Start_time is 58 then five minutes later current time is going to be 3 which is going to give you a negative 55.
So If you check to see if Diff_time is less than 1 you add 60 to it.
In the same situation it will show five minutes has passed which is correct.
Another thing that had been causing trouble is set a sleep before you cast the buff, just to make sure your able to cast.
I also added a check to make sure the buffs had been actually cast by setting a flag when you buff.
Then when the timer reached 55 minutes it double checks your buffs.
Since adding all that I have not had any problems getting buffs on the bot.
It is all redone in the Blood Mage 2.3 I uploaded yesterday.
We are suppose to be able to see what all effects are on a character soon, it will make buffing a lot easier.
It will be nice as well to see if you invis or not on the Blood Mage.
Posted: March 26th, 2007, 10:44 am
by kumpel100
for example:
in top of skript:
Code: Select all
Dim CurrentTime
Dim Timer15 ' Ward
Dim Diff15
Dim Timer30 'Renewal
Dim Diff30
Dim Timer60 ' all other buffs
Dim Diff60
Dim Timer61 ' all other buffs
Dim Diff61
CurrentTime = Minute(Now)
Timer15 = Minute(Now)
Timer30 = Minute(Now)
Timer60 = Minute(Now)
Timer61 = Minute(Now)
buff section:
Code: Select all
'*************************************************************************'
'*''''''''''''''''''''''''''''''''' Buffs ''''''''''''''''''''''''''''''*'
'*************************************************************************'
function CHECK_BUFFS
Diff15 = Minute(Now) - Timer15 'Ward
If (Diff15 >= 1) then
Sleep 3000
Log.DebugLog " Buffing Ward_Shield"
VGSEndText HOTKEY_Ward
Sleep 3000
Timer15 = Minute(Now)
end if
Diff30 = Minute(Now) - Timer30 'Renewal
If (Diff30 >= 10) then
Sleep 3000
Log.DebugLog " Buffing Renewal"
VGSEndText BUFF_Renewal ' Reneval III
Sleep 3000
Timer30 = Minute(Now)
end if
Diff60 = Minute(Now) - Timer60 'ALL other buffs
If (Diff60 >= 20) then
Log.DebugLog " Buffing Bestowal"
VGSEndText BUFF_Bestowal ' Buffs I
Sleep 3000
Log.DebugLog " Buffing Resolution"
VGSEndText BUFF_Resolution ' Buffs II
Sleep 3000
Log.DebugLog " Buffing Endowment"
VGSEndText BUFF_Endowment ' Buffs III
Sleep 3000
Log.DebugLog " Buffing Spirit_Ressist"
VGSEndText BUFF_Spirit_Ressist ' Buffs IIII
Sleep 3000
Timer60 = Minute(Now)
end if
Diff61 = Minute(Now) - Timer61 'ALL other buffs
If (Diff60 >= 21) then
Sleep 3000
Log.DebugLog " Buffing_Power_of_Reprisal "
VGSEndText BUFF_Power_of_Reprisal
Sleep 2000
Timer61 = Minute(Now)
end if
end function
in mainloop:
Posted: March 26th, 2007, 10:53 am
by sinshar
Here is a little bit of my Vanguard SKills Object (class) and how i do skills
This first snippit is how I loaded each skill. NOTE: Since this is a timer forum thread, I have set GIft of ardor to a time a long time ago.. so its immediately ready. the first time i need it, after that the PERFORMSKILL FUnction handles resetting the timer.
Code: Select all
'=========================================================================================
' VG SKILLS OBJECT .VBS
'=========================================================================================
' Currently there are 25 Skills on file
Dim objVGSkill
Set objVGSkill = New VGSkill
' One skill
objVGSkill.SkillName(0) = "Gift of Ardor III"
objVGSkill.SkillRefresh(0) = 60
objVGSkill.SkillRange(0) = 25
objVGSkill.SkillEnergy(0) = 54 f
objVGSkill.SkillEndurance(0) = 0
objVGSkill.SkillCastTime(0) = 0
objVGSkill.KeyMapping(0) = ""
objVGSkill.SkillLastUsedTime(0) = "2/25/2007 11:01:42 PM" ' since its refresh is so damn long
' two skill
objVGSkill.SkillName(1) = "Power of the Grave I"
objVGSkill.SkillRefresh(1) = 0
objVGSkill.SkillRange(1) = 25
objVGSkill.SkillEnergy(1) = 19
objVGSkill.SkillEndurance(1) = 0
objVGSkill.SkillCastTime(1) = 0
objVGSkill.KeyMapping(1) = ""
objVGSkill.SkillLastUsedTime(1) = Now
' 3 skill
objVGSkill.SkillName(2) = "Power of the Grave II"
objVGSkill.SkillRefresh(2) = 0
objVGSkill.SkillRange(2) = 25
objVGSkill.SkillEnergy(2) = 30 ' not sure
objVGSkill.SkillEndurance(2) = 0
objVGSkill.SkillCastTime(2) = 0
objVGSkill.KeyMapping(2) = ""
objVGSkill.SkillLastUsedTime(2) = Now
This little bit is the class define itselt
Code: Select all
Class VGSkill
' Set theseindexes to +1 of the last known index (example VGSKills(1) then set it to 2
' declare private class variable
Dim m_SkillName(3)
Dim m_Refresh(3)
Dim m_Range(3)
Dim m_Energy(3)
Dim m_Endurance(3)
Dim m_CastTime(3)
Dim m_KeyMapping(3)
Dim m_LastUsedTime(3)
' declare the property
Public Property Get SkillName(i)
SkillName = m_SkillName(i)
End Property
Public Property Let SkillName (i,strSkillName)
m_SkillName(i) = strSkillName
End Property
' declare the property
Public Property Get SkillRefresh(i)
SkillRefresh = m_Refresh(i)
End Property
Public Property Let SkillRefresh (i,strSkillRefresh)
m_Refresh(i) = strSkillRefresh
End Property
' declare the property
Public Property Get SkillRange(i)
SkillRange = m_Range(i)
End Property
Public Property Let SkillRange (i,strSkillRange)
m_Range(i) = strSkillRange
End Property
' declare the property
Public Property Get SkillEnergy(i)
SkillEnergy = m_Energy(i)
End Property
Public Property Let SkillEnergy (i,strSkillEnergy)
m_Energy(i) = strSkillEnergy
End Property
' declare the property
Public Property Get SkillEndurance(i)
SkillEndurance = m_Endurance(i)
End Property
Public Property Let SkillEndurance (i,strSkillEndurance)
m_Endurance(i) = strSkillEndurance
End Property
' declare the property
Public Property Get SkillCastTime(i)
SkillCastTime = m_CastTime(i)
End Property
Public Property Let SkillCastTime (i,strSkillCastTime)
m_CastTime(i) = strSkillCastTime
End Property
' declare the property
Public Property Get KeyMapping(i)
KeyMapping = m_KeyMapping(i)
End Property
Public Property Let KeyMapping (i,strSkillKeyMapping)
m_KeyMapping(i) = strSkillKeyMapping
End Property
' declare the property
Public Property Get SkillLastUsedTime(i)
SkillLastUsedTime = m_LastUsedTime(i)
End Property
Public Property Let SkillLastUsedTime(i,strSkillLastUsedTime)
m_LastUsedTime(i) = strSkillLastUsedTime
End Property
End Class
And this is my perform skill function
Code: Select all
'=========================================================
' HELPER FUNCTIONS
'=========================================================
' Here down is the original,
Function PerformSkill(SkillName) 'Casts a spell or performs a skill
PerformSkill = false ' initialize
Dim CurrentTime ' holds the time at the attempt to cast
Dim TimeSinceLastCast ' holds the seconds since last cast
'loop through and find the skill in the object
for i = 0 to 3 ' set this to however many objects are in your VGSKills Object in
' Find the Skill
if objVGSkill.SkillName(i) = SkillName then
UpdateDebugInfo "Found Skill" & SkillName
' Now check to see if the skill can be cast (skill timer)
CurrentTime = Now ' get the now time.
UpdateDebugInfo "Current time is " & CurrentTime
TimeSinceLastCast = DateDiff("s", objVGSkill.SkillLastUsedTime(i), CurrentTime) 'Calcualte the seconds since last cast
if (TimeSinceLastCast => objVGSkill.SkillRefresh(i) ) then
UpdateDebugInfo "Time since last cast good"
' check for Energy
if (getPlayerPower => objVGSkill.SkillEnergy(i) ) then
UpdateDebugInfo "Energy good"
' check for Endurance
if (getPlayerEndurance => objVGSkill.SkillEndurance(i) ) then
UpdateDebugInfo "Endurance good"
' Check if Range is good
if (getTargetDistance() <= objVGSkill.SkillRange(i) ) then
UpdateDebugInfo "Mob Is within Range "
' GO ahead and send the hot key
VGSendText( objVGSkill.KeyMapping(i) )
PerformSkill = true
' Reset the skills last used timer
objVGSkill.SkillLastUsedTime(i) = Now
' Must wait 2 seconds for skill Manditory timer to refresh.
' check the skills cast time, and subtract 2 from it if its longer
' if the SKill cast time is over 2 seconds, do nothing, other wise wait itout
if ( objVGSkill.SkillCastTime(i) > 2 ) then
' DO nothing its already time to cast
else
WIN32.SLEEP(StandardCombatSkillRefresh)
end if
if (PerformSkill = true ) then
UpdateDebugInfo SkillName & " Performed Sucessfully "
else
UpdateDebugInfo SkillName & " Failed "
end if
end if
end if
end if
end if
end if
next
end function
Thats how i did it for handling timers in the casting and performing of skills, Hopwfully it answeres your question,One of these days i will post my bots, the problem is my code is Very hard to read and Setup...
Posted: March 26th, 2007, 11:34 am
by binafus
Everytime you figure the difference you need to check to see if they number is negative if it is add 60 to it.
Diff15 = Minute(Now) - Timer15 'Ward
If Diff15 < 0 then
Diff15 = Diff15 + 60
End If
Do this for every timer check you have.
Posted: March 26th, 2007, 12:20 pm
by kumpel100
binafus wrote:Everytime you figure the difference you need to check to see if they number is negative if it is add 60 to it.
Diff15 = Minute(Now) - Timer15 'Ward
If Diff15 < 0 then
Diff15 = Diff15 + 60
End If
Do this for every timer check you have.
what means that +60 ?
60= 60 minutes?
Posted: March 26th, 2007, 12:53 pm
by binafus
Start Time = 10 at ten after the hour
15 minutes later we do a Minute(Now) it would 25 after.
So your equation would work right and get buffs.
25 - 10 = 15 then buff ur 15 minute buff.
But if Start Time = 55 at 55 minutes after the hour.
Then 15 minutes later you do a Minute(Now) it would be 10 after so your equation would look like.
10 - 55 = -45 Which would never reach your buff timer
So you check for a negative number and if so you add 60
10 - 55 = -45
Diff = -45 + 60 = 15 minutes which would be correct.
Posted: March 26th, 2007, 1:05 pm
by kumpel100
.. works now...