Skip navigation
1748 Views 5 Replies Latest reply: Aug 2, 2011 1:54 AM by dante2010 RSS
[EW]TheO\'ReilyFactor Apprentice 373 posts since
Oct 5, 2011
Currently Being Moderated

Jul 30, 2011 11:36 PM

Scripting Error, need help

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

  • dante2010 Apprentice 745 posts since
    Sep 23, 2011
    Currently Being Moderated
    Jul 31, 2011 2:10 AM (in response to [EW]TheO\'ReilyFactor)
    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.
  • dante2010 Apprentice 745 posts since
    Sep 23, 2011
    Currently Being Moderated
    Aug 1, 2011 2:50 AM (in response to [EW]TheO\'ReilyFactor)
    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).
  • dante2010 Apprentice 745 posts since
    Sep 23, 2011
    Currently Being Moderated
    Aug 2, 2011 1:54 AM (in response to [EW]TheO\'ReilyFactor)
    Re: Scripting Error, need help

Bookmarked By (0)