Daily Bonus
This script provides a simple “daily bonus” mechanic, allowing players to receive bonus rewards once a day. It assumes that you can get a bonus on a new day, but you can write your conditions to use different periods if you want.
It is intended for offline games and uses the player’s system time to reward bonuses and to determine whether rewards can be rewarded.
In order to provide developers with more control over the rewards, script calls are provided. It is up to the developer to determine how to set it up for their game.
Download
Script: download here
Installation
Place this script below Materials and above Main
Usage
The following script calls are provided.
daily_bonus_available?
This checks whether you are eligible for daily bonuses, based on the current
day. The assumption is that you can only get rewards once a day, and so this
method returns true only if the day is different from the last recorded day.
update_bonus_time
This will update the time that the bonus was taken. You should call this
whenever a bonus is rewarded.
If “daily bonus” is not suitable, you can get the last reward time directly
last_reward_time
Which returns a Time object. You can then use this to check against the current
time.
Example
Suppose you decided to create an event that serves as the reward NPC. Use a variable to determine how many times you have received rewards.
You would have a conditional branch that checks whether login bonuses are available. If so, you would then go through a series of variable checks to determine which reward to give them.
Finally, you would call update_bonus_time
to log the actual reward.
I have 30 different conditional branches (one for each day) inside the conditional branch which asks if the player is eligible for a reward (daily_bonus_available?), and it is returning ALL of them as TRUE, even though those conditional branches are tied to a completely different thing (an in-game variable) and only one out of the 30 should be returned as TRUE.
I get a cant compare to nil error when i call the conditional branch…
got it working but its a shame you cant get the first daily bonus immediately (it crashes if i hadnt called update once before the conditional)
I’ve updated the script so that you can specify exactly how many seconds to wait before the next reward is available.
So if you wanted the first reward to be offset by a certain amount of time after the game starts, just make the call
update_bonus_time(seconds)
And it should work.
Hello there Hime.
Once again, your work is awesome but I'm really noob on scripting so I'm pretty lost: how do you change the timer for the reward?
I'm wondering if you were able to upload a master demo of your scripts or something like this (I guess a demo for each script is way too tiresome), since I can see how it works by my own more easily.
Thanks in advance.
The easiest way would be to find a script that allows you to compare two times and then use it in a scripted conditional branch.
I don't provide that functionality in this script because that is not the purpose of the script.