Jul 30, 2011 11:36 PM
Scripting Error, need help
-
Like (0)
// Setting up the health script
main()
{
thread health_regen();
}
health_regen()
{
while ((isplayer (self)) && (isalive(self)))
{
if(self.health < 100)
self iprintln("boobs");
wait (5);
self.health = 100;
self.health_regen destroy();
}
}[/code:1x0ove91]
the problem is that once you take one point of damage, the script runs continously setting your health to 100 every 5 seconds. Maybe I'm not stopping the thread correctly or maybe I'm not setting it up in the callback right. if some of you experienced modders could help me get this straight this would greatly enhance my mod.
thanks guys 
FYI this is how I start the thread in the callback
[code:1x0ove91]/*================
Called when a player has taken damage.
self is the player that took damage.
================*/
CodeCallback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc)
{
// adding in health regen
if(self.iDamage > 1)
{
self thread maps\mp\gametypes\_health::health_regen();
}
/*================
Called when a player has taken damage.
self is the player that took damage.
================*/
CodeCallback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc)
{
// adding in health regen
self thread maps\mp\gametypes\_health::health_regen(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc);
}
[/code:26kz63ip]
[code:26kz63ip]health_regen( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc )
{
if( iDamage < 1 )
iDamage = 1;
if( iDamage && isplayer( self ) && isalive( self ) )
{
if( self.health < 100 )
{
self iprintln( "boobs" );
wait( 5 );
self.health = self.maxhealth;
}
}
}
playerHealthRegen( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc )
{
if( iDamage < 1 )
iDamage = 1;
if( iDamage && isplayer( self ) && isalive( self ) )
{
if( self.health < maxhealth )
{
self iprintln( "boobs" );
wait( 5 );
self.health = self.maxhealth;
}
}
}
[/code:2v8ke2nf]
The orignal script looks like this, however trying to get this run on UO is hard for me to do as i can barely tell which functions are supported and which aren't. If you couldnt tell scripting isnt my forte
[code:2v8ke2nf]playerHealthRegen()
{
self endon("end_healthregen");
maxhealth = self.health;
oldhealth = maxhealth;
player = self;
health_add = 0;
regenRate = 0.1; // 0.017;
veryHurt = false;
thread playerBreathingSound(maxhealth * 0.35);
lastSoundTime_Recover = 0;
hurtTime = 0;
newHealth = 0;
for (;;)
{
wait (0.05);
if (player.health == maxhealth)
{
veryHurt = false;
continue;
}
if (player.health <= 0)
return;
wasVeryHurt = veryHurt;
ratio = player.health / maxHealth;
if (ratio <= level.healthOverlayCutoff)
{
veryHurt = true;
if (!wasVeryHurt)
{
hurtTime = gettime();
}
}
if (player.health >= oldhealth)
{
if (gettime() - hurttime < level.playerHealth_RegularRegenDelay)
continue;
if (gettime() - lastSoundTime_Recover > level.playerHealth_RegularRegenDelay)
{
lastSoundTime_Recover = gettime();
self playLocalSound("breathing_better");
}
if (veryHurt)
{
newHealth = ratio;
if (gettime() > hurtTime + 3000)
newHealth += regenRate;
}
else
newHealth = 1;
if (newHealth > 1.0)
newHealth = 1.0;
if (newHealth <= 0)
{
// Player is dead
return;
}
player setnormalhealth (newHealth);
oldhealth = player.health;
continue;
}
oldhealth = player.health;
health_add = 0;
hurtTime = gettime();
}
}
// Tally
maps\mp\gametypes\_healthRegen::init();