Jump to content
MakeWebGames

Understanding Cron's


AinzOoalGown

Recommended Posts

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

Link to comment
Share on other sites

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 by PHPStudent
Link to comment
Share on other sites

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));

        }

	});

 

  • Like 1
  • Thanks 3
Link to comment
Share on other sites

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