DMH-Online

Dungeon Masters Helper · Est. 2005

Creatures Scripts

NWN Script: random_hps.htm

Author Sticky: Post Working Scripts Here
Spike- Posted: Saturday, 06 July 04:01PM
1. Random Hitpoints for Creatures

2. What it does: Rolls up Random hitpoint totals for your creatures, then applies them.

3. Notes: This should be used OnEnter the area/module (it can be adapted to other places). There are of course some issues with this script -- Since Bioware did not include anyway to actually Set the Max hitpoints for a creature (doh!), I had to use Damage effects for creatures that have less than default hitpoints (so they can 'heal' above their new 'Max' unfortunately), and temporary hitpoints (applied permanently though) for #s above default. If someone knows a better way, please fix this up and repost.
I just commented out a few debug lines, feel free to uncomment the PrintString lines to see a little more of what is happening (in the log file).

I also ignored PCs entering, and "Playable" races, because these are the most likely to be NPCs (though a better way might be to check for any 'classes' instead)

Also while doing this, I noticed that the DM Client doesn't show current hitpoints above Max, so even though the Chooser might say 4/4 Hps for an Orc, that Orc might actually have 5 or 8 hitpoints.

NWScript:
//:://////////////////////////////////////////////////////
//:: Random HitPoints for Creatures (OnEnter module)
//:: Copyright (c) 2002 Me
//:://////////////////////////////////////////////////////
//:: Created By: Spike (SpikeZOM@yahoo.com)
//:: Created On: July 6, 2002
//:://////////////////////////////////////////////////////

void main()
{
  object oCreature = GetEnteringObject();
  if( GetIsPC(oCreature) ) return;
  int nHD = GetHitDice(oCreature);
  int nRacialType = GetRacialType(oCreature);
  int nConstMod = GetAbilityModifier(ABILITY_CONSTITUTION, oCreature);
  //don't apply negative modifier
  if( nConstMod < 0 ) nConstMod = 0;
  int nMax = GetMaxHitPoints(oCreature);
  int nNewHP;
  int nDie;
  //assume these are NPCs, so ignore -- may be better to check for classes
  if( (nRacialType == RACIAL_TYPE_DWARF) || (nRacialType == RACIAL_TYPE_ELF) ||
      (nRacialType == RACIAL_TYPE_GNOME) || (nRacialType == RACIAL_TYPE_HALFELF) ||
      (nRacialType == RACIAL_TYPE_HALFLING) || (nRacialType == RACIAL_TYPE_HALFORC) ||
      (nRacialType == RACIAL_TYPE_HUMAN) || (nRacialType == RACIAL_TYPE_INVALID))
   {
     //PrintString("RacialType NPC/Other" + " for " + GetName(oCreature));
     return;
   }
  else if( (nRacialType == RACIAL_TYPE_ABERRATION) || (nRacialType == RACIAL_TYPE_ANIMAL) ||
           (nRacialType == RACIAL_TYPE_ELEMENTAL) || (nRacialType == RACIAL_TYPE_GIANT) ||
           (nRacialType == RACIAL_TYPE_HUMANOID_GOBLINOID) || (nRacialType == RACIAL_TYPE_HUMANOID_MONSTROUS) ||
           (nRacialType == RACIAL_TYPE_HUMANOID_ORC) || (nRacialType == RACIAL_TYPE_HUMANOID_REPTILIAN) ||
           (nRacialType == RACIAL_TYPE_OUTSIDER) || (nRacialType == RACIAL_TYPE_SHAPECHANGER) ||
           (nRacialType == RACIAL_TYPE_VERMIN))
  {
    nDie = 8;
    //PrintString("RacialType 8" + " for " + GetName(oCreature));
  }
  else if( (nRacialType == RACIAL_TYPE_BEAST) || (nRacialType == RACIAL_TYPE_CONSTRUCT) ||
           (nRacialType == RACIAL_TYPE_MAGICAL_BEAST))
       {
        nDie = 10;
        //PrintString("RacialType 10" + " for " + GetName(oCreature));
       }
  else if( (nRacialType == RACIAL_TYPE_DRAGON) || (nRacialType == RACIAL_TYPE_UNDEAD))
       {
        nDie = 12;
        //PrintString("RacialType 12" + " for " + GetName(oCreature));
       }
  else
    {
        nDie = 6;
        //PrintString("Racial Type Else(6)");
    }
    //Roll for random hitpoints
    if( nDie == 8 )
    {
        nNewHP = d8(nHD) + (nConstMod * nHD);
    }
    else if (nDie == 10)
         {
            nNewHP = d10(nHD) + (nConstMod * nHD);
         }
    else if (nDie == 12)
         {
            nNewHP = d12(nHD) + (nConstMod * nHD);
         }
    else
        {
            nNewHP = d6(nHD) + (nConstMod * nHD);
        }
    //PrintString("Rolled: " + IntToString(nNewHP) + " for " + GetName(oCreature));
    //Make it so..
    if(nNewHP > nMax)
    {
        int nChange = nNewHP - nMax;
        effect eTempHP = EffectTemporaryHitpoints(nChange);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eTempHP, oCreature, 0.0);
        //PrintString("Temp Applied: " + IntToString(nChange));
        //PrintString("Applied Temp Effect");
    }
    else if(nNewHP < nMax)
    {
        int nChange = nMax - nNewHP;
        effect eDmg = EffectDamage(nChange);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eDmg, oCreature);
        //PrintString("Damage Applied: " + IntToString(nChange));
        //PrintString("Applied Damage Effect");
    }
    else
    {
        nNewHP = nMax;
        //PrintString("No Change");
    }
}



_________________
Braeunk vhos trolkh!

⌂ All Scripts ← PreviousNext → 👁 Category List

All Creatures Scripts

📄 apply_spell_effect 📄 aurak_draconian 📄 baaz_draconian 📄 boss_spawner 📄 change_light_spawn_pt_on_death 📄 clone_mob 📄 collect_loot 📄 create_unique_objectIDs 📄 creature_proc 📄 explode_ondeath 📄 explode_ondeath_002 📄 explode_ondeath_003 📄 exploding_chickens 📄 fire_death 📄 inverse_mob 📄 iron_statue 📄 lich 📄 lootable_corpse 📄 lootable_corpse_002 📄 lootable_corpse_002a 📄 lootable_corpse_oo2 📄 mob_respawn 📄 mob_respawn_002 📄 multi_creature_spawn 📄 night_time 📄 random_death_effect 📄 random_drops 📄 random_drops_002 📄 random_drops_003 📄 random_enc_onrest 📄 random_hps 📄 sivac_draconian 📄 spawn 📄 spawn_on_hearbeat 📄 summon_last_hostile 📄 summon_mob 📄 trolls 📄 trolls_002 📄 vampire_coffin 📄 werewolf