How do I... create a daily rewards system?

Get help using Construct 2

Post » Thu Dec 20, 2012 8:08 pm

I'd like to add a daily rewards system. I have a MYSQL database connected to the game using AJAX to record player data - but I'd like to add points to their account each time they log in - but only once per day.

Anyone have any suggestions on how to do this? I'm thinking it would require a PHP script of some sort - but I've never built one and if anyone has any suggestions on how to do this (or suggestions on where to look for more info) that would be AMAZING!!

Thanks in Advance!

Amani Swannn
Posts: 15
Reputation: 330

Post » Thu Dec 20, 2012 8:51 pm

Hey browardtech,

I haven't messed with mySQL and AJAX, so this is just a random idea... but could you use some of the basic System time functions to check when they last logged in? When they login, have the system save the current time and date and every time after that check it to see if it's been a certain amount of time since last login?
Posts: 152
Reputation: 3,764

Post » Thu Dec 20, 2012 9:05 pm

The method Space Ape gave is correct and has to be done, as you thought in a PHP script you would call via AJAX on login of your player.

To learn PHP a google search might give some good results (the sites I used to learn it 10 years ago were in French, so I guess wouldn't be of use for you or even still up to date).
And for development questions there's always the nice, PHP itself being already largely discussed over the net as well as out of the scope of this forums (just saying for anyone else looking for infos about PHP here).Kyatric2012-12-20 21:07:29
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Posts: 7,084
Reputation: 62,904

Post » Thu Dec 20, 2012 9:37 pm

I posted a question in stackoverflow...

...and I know basic PHP - but I still could use a bit of help explaining how to do so - if anyone can assist - I sure could use it!
Posts: 15
Reputation: 330

Post » Thu Dec 20, 2012 10:36 pm

ok the thing is this forum covers creating client side game. What your asking for is server side rewards. This isn't the area that C2 is built for.

So bind the website user to the game by whatever means. Upload the score into a daily highest for the user. Upon upload it's the server side to compare there first daily accomplishment reward -24 hours. Upon that offer your points to the user account. However everything on the server side is going to have to use other forums.

are you using Joomla, Drupal or some other CMS system. I'm interested in this myself as I have a game that will be offering online user points upon success. But it's not right now so I haven't spent any time focussing on it. Also I'm using Drupal to ease my pain. However this will require a custom page call from the game ajax upload.
Posts: 2,455
Reputation: 14,921

Post » Thu Dec 20, 2012 11:43 pm

Look up cron jobs on stack overflow. I think that's probably what you're looking for. It's basically a php other other script that is run on a server at specific times. So the basic layout would be create a script to update the reward then create a cron job on your server to run it once every 24 hours. You can search stackoverflow for info on cron jobs. Hope that helps :)
Posts: 706
Reputation: 15,809

Post » Fri Dec 21, 2012 4:29 am

You can actually achieve this with the plugin. Look into the data storage feature - you can store data for each given user.

What I would do is use this plugin to get the year, month and day. Then see if that date is different than the date you have stored using the plugin under the key 'lastLogin' (you can use any key name you want). If it is, then you increment their point total (another integer stored as data on by however many points you want to add. You can also tie this into our achievements system so you can give out achievements if they hit a certain number of points, or days logged in consecutively, etc...
Posts: 208
Reputation: 6,247

Post » Mon Nov 02, 2015 3:04 am

Ok, it would be something like this:

You are using ajax to save the score and login, through a php file right?

First thing: Create a column in the user table on your mysql database for the last_loginreward_time for example.

Now, in the php file, everytime the user login, check the last_loginreward_time for the current user.

If it's not from today, update the field with the current timestamp and add the reward to the user.
If it's from today, don't update the field, and don't add the reward to the user.

Another way is creating a table just for the log of logins. Everytime a user login in the game, you create a new log with the time. Then, make a query to pull all logins from the player, of the current day, if there is more than one result, means that the user logged more than one time today, so he probably already received the reward. If there is only one (because we just added), means that this logins is the first today, so give him the reward.

I won't give you the code, because you need to know understand something that you did yourself, it's the best way to learn. But that's a logic you could use.

Edit: Sorry for answering a really old post. Was unintentional. Forgot to look at the date, my mistake.
Check our 2D assets platform!
Posts: 12
Reputation: 713

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests