AinzOoalGown Posted January 3, 2021 Share Posted January 3, 2021 Hi, I am trying to understand Cron's as I have added a new userstat "US_ram" and "US_maxRam". This is a replacement of "Brave" which was just a placeholder. However I dont understand how I to use the current cron system, as would like to make it regenerate like "will" does. Ive looked through the source and cant see how "Will" and other stats are regenerated over time, or where to set the timer for this. Can anyone point me in the right direction please? Thanks Quote Link to comment Share on other sites More sharing options...
Sim Posted January 3, 2021 Share Posted January 3, 2021 I think @Dayo posted a tutorial somewhere Quote Link to comment Share on other sites More sharing options...
PHPStudent Posted January 3, 2021 Share Posted January 3, 2021 (edited) So I think will and energy regeneration is written in workout.hooks.php file for dayo's workout module. I think the code for brave regeneration would have to go into the crimes files, but I'm unsure how to do that. I could very well be wrong (best to check with dayo) Edited January 3, 2021 by PHPStudent Quote Link to comment Share on other sites More sharing options...
Dayo Posted January 3, 2021 Share Posted January 3, 2021 here is an example of how you can do this cronless, using my workout mod as an example. <?php // {module_name}.hooks.php new Hook("userInformation", function ($user) { global $page; if ($user) { $secondsBetweenGain = 60; // How often (in seconds) you want them to regen "ram" $timer = "ramRegen"; // Make sure you always change this if you have it in a different hooks file! $last = $user->getTimer($timer); // When was the last time the users ram regened $seconds = (time() - $last); // Calculates how many seconds ago that was $times = floor($seconds / $secondsBetweenGain); // Calculates how much ram to give to th user if ($times) { // Only run this if they have new ram to add $newRam = $times + $user->info->US_ram; $maxRam = $user->info->US_maxRam; if ($newRam > $maxRam) $newRam = $maxRam; // Cap the ram to maxRam $user->set("US_ram", $newRam); // Update the user $user->updateTimer($timer, $last + ($times * $secondsBetweenGain)); // Update the timer } // Add ram data to the global template $ramPerc = round($user->info->US_ram / $user->info->US_maxRam * 100, 2); $page->addToTemplate("ram", $user->info->US_ram); $page->addToTemplate("maxRam", $user->info->US_maxRam); $page->addToTemplate("ramPerc", number_format($ramPerc, 2)); } }); 1 3 Quote Link to comment Share on other sites More sharing options...
AinzOoalGown Posted January 3, 2021 Author Share Posted January 3, 2021 (edited) Awesome thanks 🙂 @Dayo I think it might be worth making a Guides Section with in GL Forum part to sticky your information guides and documentation. Or a Wiki page maybe. Thanks Edited January 3, 2021 by AinzOoalGown 1 Quote Link to comment Share on other sites More sharing options...
Sim Posted January 24, 2021 Share Posted January 24, 2021 Is there a such thing as a global timer? Timers that are not binded to players? @Dayo Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.