now I have this script
I want to send the weekly reward to players by mail, here's my take on how to tackle this problem
yup, basically I just added a few more line down there
now, this is what happen when the script first loaded
1. when the server load the script for the first time, it will execute OnInit: and try to save the date of Sunday on that week
- CURDATE() means today is '20201014'
- DAYOFWEEK(CURDATE()) means today is Wednesday(4) -> Sunday is (1)
- that's why needs a -1 , DAYOFWEEK(CURDATE())-1 means -3
- SUBDATE(CURDATE(), INTERVAL (DAYOFWEEK(CURDATE()) -1) DAY)
- SUBDATE('20201014', INTERVAL (3) DAY)
- return '2020-10-11' is the Sunday of that week
- since it return '2020-10-11', have to kill the '-' symbol, use REPLACE syntax to remove that symbol
this value '20201011' is save into $poring_rank_1st_sunday and remain unchange forever
and the script will always try to compare to this value in DATEDIFF
now, this is what happen on the next week when triggering OnSun0000: label
"SELECT DATEDIFF(CURDATE(), '"+ $poring_rank_1st_sunday +"')/7"
- CURDATE() is '20201018', the Sunday on the next week
- DATEDIFF('20201018', '20201011') return 7, since we need to compare in weeks, do a /7, 7/7 = 1
- .this_week_index = 1, $poring_rank_week_index = 0, the value are different now, thus it will try to reset the ladder
and once the ladder is reset, set $poring_rank_week_index(0) into .this_week_index(1) so it won't trigger on OnInit: label again
even doing a @reloadscript, it will compare the week index as 1 == 1, and won't execute ladder reset
only the next week again, compare the week index as 2 == 1, only will execute ladder reset
unlike the monthly reset, which save the actual date,
this one has to increase the week index counter even if there are no ranking in that week
External Links:
Weekly MVP Rewards