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