DMH-Online

Dungeon Masters Helper · Est. 2005

Misc Scripts

NWN Script: common_includes_002.htm

Author Sticky: Post Working Scripts Here
SDxEair Posted: Thursday, 18 July 10:16AM
Several Useful Functions, I will Add to this file as I go, it currently includes:

object GetFirstPCInArea(object oAreaTest)

object GetNextPCInArea(object oAreaTest)

location OffSetLocation(location lPlayer)

int GetAreaPCCount(object oArea)

object GetRandomPCInArea(object oArea)

All the info is in the script!

NWScript:
//Include File by Eair
//Email: indy37@earthlink.net
//7/18/02
//Note: currently working on a Random Encounter Generator that gets as close to
//the tables in the DMG as possible, it works at the moment but only impelmented
//Table 4-15: 1st-Level Dungeon Encounters
//If anyone creates monsters for the Tables that arn't in NWN(theres a lot)
//Pls Tell me.

//Gets the First PC in oArea
object GetFirstPCInArea(object oAreaTest)
{
    object oPCTestValid = GetFirstPC();
    while(GetArea(oPCTestValid)!=oAreaTest&&GetIsObjectValid(oPCTestValid))
        oPCTestValid = GetNextPC();
    return(oPCTestValid);
}
//Gets the Next PC in oArea
object GetNextPCInArea(object oAreaTest)
{
    object oPCTestValid = GetNextPC();
    while(GetArea(oPCTestValid)!=oAreaTest&&GetIsObjectValid(oPCTestValid))
        oPCTestValid = GetNextPC();
    return(oPCTestValid);
}
//OffSet's a location by 10 in one of 8 dirrections(random)
//And Points fFacing towards the original location
location OffSetLocation(location lPlayer)
{
  //Excerpt from...
//:://////////////////////////////////////////////////////
//:: PnP Random Encounters
//:://////////////////////////////////////////////////////
/*
    This Script Generates Old School Random Encounters
    like the ones from a random encounter table in a PnP
    module
*/
//:://////////////////////////////////////////////////////
//:: Created By: LuckDragon
//:://////////////////////////////////////////////////////
  int iDirection=d8();
  float fX;
  float fY;
  float fF;//Added by Eair
  switch(iDirection) {
    case 1:  // North
      fX=0.0; fY=10.0; fF=270.0;
      break;
    case 2:  // South
      fX=0.0; fY=-10.0; fF=90.0;
      break;
    case 3:  // East
      fX=10.0; fY=0.0; fF=180.0;
      break;
    case 4:  // West
      fX=-10.0; fY=0.0; fF=0.0;
      break;
    case 5:  // Northeast
      fX=10.0; fY=10.0; fF=225.0;
      break;
    case 6:  // Southeast
      fX=10.0; fY=-10.0; fF=135.0;
      break;
    case 7:  // Southwest
      fX=-10.0; fY=-10.0; fF=45.0;
      break;
    case 8:  // Northwest
      fX=-10.0; fY=10.0; fF=315.0;
      break;
  }
  object oTemp = GetAreaFromLocation(lPlayer);//Added by Eair
  vector vStart = GetPositionFromLocation(lPlayer);
  vector vOffset = Vector(fX,fY);
  vector vEndvector = vStart+vOffset;
  location lEndLocation = Location(oTemp,vEndvector,fF);//Added by Eair
  return(lEndLocation);
  //End of Excerpt!
}
//Gets the number of PC's in oArea
int GetAreaPCCount(object oArea)
{
    int iPCCount=0;
    object oPCTest = GetFirstPCInArea(oArea);
    while(GetIsObjectValid(oPCTest))
    {
        oPCTest = GetNextPCInArea(oArea);
        iPCCount++;
    }
    return(iPCCount);
}
//Gets a Random PC in oArea
//Will return OBJECT_INVALID if no PC's are in the Area
object GetRandomPCInArea(object oArea)
{
    int iRandomPCNumber = d100();/*This Assumes theres no more than 100 people
    in the Area, and there probly won't be in most servers. if you expect more,
    change d100() to d100(X)-X, it might not be exact... if you want better make
    your own random number generator*/
    while(iRandomPCNumber>GetAreaPCCount(oArea))
        iRandomPCNumber = d100();
    object oReturnPC = GetFirstPCInArea(oArea);
    int iCounter = 0;
    while(iCounter<iRandomPCNumber&&GetIsObjectValid(oReturnPC))
    {
        GetNextPCInArea(oArea);
        if(!GetIsObjectValid(oReturnPC))
            GetFirstPCInArea(oArea);
        iCounter++;
    }
    return(oReturnPC);
}
⌂ 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