DMH-Online

Dungeon Masters Helper · Est. 2005

Misc Scripts

NWN Script: xp_gold_loss_002.htm

Author Sticky: Post Working Scripts Here
Grus Posted: Friday, 28 June 11:19PM
NWScript:
void ApplyPercentPenalty(object oDead,
                         float flPenaltyXP,
                         float flPenaltyGold)
{
  // Written by Grus Kel'fer - grus1968@yahoo.com
  // I used the ApplyPenalty script in the handbook,
  // P. 30 as a template.
  // This function is called to subract a percentage of
  // the PC's experience and gold.
  // Usage Example (called from OnRespawn script):
  // ApplyPercentPenalty(oDead, .10, .30);
  // This call would subract 10% of the PC's XP, and
  // 30% of the PC's gold.
  // Error check penalty arguments to make sure they
  // are between 0 and 1.0 inclusive.
  flPenaltyXP = flPenaltyXP < 0.0 ? 0.0 : flPenaltyXP;
  flPenaltyXP = flPenaltyXP > 1.0 ? 1.0 : flPenaltyXP;
  flPenaltyGold = 
            flPenaltyGold < 0.0 ? 0.0 : flPenaltyGold;
  flPenaltyGold = 
            flPenaltyGold > 1.0 ? 1.0 : flPenaltyGold;
  
  // Get current PC experience and level
  int nCurrentXP = GetXP(oDead);
  int nCharacterLevel = GetHitDice(oDead);
  // Compute new experience points based on penalty
  int nLostXP = FloatToInt(flPenaltyXP*nCurrentXP);
  int nNewXP = nCurrentXP - nLostXP;
  // Make sure new PC experience points do not cause a 
  // level loss
  int nLowerBoundXP = ((nCharacterLevel *
                       (nCharacterLevel-1)) /
                        2 * 1000);
  nNewXP = 
        nNewXP < nLowerBoundXP ? nLowerBoundXP : nNewXP;
  // Set new XP, and take gold based on penalty
  SetXP(oDead, nNewXP);
  AssignCommand(oDead,
                TakeGoldFromCreature(FloatToInt(
                    flPenaltyGold * GetGold(oDead)),
                    oDead, TRUE));
}
⌂ All Scripts ← PreviousNext → 👁 Category List

All Misc Scripts

📄 arena 📄 cast_bless_on_PC 📄 change_music 📄 chess_game 📄 climbing 📄 climbing_002 📄 common_includes_002 📄 cone_aoe 📄 cron 📄 cross_country_travel 📄 daoc_style_graves 📄 determine_time 📄 effects 📄 escort 📄 ez_respawn 📄 faction 📄 floating_text 📄 function_includes 📄 gambling 📄 include_sounds 📄 include_time_date 📄 jail 📄 jail_system 📄 journal_entry 📄 logbook 📄 manage_action_queue 📄 mmorpg_vault 📄 mod_intro 📄 mod_intro_002 📄 mod_intro_003 📄 mod_intro_005 📄 pers_world_database 📄 pers_world_database_002 📄 piller_of_fire 📄 plot_item 📄 portal_system 📄 portal_system_002 📄 puking 📄 quest_escort 📄 rep_per 📄 reward_rp 📄 rotation 📄 save_pc_location_002 📄 save_pc_location_003 📄 skill_checks 📄 skill_checks_002 📄 slot_machine 📄 story 📄 swimming 📄 take20_bypass 📄 vis_waypoint 📄 working_temple 📄 working_temple_002 📄 xp_gold_loss 📄 xp_gold_loss_002 📄 xp_loss_action