mIRC Home    About    Download    Register    News    Help

Print Thread
#72905 27/02/04 08:17 AM
Joined: Feb 2003
Posts: 13
C
Pikka bird
OP Offline
Pikka bird
C
Joined: Feb 2003
Posts: 13
What i need is for a variable to be reset to 0 at the beginning of every new month and for its old total to be added to a year variable. Anyone any idea on how to do this?

#72906 27/02/04 10:20 AM
Joined: Mar 2003
Posts: 1,271
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
This code will work when a few conditions are met:

1. the monthly and yearly totals are saved in variables called %yeartotal and %monthtotal (you can of course change them)
2. everytime you save a monthly total, the script remembers of which month it's saved via the variable %lastmonth
3. to ensure it works, try using //set %lastmonth $date(mm)


Code:
[color:green]; This will start a timer that will try to update just after midnight[/color]
on *:START: { timer[color:blue]upd[/color] -o 00:01 1 1 updateme }
[color:red] [/color]
[color:green]; this is called at midnight via the timer and then makes sure it's the firs of the month before actually updating[/color]
alias [color:blue]updateme[/color] {
  [color:green]; check if it's the 1st of a month[/color]
  [color:green]; check to make sure it's a new month[/color]
  if ($date(dd) == 1) && ($date(mm) > [color:blue]%lastmonth[/color]) {
    [color:green]; increment the yearly total with this month's score[/color]
    inc [color:blue]%yeartotal %monthtotal[/color]
    [color:green]; set this month's score back to 0[/color]
    unset [color:blue]%monthtotal[/color]
    [color:green]; remember we already saved this month[/color]
    set [color:blue]%lastmonth[/color] $date(mm)
  }
}


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
#72907 27/02/04 02:21 PM
Joined: Feb 2004
Posts: 201
J
Jae Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2004
Posts: 201
if ($date(dd) == 1) && ($date(mm) > %lastmonth)

<=- that will not work moving from December to January......
cos 1 isnt larger than 12 ... for obvious reasons. but cant be hard to fix..

#72908 27/02/04 10:20 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
using Locutusofborgs code
i would change it to this

Code:
on *:START: { timerupd -o 00:01 1 1 updateme } 
;
alias updateme {
  ; check to make sure it's not in the same month we already added for.
  if ($date(mm) != %lastmonth) {
    inc %yeartotal %monthtotal
    unset %monthtotal
    set %lastmonth $date(mm)
  }
}


this should work even if you play giggy with your date, it just goes off at 00:01 as before, but if the %lastmonth (aka the last month the yearly total was added to) is not this month, well add to the total again, since we dont know what your doing with the yearly total, its really just a grand total, rather than a yearly one.



Link Copied to Clipboard