Raised This Month: $51 Target: $400
 12% 

[Any] Daily Rewards


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SnapDragon
Member
Join Date: Feb 2015
Location: Under the bridge close t
Old 02-24-2017 , 05:16   [Any] Daily Rewards
Reply With Quote #1

I have being thinking about making Daily reward plugin, but i dont know how to make this daily reseting trigger at MySQL, so i dumped that project, now im asking if someone knows how to do it, or have something like it allready done.
__________________
-----------------------------------------------
////////////////////////////////////////////////
<><><><><><><><><><><><><>
<><>Check bans.VikVek.com<><><><>
<><><><><><><><><><><><><>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\
-----------------------------------------------
SnapDragon is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-24-2017 , 07:55   Re: [Any] Daily Rewards
Reply With Quote #2

Use a timestamp?
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-24-2017 , 08:19   Re: [Any] Daily Rewards
Reply With Quote #3

Add a column last_day_claimed.

When the reward is claimed, set the account's last reward claim day to TO_DAYS(NOW());, then you can check that the daily reward for the day hasn't been claimed by selecting from the table WHERE last_day_claimed >= TO_DAYS(NOW()); (you'll get zero rows if the reward hasn't been claimed).

Daily rollover dependent on your MySQL instance, I think.

For SQLite, I think you can use cast(julianday('now') as int) instead.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-24-2017 at 08:32.
nosoop is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-24-2017 , 08:43   Re: [Any] Daily Rewards
Reply With Quote #4

Do not use NOW().

Use: https://sm.alliedmods.net/new-api/sourcemod/GetTime

Save into the table and whenever the client rejoins, GetTime and then check their last unixtime stamp.

A simple if statement; if (CurrentTime > OldTime + 86400)

86400 = 1 Day.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-24-2017 , 10:10   Re: [Any] Daily Rewards
Reply With Quote #5

Quote:
Originally Posted by OSWO View Post
Use: https://sm.alliedmods.net/new-api/sourcemod/GetTime

A simple if statement; if (CurrentTime > OldTime + 86400)

86400 = 1 Day.
Your suggestion applies a 24-hour cooldown on claims. Not a system that resets each day.

Which seems the same, except that if a player plays in the evening and then plays in the morning the next day, they still have to wait for the evening until they can claim the next reward. Not to mention claims will end up happening later and later.

I was also going to suggest GetTime() / 86400 to get the number of days and store that, but taking leap seconds and whatnot into account means the "day" may not reset at a predictable time.

FormatTime(buffer, sizeof(buffer), "%Y%m%d") would work with string equality tests.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-24-2017 at 10:15.
nosoop is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode