Jump to content

Health Regen Script Modification Help


Recommended Posts

I am trying to modify Dayo's Health Regen (free) script to include the other stats in game to make it easier to modify on the fly. However I cant seem to get my logic right, I am probs tired and missing something small but thought I would ask if anyone can spot where Ive went wrong.

I know the health system works differently to other stats, as it looks up the rank health as max and uses US_health (damage to player) to deduct rank value so I have modified it so energy gains to US_will, unlike original which deducts from US_health.

I have removed the regen from workout.hooks.php.


		$regenEnergy = $settings->loadSetting("regenEnergy", 1, 1);
		$regenTimeEnergy = $settings->loadSetting("regenTimeEnergy", 1, 1);

        $timerEnergy = "energyRegen";
        $lastEnergy = $user->getTimer($timerEnergy);
        $timesEnergy = floor((time() - $lastEnergy) / $regenTimeEnergy);

    	if ($timesEnergy) {

    		if ($user->info->US_energy) {
	        	$newEnergy = $user->info->US_energy + ($timesEnergy * $regenEnergy);
	        	$maxEnergy = $user->info->US_maxEnergy;
	        	$user->set("US_energy", $newEnergy);
	    		if ($newEnergy > $maxEnergy) $newEnergy = $maxEnergy;
                $energy = $user->info->US_energy;
	            if ($energy < 0) $energy = 0;
	            $page->addToTemplate('energy', number_format($energy, 2));

    		$user->updateTimer($timerEnergy, $lastEnergy + ($timesEnergy * $regenTimeEnergy));


Any guidance would be great.


Edited by AinzOoalGown
Link to comment
Share on other sites

5 hours ago, PHPStudent said:

Do you mean similar to how stats (energy, brave, will, and health) regenerate in mccodes through crons/timestamps? Soz, I don't have a fix I just wanted clarification. Because I'd also be interested in that if its what you're asking for.

I am using Dayo's Health regen module:

So this module allows the regeneration of health over time using timestamps. Originally (from my knowledge) the other stats are regenerated in workout.hooks.php and are defined there as set values.

The good thing about Dayo's health regen module is that you can set the values and time in admin panel for health regen. So I wanted to take that idea and expand it for the other stats (will, energy, brave) so they can also be set in the admin panel. However I think my math/logic is wrong. As health stat regen is deduction from US_health (US-health is bascially how much damage the player has, so reducing it to zero means a player has full health), where as other stats (will, energy, brave) is a addition (stat / maxStat (100/100)).

Edited by AinzOoalGown
  • Like 1
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.

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