Jump to content
MakeWebGames

Change the bank interest without crons?


Recommended Posts

So.... i came across the post Cron-less Energy/Will/Brave/HP Regen + Admin Panel by Cronus2(link below)

 

And i was wondering if it would be possible to make or do something like that for Banks and their interest system?

Being able to allow admins to make adjustments to bank interest for donators and non-donators

 

I am asking because i have no idea if it can be done nor where to start to really figure that out, i do not have the knowledge on those kind of details yet nor have that great of a understanding of the crons or timestamps yet

 

 

LINK: 

 

Link to comment
Share on other sites

I think I did something similar in a mc2 game, I think I used a cron like if donator then interest = if non donator interest =. In terms of a cronless cron in MC2 that is an interesting point and I suppose it could be done. In terms of GL I would create new settings so they can be updated via the admin panel and in the code do a if this then else do that for showing the interest rate. In the hook file I think I'd do something similar to determine which interest rate applied.

Link to comment
Share on other sites

1 hour ago, Canjucks said:

I think I did something similar in a mc2 game, I think I used a cron like if donator then interest = if non donator interest =. In terms of a cronless cron in MC2 that is an interesting point and I suppose it could be done. In terms of GL I would create new settings so they can be updated via the admin panel and in the code do a if this then else do that for showing the interest rate. In the hook file I think I'd do something similar to determine which interest rate applied.

lol, yeah... i know how to do the IF in the crons and stuff but i would like to be able to changes to the rate/percentage without having to edit so much for all the calculations

 

so i was thinking having someway to do it in an admin panel would be something new, different and would help alot with keeping things in order.... at least it gave you something new aswell

Link to comment
Share on other sites

5 hours ago, MajikalJoker said:

lol, yeah... i know how to do the IF in the crons and stuff but i would like to be able to changes to the rate/percentage without having to edit so much for all the calculations

 

so i was thinking having someway to do it in an admin panel would be something new, different and would help alot with keeping things in order.... at least it gave you something new aswell

Wasn't meaning to do any help of IFs just playing out what I did in the past. But yes will be something different and you should post your solution if you get it working.

Link to comment
Share on other sites

You can do it all through the header file using timestamps. 

Set up your queries for players who have donated and non-donated designation for the bank.

Then, when the game time gets to the first timestamp you set for the interest to be added it will run.

Just make sure that when you do your update queries for this, you also include the updated timestamp for 24 hours later.

 

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, newttster said:

You can do it all through the header file using timestamps. 

Set up your queries for players who have donated and non-donated designation for the bank.

Then, when the game time gets to the first timestamp you set for the interest to be added it will run.

Just make sure that when you do your update queries for this, you also include the updated timestamp for 24 hours later.

 

 

From what i am hearing is it is possible to be done.... just gotta learn about timestamps more and understand how to implement it, Thank You!

 

any recommendations on where to start?

Link to comment
Share on other sites

1 hour ago, MajikalJoker said:

From what i am hearing is it is possible to be done.... just gotta learn about timestamps more and understand how to implement it, Thank You!

 

any recommendations on where to start?

There's a lot to it but I'll give you the general outline to help you.

 

1. You'll need to create or append a settings table with the value you want for interest for donators and non-donators

2. You need a place to store the "last run" timestamp...id highly recommend a new field in the users table and handle all users individually, but you could also have one global timestamp

(I'll be explaining as if you're doing the user table route from now on for ease of explanation)

3. Whenever you fetch the user run checks against the last run timestamp. For the timestamp if you have a 0 set the original to floor(time()/86400)*86400 to make it happen right at midnight server time. Want it every 24 hours? Do the following check for example

 

if(timeNow-timestamp > 86400{

//Run it but store the above different so you know how many times to run it.

//Increase the saved last run by 86400*timeToRun

}

 

3a. If you have a users class it's best to put it there. If not put it in the main file (not sure what it's called) where you fetch the user id cookie or whatever or wherever you fetch the user information. You can fetch just the timestamp with a query and run the checks mentioned above

 

Hopefully that makes sense and helps

Just now, gamble said:

 

(Sorry on mobile don't know how to delete quote k meant to edit)

 

Edit:

I meant to mention I recommend you store and handle each user separately for the sake of speed. Easier to update one at a time as needed vs 300000 at once when there's only one user online if that makes sense? Only do what's needed rather than have one handle everyone 

Edited by gamble
Additional info
Link to comment
Share on other sites

Crons are really not needed when simple arithmetic covers it nicely. You could, for example, have different rates per user by storing the APR (annual percentage rate) and the date deposited in the user table. After that, it's just simple case of basic arithmetic to determine the PV (present value).

Example: -- assuming the date deposited is a integer from the PHP function time():

$principal = $ir["bankmoney"];
$apr = $ir["apr"];

$daysSinceDeposited = (time() - $ir["deposited"]) / 86400;  /* 86400 seconds in a day */
$dailyRate = pow(1 + $apr / 100, 1 / 365.2425);             /* 365.2425 days in a year */

$presentValue = pow($dailyRate, $daysSinceDeposited) * $principal;

So assuming an APR of 40%, a principal of $100, after 10 days we'd have a computer present value of $100.925, after 100 days it would be $109.650, after 1 year it would be $140.00 (exactly 40% APR).

Taking money out of the bank would necessitate computing the present value, subtracting the withdrawal amount and placing the result in your bankmoney field, deposits are done by storing the present value plus the deposit amount in the bankmoney field.

Edited by Jax
Adjusted # of days in year
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

window.onload = function() {
    // Call your function immediately if needed
    executeQuery();

    // Then set it to run every 5 minutes
    setInterval(function() {
        executeQuery();
    }, 300000); // 300000 milliseconds = 5 minutes
};

function executeQuery() {
    console.log("Query executed at: " + new Date().toLocaleTimeString());
    // Your query or code goes here
}
 

Edited by rockwood
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...