//gameUpdates
function Tick()
{
if ( updatePlayerHealth() != -1 )
$tickId = schedule(1000,0,"Tick");
}
function updatePlayerHealth()
{
%player = LocalClientConnection.player;
if (! isObject(%player) )
{
echo("updatePlayerHealth : player object not valid (" SPC $tickId SPC ")" );
return -1;
}
// figures out the total health penalty at once
// this way, reducing the values will "raise" the players over-all health
%amount = 0;
%totalPossibleDamge = 0;
// JY - NOTE: The latest changes make sure that you won't die by a single low value
// rather by a combination of thirst, hunger and Heat
// HUNGER health loss
%hungerDmg=0;
if(Hunger.getValue() > 0.1)
{
%hungerDmg = 100 * (Hunger.GetValue()-0.1);
echo("Hunger health penalty is " @ %hungerDmg);
// tracks the MAX damage taken
if (%hungerDmg > $Player::HungerDamage)
$Player::HungerDamage = %hungerDmg;
%totalPossibleDamge = %totalPossibleDamge - 90;
}
// WATER health loss
%thirstDmg=0;
if(Thirst.GetValue() > 0.1)
{
%thirstDmg = 100 * (Thirst.GetValue()-0.1); // ... .1 = -10, .5 = -50, .9 = -90
// tracks the MAX damage taken
if (%hungerDmg > $Player::ThirstDamage)
$Player::ThirstDamage = %thirstDmg;
echo("Thirst health penalty is " @ %thirstDmg);
%totalPossibleDamge = %totalPossibleDamge - 90;
}
// HEAT health loss
%tempDmg = 0;
if (Heat.GetValue() < 0.4)
{
%tempDmg = (0.4 - Heat.GetValue()) * 200; // 0.01 to 0.40 = 80 to 2
%totalPossibleDamge = %totalPossibleDamge - 80; // max 80 dmg
echo("Heat health penalty is " @ %tempDmg);
}
else if (Heat.GetValue() > 0.6)
{
echo("The heat is getting to you ...");
%tempDmg = (Heat.GetValue() - 0.6) * 100; // 0.01 to 0.40 = 1 to 40
%totalPossibleDamge = %totalPossibleDamge - 40; // max 40 dmg
echo("Heat health penalty is " @ %tempDmg);
}
if (%tempDmg > $Player::TempDamage)
$Player::TempDamage = %tempDmg;
// determine actual over-all impact on players health
// and keep it seperate from actual damage from wounds, etc.
%amount = 0 - %thirstDmg - %hungerDmg - %tempDmg;
if (%amount != 0)
{
%player.adjustHealth( %amount );
$Player::Score = $Player::Score + (1 - (%amount/%totalPossibleDamge));
}
else
$Player::Score = $Player::Score + 1;
$Game::totalScore = $Game::totalScore + 1;
%gameScore = $Player::Score/$Game::totalScore;
GameScore.SetValue(%gameScore);
echo(" ++ gameScore = " @ %gameScore);
}
function changeBar(%whichBar, %amount)
{
echo(%whichBar @" is being changed by "@ %amount);
switch$(%whichBar)
{
case "HeatBar":
Heat.SetValue(Heat.GetValue() + %amount);
case "HungerBar":
Hunger.SetValue(Hunger.GetValue() + %amount);
case "ThirstBar":
Thirst.SetValue(Thirst.GetValue() + %amount);
}
}