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

0 favourites
  • 10 posts
From the Asset Store
Give your players time based rewards, checks how long player has been away to display time remaining to reward.
  • 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

  • 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?

  • 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 stackoverflow.com, 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).

  • I posted a question in stackoverflow...

    stackoverflow.com/questions/13980764/daily-rewards-system-php-file

    ...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!

  • 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.

  • 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 :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can actually achieve this with the Clay.io 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 Clay.io 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 Clay.io) 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...

  • 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.

  • hassekf sharing Knowledge is always helps for someone, its 7 years but i came across this post today for my game. i Wonder if there is any example for daily reward

    thanks

  • hassekf sharing Knowledge is always helps for someone, its 7 years but i came across this post today for my game. i Wonder if there is any example for daily reward

    thanks

    Hey mate, not a problem. I would recommend you to try first, and see where you got stuck, then i can guide you from there. This way you can get your head around the logic for the whole process, otherwise, if i give you a step-by-step, you would end up not understanding how everything works.

    Just hit me up as soon as you have any specific question. I'm glad to help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)