5 Replies Latest reply: Aug 2, 2011 1:54 AM by dante2010 RSS

Scripting Error, need help

[EW]TheO'ReilyFactor
Ok, so this isn't Black Ops but the scripting language stay pretty well the same between cod games.

i'm trying to set up health regen on  UO which use health packs by default. I call this script when ever the player recieves one point of damage.

//     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();
     }

  • Re: Scripting Error, need help
    The great thing about the way Call of Duty games works is you don't need a loop function to monitor things like player damage or being killed - the engine does it for you. So, loose the while() loop and use the callback_playerdamage function to do the work for you:

    /*================
    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;
            }
         }
    }


    Doing it that way will prevent any health increase happening when damage is not being done to the player.

    EDIT -

    If I was attempting this, I would port the COD2/COD4 _heathoverlay.gsc (i.e. regen) code over to UO, as it makes a far better job  of it and has all the right checks in it. There is only one unsupported function in that file (setNormalHealth()) but you can re-create that yourself as all it does is what you already did  - assign self.health back to self.maxhealth. The rest of the code you wouldn't have a problem with.
  • Re: Scripting Error, need help
    [EW]TheO'ReilyFactor
    Thanks for the help, that does stop the loop like i was looking for, however there is an issue with the script right now. the script starts everytime you take damage, (which its written to do, trying to think a way around that) right now I'm using the cod2 _healthoverlay.gsc with the regen part of the script like this:
    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();
         }     
    }


    If you could help me make sense of how the cod2 one works so i can get it to work for UO, it'd be greatly appriciated. Thanks for the help Tally (i believe thats it) I'll be sure to credit you for your help.
  • Re: Scripting Error, need help
    Download this:

    http://demon-mod.com/downloads/uo_healthregen.zip

    That is the basis of a port of COD2's health regen code to UO. In order for it to work, I had to put in COD2 player notifications in the UO TDM gametype script as it didn't have them at the time UO was made. So, you will have to do the same with the other UO gametypes, otherwise it work work when you play those gametypes.

    Also included are the breathing sounds from COD2, but although they play, they need a little work.

    You will need to work on a player hud for a damage screen, and get it to pulse (just toggle the hud alpha setting from 0.8 to 0, and back again, over time).
  • Re: Scripting Error, need help
    [EW]TheO'ReilyFactor
    Hey thanks again for the help Tally. Just to check to make sure. Is this the only line i need to add to make the other gametypes to work?

         // Tally
         maps\mp\gametypes\_healthRegen::init();


    Because TDM works but with the other gametypes i get the breathing sounds but no regen, the only thing i can think of is that there's more that i need to add more than just that because  when i try to just add that line i get breathing but no healing.

    Sorry I'm basically making you write the whole mod for me....