Jump to content
MakeWebGames

Cron-less Energy/Will/Brave/HP Regen + Admin Panel


Cronus2

Recommended Posts

image.png.8c58d27b04dd48a85dbbe5fffcfde3bf.png

I just jumped back into script writing and this was the first thing I added to my base MCCodes so things can regen without crons.
This also includes the ability to adjust the regen settings through the admin panel.

This script adds ZERO new queries to page loads, unless something is updated.
It also adds 6 new variables to the game settings table in the database, so that you can adjust the regen amounts through the admin panel.

1. Add "lastupdate" to your users table as INT.
2. Add the following to your settings table, the ID values are not important:
    image.png.976b85dbde14c3d4cad51191d4545a27.png
3. Add the following code to your globals.php around line 138, right after the Force Logout function:
 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

This updates each as expected and will not let any of them regen over 100%.

4. Replace this section of your admin.php:
image.png.4ed7fe4bbbc0270e621150c088a44253.png
With this:
 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

You will also need to add the following link to your staff admin panel menu under the area where only $ir['user_level']=2:
 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

If you have any questions or if you think something is incorrect, let me know.

---------------------------------

Also, if you carry the $timediff variable into your header function in header.php, it can give you the seconds remaining until the users next regen.

I put it in the menu bar kind of like this, though it would probably look nicer as mins/secs:

image.png.267bc24df137375fb350c622bbcb9904.png

Edited by Cronus2
  • Like 1
  • Thanks 2
Link to comment
Share on other sites

1 hour ago, AdamHull said:

Would this work if nobody was on the site? Would it loop through and update for the missing time?

 

This is the reason I hate timestamps 

It does not update if no one is on the site, and also it only updates the user loading the page instead of the entire users table.

Once the user comes back online, it catches them up though.

Link to comment
Share on other sites

  • Cronus2 changed the title to Cron-less Energy/Will/Brave/HP Regen + Admin Panel
  • 5 months later...
1 hour ago, Ob4j4 said:

How do I add the timediff variable in the header?

The timediff would be an exposed variable so you would be able to place it anywhere. It’s been a while since I looked at global_func.php so I am not sure if there is a function that will convert to min:sec.

Bottom line, you should be able to slap that variable pretty much anywhere

Link to comment
Share on other sites

You know, if somebody at work posted two files totalling over 400 lines with the simple "I'm getting big numbers" complaint, my response would not be unkind, but I'd suggest that perhaps they went back to the drawing board, tried to find out what the problem was themselves, better yet, explain what the problem is with screen grabs where appropriate, and provide description of what is happening, where it is happening, and what the expected behaviour is.

A lot of the people here are lucky enough to work in the industry, but looking through poorly formatted code, without a clue as to what the issue is strikes me as being more work, less play!

Saying that, the whole delta updates i.e. timestamp based rather than cron based updates looks very messy, especially as it can be done in a couple of queries and not within a loop. If you had for example a user that hadn't logged in for one month, that loop could run over 8,000 times, generating over 1,500 queries when 2 would suffice.

Given you know the current time, you know the time the user was last updated, that gives you a time difference in seconds. Assuming that is greater than some small figure (say 300 seconds) then you can update the user's fields: will, brave, hp and energy with the time difference multiplied by the increase per second of each field which is simple to calculate.

The problem with doing this, is loss but this is only addressed by using real numbers for the four fields; the maximal values can remain integers; which in turn does cause a couple of other minor issues.

Nothing against the original author of this, conceptually it's a neat trick, but anytime you have a query in a loop, you need to start asking questions. With the default DB schema, even a simple SELECT operation will lock the entire table for all other operations, so this method will quickly limit the amount of simultaneous users you can have on any system, and has the potential to cause unpredictable and difficult to debug timeouts.

Finally, it's great to update your own player like this; I use a similar technique, but what happens to other players? NPCs being the obvious example. If you have a number of NPCs that people can fight against, how do their stats regenerate? I simply pose the question, I don't offer a solution here, though it is simple to implement.

Link to comment
Share on other sites

8 hours ago, Inveteratus said:

You know, if somebody at work posted two files totalling over 400 lines with the simple "I'm getting big numbers" complaint, my response would not be unkind, but I'd suggest that perhaps they went back to the drawing board, tried to find out what the problem was themselves, better yet, explain what the problem is with screen grabs where appropriate, and provide description of what is happening, where it is happening, and what the expected behaviour is.

A lot of the people here are lucky enough to work in the industry, but looking through poorly formatted code, without a clue as to what the issue is strikes me as being more work, less play!

Saying that, the whole delta updates i.e. timestamp based rather than cron based updates looks very messy, especially as it can be done in a couple of queries and not within a loop. If you had for example a user that hadn't logged in for one month, that loop could run over 8,000 times, generating over 1,500 queries when 2 would suffice.

Given you know the current time, you know the time the user was last updated, that gives you a time difference in seconds. Assuming that is greater than some small figure (say 300 seconds) then you can update the user's fields: will, brave, hp and energy with the time difference multiplied by the increase per second of each field which is simple to calculate.

The problem with doing this, is loss but this is only addressed by using real numbers for the four fields; the maximal values can remain integers; which in turn does cause a couple of other minor issues.

Nothing against the original author of this, conceptually it's a neat trick, but anytime you have a query in a loop, you need to start asking questions. With the default DB schema, even a simple SELECT operation will lock the entire table for all other operations, so this method will quickly limit the amount of simultaneous users you can have on any system, and has the potential to cause unpredictable and difficult to debug timeouts.

Finally, it's great to update your own player like this; I use a similar technique, but what happens to other players? NPCs being the obvious example. If you have a number of NPCs that people can fight against, how do their stats regenerate? I simply pose the question, I don't offer a solution here, though it is simple to implement.

Some people learn things differently than others what's right for me and may not be what they had envisioned, Ever had something in your head that you cant quite explain to others how to picture it ?? This is the same thing. Its the correct format for them but we see it differently. but either way the end result works...

Link to comment
Share on other sites

15 hours ago, Uridium said:

Some people learn things differently than others what's right for me and may not be what they had envisioned, Ever had something in your head that you cant quite explain to others how to picture it ?? This is the same thing. Its the correct format for them but we see it differently. but either way the end result works...

I'm sure everyone has done that, however....

"Here is all the code because I can't be bothered to debug shit myself", is a bullshit approach.

Even a basic var_dump of the variable, so it would at least return (string "") or something, would be more research than it feels has been done.

Feed a man a fish and he'll eat for a day, and all that shizzle.

  • Like 1
Link to comment
Share on other sites

To put my 2 cents into it, he just gave people mmcodes for free, posted all the main pages ones plus database sqls. 

My advice is LEARN PHP, no one is going to do it for you, if you can't learn it you will never be able to have a game and control the bugs and whatever happens in it. Or be able to update it. Unless you are loaded with cash and pay someone to do it all for you.

Edited by lucky3809
  • Like 2
Link to comment
Share on other sites

  • 7 months later...

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