This partial implementation of the sample script includes wrappers for the high level NWScript functions. You should include the wrappers in your script object type.
        public static void JumpToArea(CLRScriptBase script, User currentUser)
        {
            uint currentArea = script.GetArea(currentUser.Id);
            if (!ALFA.Shared.Modules.InfoStore.ActiveAreas.Keys.Contains(currentUser.Id))
            {

            }

            // If this is an adjacent area, jump the DM to one of the ATs connecting the areas.
            foreach (ALFA.Shared.ActiveTransition exitTranstion in ALFA.Shared.Modules.InfoStore.ActiveAreas[currentArea].ExitTransitions.Keys)
            {
                if (exitTranstion.AreaTarget.Id == currentUser.FocusedArea)
                {
                    script.JumpToLocation(script.GetLocation(exitTranstion.Target));
                    return;
                }
            }

            // If these aren't adjacent areas, grab an AT if we can find one.
            if (ALFA.Shared.Modules.InfoStore.ActiveAreas[currentUser.FocusedArea].ExitTransitions.Count > 0)
            {
                foreach(ALFA.Shared.ActiveTransition enterTransition in ALFA.Shared.Modules.InfoStore.ActiveAreas[currentUser.FocusedArea].ExitTransitions.Keys)
                {
                    script.JumpToLocation(script.GetLocation(enterTransition.Id));
                    return;
                }
            }

            // If we can't find one, just try the middle of the area.
            float x = script.GetAreaSize(AREA_WIDTH, currentUser.FocusedArea) / 2;
            float y = script.GetAreaSize(AREA_HEIGHT, currentUser.FocusedArea) / 2;
            float z = 0.0f;
            NWLocation loc = script.Location(currentUser.FocusedArea, script.Vector(x, y, z), 0.0f);
            script.JumpToLocation(loc);
        }
 public static void DrawNavigatorCategory(CLRScriptBase script, NavigatorCategory nav)
 {
     if (nav != null)
     {
         script.ClearListBox(script.OBJECT_SELF, "SCREEN_DMC_CREATOR", "LISTBOX_ACR_CREATOR");
         if (nav.ParentCategory != null)
         {
             string textFields = "LISTBOX_ITEM_TEXT=  ..";
             string variables = "5=Category:..";
             script.AddListBoxRow(script.OBJECT_SELF, "SCREEN_DMC_CREATOR", "LISTBOX_ACR_CREATOR", "Category:..", textFields, "LISTBOX_ITEM_ICON=folder.tga", variables, "unhide");
         }
         foreach (NavigatorCategory navCat in nav.ContainedCategories)
         {
             string textFields = String.Format("LISTBOX_ITEM_TEXT=  {0}", navCat.DisplayName);
             string variables = String.Format("5={0}", "Category:" + navCat.Name);
             script.AddListBoxRow(script.OBJECT_SELF, "SCREEN_DMC_CREATOR", "LISTBOX_ACR_CREATOR", "Category:" + navCat.Name, textFields, "LISTBOX_ITEM_ICON=folder.tga", variables, "unhide");
         }
         foreach (IListBoxItem navItem in nav.ContainedItems)
         {
             script.AddListBoxRow(script.OBJECT_SELF, "SCREEN_DMC_CREATOR", "LISTBOX_ACR_CREATOR", navItem.RowName, navItem.TextFields, navItem.Icon, navItem.Variables, "unhide");
         }
     }
     else
     {
         script.SendMessageToPC(script.OBJECT_SELF, "Error: Navigator category is null. Cannot draw a list.");
     }
 }
        public static void Enter(CLRScriptBase s, ALFA.Shared.ActiveTrap trap)
        {
            uint enterer = s.GetEnteringObject();

            if (trap.IsFiring)
            {
                // Trap's already firing. It'll reset when it runs out of targets.
                return;
            }

            // If one is enough, we don't need to check the trigger's contents.
            if (trap.MinimumToTrigger == 1)
            {
                if (FitsTrapTargetRestriction(s, trap, enterer))
                {
                    Fire(s, trap);
                }
            }
            else
            {
                int validTargets = 0;
                foreach (uint contents in s.GetObjectsInPersistentObject(s.GetObjectByTag(trap.Tag, 0), OBJECT_TYPE_CREATURE, 0))
                {
                    if (FitsTrapTargetRestriction(s, trap, contents))
                    {
                        validTargets++;
                    }
                }
                if (validTargets >= trap.MinimumToTrigger)
                {
                    Fire(s, trap);
                }
            }
        }
 private void stripProperties(CLRScriptBase script, uint item)
 {
     for (ItemProperty ip = script.GetFirstItemProperty(item); script.GetIsItemPropertyValid(ip) == CLRScriptBase.TRUE; ip = script.GetNextItemProperty(item))
     {
         script.RemoveItemProperty(item, ip);
     }
 }
 private static void DetectHeartBeat(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint detector)
 {
     if (IsTrapDetectedBy(s, trap, detector))
     {
         HandleTrapDetected(s, trap, detector);
     }
 }
        private static bool IsTrapDetectedBy(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint detector)
        {
            if (trap.Detected)
            {
                return false;
            }
            if(!IsInArea(s, trap, detector))
            {
                return false;
            }

            if (s.GetDetectMode(detector) == FALSE)
            {
                s.DelayCommand(6.0f, delegate { DetectHeartBeat(s, trap, detector); });
                return false;
            }

            if (trap.DetectDC > 20 &&
                s.GetLevelByClass(CLASS_TYPE_ROGUE, detector) == FALSE &&
                s.GetHasSpellEffect(SPELL_FIND_TRAPS, detector) == FALSE)
            {
                s.DelayCommand(6.0f, delegate { DetectHeartBeat(s, trap, detector); }); 
                return false;
            }

            int searchBonus = s.GetSkillRank(SKILL_SEARCH, detector, FALSE);
            int roll = s.d20(1);
            int finalDice = roll + searchBonus;
            if (trap.DetectDC <= finalDice)
            {
                return true;
            }
            s.DelayCommand(6.0f, delegate { DetectHeartBeat(s, trap, detector); });
            return false;
        }
 public static void DrawAreas(CLRScriptBase script, User currentUser)
 {
     script.ClearListBox(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_AREAS");
     if (ALFA.Shared.Modules.InfoStore.ActiveAreas.Keys.Contains(script.GetArea(currentUser.Id)))
     {
         ALFA.Shared.ActiveArea currentArea = ALFA.Shared.Modules.InfoStore.ActiveAreas[script.GetArea(currentUser.Id)];
         string currentName = "<Color=DarkOrange>" + currentArea.DisplayName + "________";
         DisplayString.ShortenStringToWidth(currentName, 250);
         currentName = currentName.Trim('_') + "</color>";
         script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_AREAS", currentArea.Id.ToString(), "LISTBOX_ITEM_TEXT=  "+currentName, "", "5="+currentArea.Id.ToString(), "");
         List<ALFA.Shared.ActiveArea> adjAreas = new List<ALFA.Shared.ActiveArea>();
         foreach (ALFA.Shared.ActiveArea adjacentArea in currentArea.ExitTransitions.Values)
         {
             if (!adjAreas.Contains(adjacentArea))
             {
                 string adjName = "<Color=DarkGoldenRod>" + adjacentArea.DisplayName + "________";
                 DisplayString.ShortenStringToWidth(adjName, 250);
                 adjName = adjName.Trim('_') + "</color>";
                 script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_AREAS", adjacentArea.Id.ToString(), "LISTBOX_ITEM_TEXT=  " + adjName, "", "5=" + adjacentArea.Id.ToString(), "");
                 adjAreas.Add(adjacentArea);
             }
         }
     }
     foreach (ALFA.Shared.ActiveArea area in AreaList)
     {
         script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_AREAS", area.Id.ToString(), "LISTBOX_ITEM_TEXT=  " + area.DisplayName, "", "5=" + area.Id.ToString(), "");
     }
     currentUser.LastSeenArea = script.GetArea(currentUser.Id);
 }
 public static DisableResult IsDisableSuccessful(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, int DC, uint disabler)
 {
     if (s.GetSkillRank(SKILL_DISABLE_TRAP, disabler, TRUE) == 0)
     {
         s.SendMessageToPC(disabler, "<c=#98FFFF>Disable Device: * Success will never be possible *</c>");
         return DisableResult.Failure;
     }
     
     int roll = s.d20(1);
     int skill = s.GetSkillRank(SKILL_DISABLE_TRAP, disabler, FALSE) + trap.TotalHelp;
     int final = roll + skill;
     string resultString = "Failure!";
     DisableResult value = DisableResult.Failure;
     if (final >= DC)
     {
         value = DisableResult.Success;
         resultString = "Success!";
     }
     if (DC > final + 4)
     {
         value = DisableResult.CriticalFailure;
         resultString = "CRITICAL FAILURE!";
     }
     string message = String.Format("<c=#98FFFF>Disable Device : {0} + {1} = {2} vs. DC {3}. * {4} *</c>", roll, skill, final, DC, resultString);
     s.SendMessageToPC(disabler, message);
     
     return value;
 }
        public static void MountHorse(CLRScriptBase script, uint Character, uint Horse)
        {
            if (!isWarhorse.ContainsKey(Character)) isWarhorse.Add(Character, true);

            string cloakResRef;
            switch(script.GetTag(Horse))
            {
                case "abr_cr_an_horse01":
                    cloakResRef = "acr_ooc_horse01";
                    isWarhorse[Character] = true;
                    break;
                case "abr_cr_an_horse02":
                    cloakResRef = "acr_ooc_horse02";
                    isWarhorse[Character] = true;
                    break;
                case "abr_cr_an_horse03":
                    cloakResRef = "acr_ooc_horse03";
                    isWarhorse[Character] = true;
                    break;
                default:
                    cloakResRef = "acr_ooc_horse03";
                    isWarhorse[Character] = true;
                    break;
            }
            
            uint horseCloak = script.CreateItemOnObject(cloakResRef, Character, 1, "", CLRScriptBase.FALSE);
            if (script.GetLocalInt(Horse, ACR_IS_WARHORSE) == 1)
            {
                script.RemoveHenchman(Character, Horse);
                script.SetLocalInt(horseCloak, ACR_IS_WARHORSE, 1);
            }
            script.SetLocalInt(horseCloak, ACR_HORSE_ID, script.GetLocalInt(Horse, ACR_HORSE_ID));
            script.SetLocalInt(horseCloak, ACR_HORSE_HP, script.GetCurrentHitPoints(Horse));

            uint equippedCloak = script.GetItemInSlot(CLRScriptBase.INVENTORY_SLOT_CLOAK, Character);
            
            if (script.GetIsObjectValid(equippedCloak) == CLRScriptBase.TRUE)
            {
                foreach (NWItemProperty prop in script.GetItemPropertiesOnItem(equippedCloak))
                {
                    // copying property duration type prevents us from turning temporary properties into
                    // permanent ones. But because we don't know how long the non-permanent ones have left,
                    // we pretty much have to assign them with the expectation that they immediately expire.
                    script.AddItemProperty(script.GetItemPropertyDurationType(prop), prop, horseCloak, 0.0f);
                }
                script.SetFirstName(horseCloak, script.GetName(equippedCloak) + "(( Horse Appearance ))");
                script.AddItemProperty(CLRScriptBase.DURATION_TYPE_PERMANENT, script.ItemPropertyWeightReduction(CLRScriptBase.IP_CONST_REDUCEDWEIGHT_80_PERCENT), horseCloak, 0.0f);
            }
            script.SetPlotFlag(horseCloak, CLRScriptBase.TRUE);
            script.SetPlotFlag(Horse, CLRScriptBase.FALSE);
            
            script.AssignCommand(Horse, delegate { script.SetIsDestroyable(CLRScriptBase.TRUE, CLRScriptBase.FALSE, CLRScriptBase.FALSE); });
            script.AssignCommand(Horse, delegate { script.DestroyObject(Horse, 0.0f, CLRScriptBase.FALSE); });
            script.AssignCommand(Character, delegate { script.ActionEquipItem(horseCloak, CLRScriptBase.INVENTORY_SLOT_CLOAK); });

            if (!isWarhorse[Character]) script.DelayCommand(6.0f, delegate { RidingHeartbeat(script, Character); });
        }
        public static void Enter(CLRScriptBase s, ALFA.Shared.ActiveTrap trap)
        {
            uint enteringObject = s.GetEnteringObject();

            if (IsTrapDetectedBy(s, trap, enteringObject))
            {
                HandleTrapDetected(s, trap, enteringObject);
            }
        }
 public static void DrawListBox(CLRScriptBase script, List<IListBoxItem> resource)
 {
     // TODO: Remove the last frame of the 'thinking' animation.
     if(resource != null)
     {
         foreach (IListBoxItem item in resource)
         {
             script.AddListBoxRow(script.OBJECT_SELF, "SCREEN_DMC_CREATOR", "LISTBOX_ACR_CREATOR", item.RowName, item.TextFields, item.Icon, item.Variables, "unhide");
         }
     }
 }
 public static void SearchAreas(CLRScriptBase script, User currentUser, string searchString)
 {
     script.ClearListBox(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_AREAS");
     foreach (ALFA.Shared.ActiveArea area in AreaList)
     {
         if (area.LocalizedName.ToLower().Contains(searchString.ToLower()))
         {
             script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_AREAS", area.Id.ToString(), "LISTBOX_ITEM_TEXT=  " + area.DisplayName, "", "5=" + area.Id.ToString(), "");
         }
     }
 }
        public static void WaitForSearch(CLRScriptBase script, User currentUser, ACR_ChooserCreator.ACR_CreatorCommand currentTab, CreatorSearch awaitedSearch)
        {
            if (awaitedSearch == null)
            {
                // Search has been removed. Abort.
                return;
            }
            if (awaitedSearch.CancellationPending)
            {
                // Search has been canceled. Abort.
                return;
            }
            if (currentUser.openCommand != currentTab)
            {
                // User has switched tabs. Kill the search.
                return;
            }
            if (currentUser.CreatorSearchResponse != null)
            {
                // Looks like we've finished. Draw a list!
                CreatorSearch oldSearch = currentUser.CurrentSearch;
                currentUser.CurrentSearch = null;
                oldSearch.Dispose();

                Waiter.DrawNavigatorCategory(script, currentUser.CreatorSearchResponse);
                switch (currentUser.openCommand)
                {
                    case ACR_ChooserCreator.ACR_CreatorCommand.ACR_CHOOSERCREATOR_FOCUS_CREATURE_TAB:
                        currentUser.CurrentCreatureCategory = currentUser.CreatorSearchResponse;
                        break;
                    case ACR_ChooserCreator.ACR_CreatorCommand.ACR_CHOOSERCREATOR_FOCUS_ITEM_TAB:
                        currentUser.CurrentItemCategory = currentUser.CreatorSearchResponse;
                        break;
                    case ACR_ChooserCreator.ACR_CreatorCommand.ACR_CHOOSERCREATOR_FOCUS_LIGHTS_TAB:
                        currentUser.CurrentLightCategory = currentUser.CreatorSearchResponse;
                        break;
                    case ACR_ChooserCreator.ACR_CreatorCommand.ACR_CHOOSERCREATOR_FOCUS_PLACEABLE_TAB:
                        currentUser.CurrentPlaceableCategory = currentUser.CreatorSearchResponse;
                        break;
                    case ACR_ChooserCreator.ACR_CreatorCommand.ACR_CHOOSERCREATOR_FOCUS_TRAP_TAB:
                        currentUser.CurrentTrapCategory = currentUser.CreatorSearchResponse;
                        break;
                    case ACR_ChooserCreator.ACR_CreatorCommand.ACR_CHOOSERCREATOR_FOCUS_VFX_TAB:
                        currentUser.CurrentVisualEffectCategory = currentUser.CreatorSearchResponse;
                        break;
                    case ACR_ChooserCreator.ACR_CreatorCommand.ACR_CHOOSERCREATOR_FOCUS_WAYPOINT_TAB:
                        currentUser.CurrentWaypointCategory = currentUser.CreatorSearchResponse;
                        break;
                }
                return;
            }
            script.DelayCommand(1.0f, delegate { WaitForSearch(script, currentUser, currentTab, awaitedSearch); });
        }
        public static void GenericDamage(CLRScriptBase script, NWLocation location, TriggerArea triggerArea, int effectArea, float effectSize, int damageType, int diceNumber, int diceType, int saveDC, int attackBonus, int numberOfShots, uint trapOrigin, int targetAlignment, int targetRace, int minimumToTrigger, int detectDC, int disarmDC, string description)
        {
            string tag = uniqueTrapTag();
            string detectTag = tag + detectSuffix();
            
            script.ApplyEffectAtLocation(DURATION_TYPE_PERMANENT,
                script.SupernaturalEffect(script.EffectAreaOfEffect(triggerAreaToAreaOfEffect(triggerArea), "acr_traponenter", "****", "acr_traponexit", tag)),
                location,
                0.0f);

            script.ApplyEffectAtLocation(DURATION_TYPE_PERMANENT,
                script.SupernaturalEffect(script.EffectAreaOfEffect(triggerAreaToDetectArea(triggerArea), "acr_trapdtctenter", "****", "acr_trapdtctexit", detectTag)),
                location,
                0.0f);

            ALFA.Shared.ActiveTrap createdTrap = new ALFA.Shared.ActiveTrap();
            createdTrap.AreaName = script.GetName(script.GetAreaFromLocation(location));
            createdTrap.AttackBonus = attackBonus;
            createdTrap.ChallengeRating = 0.0f;
            createdTrap.DamageType = damageType;
            createdTrap.DetectTag = detectTag;
            createdTrap.DiceNumber = diceNumber;
            createdTrap.DiceType = diceType;
            createdTrap.EffectArea = effectArea;
            createdTrap.EffectSize = effectSize;
            createdTrap.Location = location;
            createdTrap.MinimumToTrigger = minimumToTrigger;
            createdTrap.NumberOfShots = numberOfShots;
            createdTrap.SaveDC = saveDC;
            createdTrap.SpellTrap = false;
            createdTrap.Tag = tag;
            createdTrap.TargetAlignment = targetAlignment;
            createdTrap.TargetRace = targetRace;
            createdTrap.TrapTriggerVFX = triggerAreaToTrapVFX(triggerArea);
            createdTrap.DetectDC = detectDC;
            createdTrap.DisarmDC = disarmDC;
            createdTrap.Detected = false;
            createdTrap.Disabler = 0;
            createdTrap.Helpers = new List<uint>();
            createdTrap.TotalHelp = 0;
            createdTrap.IsFiring = false;
            createdTrap.Description = description;
            createdTrap.ConfigureDisplayName();
            createdTrap.CalculateCR();

            createdTrap.TrapOrigin = GetNearestTrapEmitter(script, location);

            ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect.Add(detectTag, createdTrap);
            ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers.Add(tag, createdTrap);

            script.SetLocalString(script.GetModule(), "ACR_TRAPS_LAST_TAG", tag);
        }
 private uint getHide( CLRScriptBase script )
 {
     uint oHide = script.GetItemPossessedBy(m_oCreature, "acr_pchide");
     if (script.GetIsObjectValid(oHide) == CLRScriptBase.FALSE)
     {
         oHide = script.GetItemInSlot(CLRScriptBase.INVENTORY_SLOT_CARMOUR, m_oCreature);
         if (script.GetIsObjectValid(oHide) == CLRScriptBase.FALSE || script.GetResRef(oHide) != "acr_pchide")
         {
             oHide = CLRScriptBase.OBJECT_INVALID;
         }
     }
     return oHide;
 }
 public static void InitializeButtons(CLRScriptBase script, User currentUser)
 {
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_AOE", currentUser.ChooserShowAOE ? "trap.tga" : "notrap.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_CREATURE", currentUser.ChooserShowCreature ? "creature.tga" : "nocreature.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_DOOR", currentUser.ChooserShowDoor ? "door.tga" : "nodoor.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_ITEM", currentUser.ChooserShowItem ? "item.tga" : "noitem.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_LIGHT", currentUser.ChooserShowLight ? "light.tga" : "nolight.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_PLACEABLE", currentUser.ChooserShowPlaceable ? "placeable.tga" : "noplaceable.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_STORE", currentUser.ChooserShowStore ? "store.tga" : "nostore.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_TRIGGER", currentUser.ChooserShowTrigger ? "trigger.tga" : "notrigger.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_VFX", currentUser.ChooserShowPlacedEffect ? "vfx.tga" : "novfx.tga");
     script.SetGUITexture(currentUser.Id, "SCREEN_DMC_CHOOSER", "SHOW_WAYPOINT", currentUser.ChooserShowWaypoint ? "waypoint.tga" : "nowaypoint.tga");
 }
 public static void WaitForResources(CLRScriptBase script, IBackgroundLoadedResource resource)
 {
     if (resource.WaitForResourcesLoaded(false) == true)
     {
         DrawListBox(script, (resource as IDrawableList).ListBox);
         return;
     }
     else
     {
         // TODO: Display the 'thinking' animation.
         script.DelayCommand(0.5f, delegate() { WaitForResources(script, resource); });
         return;
     }
 }
 public static void WaitForNavigator(CLRScriptBase script, Navigator nav)
 {
     if (nav.WaitForResourcesLoaded(false) == true)
     {
         DrawNavigatorCategory(script, nav.bottomCategory);
         return;
     }
     else
     {
         script.SendMessageToPC(script.OBJECT_SELF, "loading...");
         script.DelayCommand(0.5f, delegate() { WaitForNavigator(script, nav); });
         return;
     }
 }
        /// <summary>
        /// Flush any buffered log messages to the server main log file.
        /// 
        /// N.B.  The current time is used as the log message time stamp.  It
        ///       is assumed that the caller invokes the FlushLogMessages()
        ///       function sufficiently often that the time stamp is "close
        ///       enough" to meet.
        /// </summary>
        /// <param name="Script">Supplies the CLR script object.</param>
        public static void FlushLogMessages(CLRScriptBase Script)
        {
            lock (LogMessages)
            {
                if (LogMessages.Count == 0)
                    return;

                foreach (string Message in LogMessages)
                {
                    Script.WriteTimestampedLogEntry(Message);
                }

                LogMessages.Clear();
            }
        }
 public static void SortLists(CLRScriptBase script)
 {
     if(!ALFA.Shared.Modules.InfoStore.WaitForResourcesLoaded(false))
     {
         script.DelayCommand(6.0f, delegate { SortLists(script); });
         return;
     }
     if (ALFA.Shared.Modules.InfoStore.ActiveAreas == null)
     {
         script.DelayCommand(2.0f, delegate { SortLists(script); });
         return;
     }
     AreaList = ALFA.Shared.Modules.InfoStore.ActiveAreas.Values.ToList<ALFA.Shared.ActiveArea>();
     AreaList.Sort();
 }
 public bool clear(CLRScriptBase script)
 {
     if (script.GetIsObjectValid(m_oCreature) == CLRScriptBase.FALSE || script.GetIsObjectValid(m_oCreature) == CLRScriptBase.FALSE)
     {
         return false;
     }
     uint oOldHide = getHide(script);
     foreach(ItemProperty prop in script.GetItemPropertiesOnItem(oOldHide))
     {
         if (script.GetItemPropertyDurationType(prop) == CLRScriptBase.DURATION_TYPE_PERMANENT)
         {
             script.RemoveItemProperty(oOldHide, prop);
         }
     }
     script.SendMessageToPC(m_oCreature, "PC Hide refreshed.");
     return true;
 }
 public static void Disable(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint disabler)
 {
     if (trap.Disabler == 0)
     {
         // no one is currently working on this trap.
         s.SendMessageToPC(disabler, "<c=#98FFFF>You begin to disable the trap...</c>");
         trap.Disabler = disabler;
         trap.Helpers = new List<uint>();
     }
     else
     {
         if (trap.Disabler == disabler)
         {
             s.SendMessageToPC(disabler, "<c=#98FFFF>Error: You are already disabling this device.</c>");
         }
         else if (trap.Helpers.Contains(disabler))
         {
             s.SendMessageToPC(disabler, "<c=#98FFFF>Disable Device: * Failure * You have already given aid to this attempt.</c>");
             return;
         }
         else
         {
             trap.Helpers.Add(disabler);
             if (IsDisableSuccessful(s, trap, 10, disabler) == DisableResult.Success)
             {
                 s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Disable Device: You grant {0} useful assistance with the trap.</c>", s.GetName(trap.Disabler)));
                 trap.TotalHelp += 2;
                 return;
             }
             else
             {
                 s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Disable Device: You are unable to grant {0} useful assistance with the trap.</c>", s.GetName(trap.Disabler)));
                 return;
             }
         }
     }
     if (s.GetIsDM(disabler) == TRUE && s.GetIsDMPossessed(disabler) == FALSE)
     {
         RemoveTrap(s, trap);
         s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Removing trap {0}</c>", trap.Tag));
         return;
     }
     float neededTime = s.d4(2) * 6.0f;
     NWLocation oldLoc = s.GetLocation(disabler);
     s.DelayCommand(2.0f, delegate { StallForTime(s, trap, disabler, neededTime, oldLoc); });
 }
 public static void LoadAreas(CLRScriptBase s)
 {
     if (!ACR_Candlekeep.ArchivesInstance.WaitForResourcesLoaded(false))
     {
         s.DelayCommand(6.0f, delegate { LoadAreas(s); });
         return;
     }
     ALFA.Shared.Modules.InfoStore.ActiveAreas = new Dictionary<uint, ALFA.Shared.ActiveArea>();
     List<uint> areas = new List<uint>();
     foreach (uint area in s.GetAreas())
     {
         ALFA.Shared.ActiveArea activeArea = new ALFA.Shared.ActiveArea();
         activeArea.Id = area;
         activeArea.Name = s.GetName(area).Trim();
         activeArea.Tag = s.GetTag(area);
         activeArea.GlobalQuests.Add("Infestation", s.GetLocalInt(area, "ACR_QST_MAX_INFESTATION"));
         ALFA.Shared.Modules.InfoStore.ActiveAreas.Add(area, activeArea);
         areas.Add(area);
     }
     int count = 0;
     foreach(KeyValuePair<string, string> keyValue in ALFA.Shared.Modules.InfoStore.AreaNames)
     {
         ALFA.Shared.Modules.InfoStore.ActiveAreas[areas[count]].LocalizedName = keyValue.Value;
         ALFA.Shared.Modules.InfoStore.ActiveAreas[areas[count]].ConfigureDisplayName();
         s.SetLocalString(areas[count], "ACR_AREA_RESREF", keyValue.Key);
         count++;
     }
     foreach (ALFA.Shared.ActiveArea activeArea in ALFA.Shared.Modules.InfoStore.ActiveAreas.Values)
     {
         foreach (uint thing in s.GetObjectsInArea(activeArea.Id))
         {
             uint target = s.GetTransitionTarget(thing);
             if (s.GetIsObjectValid(target) != FALSE)
             {
                 ALFA.Shared.ActiveTransition activeTransition = new ALFA.Shared.ActiveTransition();
                 activeTransition.AreaTarget = ALFA.Shared.Modules.InfoStore.ActiveAreas[s.GetArea(target)];
                 activeTransition.Id = thing;
                 activeTransition.Target = target;
                 activeArea.ExitTransitions.Add(activeTransition, activeTransition.AreaTarget);
             }
         }
     }
 }
 private static bool GetIsHalfWeight(CLRScriptBase script, List<PricedItemProperty> itProp)
 {
     PricedItemProperty removedProp = null;
     foreach (PricedItemProperty prop in itProp)
     {
         if (script.GetItemPropertyType(prop.Property) == ITEM_PROPERTY_DAMAGE_BONUS &&
             script.GetItemPropertyCostTableValue(prop.Property) == IP_CONST_REDUCEDWEIGHT_50_PERCENT)
         {
             removedProp = prop;
             break;
         }
     }
     if (removedProp != null)
     {
         itProp.Remove(removedProp);
         return true;
     }
     return false;
 }
 private static bool GetIsUseRestrictedByClass(CLRScriptBase script, List<PricedItemProperty> itProp)
 {
     List<PricedItemProperty> removedProps = new List<PricedItemProperty>();
     foreach (PricedItemProperty prop in itProp)
     {
         if (script.GetItemPropertyType(prop.Property) == ITEM_PROPERTY_USE_LIMITATION_CLASS)
         {
             removedProps.Add(prop);
         }
     }
     foreach (PricedItemProperty removedProp in removedProps)
     {
         itProp.Remove(removedProp);
     }
     if (removedProps.Count > 0)
     {
         return true;
     }
     return false;
 }
 private static bool GetHasSpecificSavingThrowPenalty(CLRScriptBase script, List<PricedItemProperty> itProp, int saveType, int saveBonus)
 {
     PricedItemProperty removedProp = null;
     foreach (PricedItemProperty prop in itProp)
     {
         if (script.GetItemPropertyType(prop.Property) == ITEM_PROPERTY_DECREASED_SAVING_THROWS_SPECIFIC &&
             script.GetItemPropertySubType(prop.Property) == saveType &&
             script.GetItemPropertyCostTableValue(prop.Property) == saveBonus)
         {
             removedProp = prop;
             break;
         }
     }
     if (removedProp != null)
     {
         itProp.Remove(removedProp);
         return true;
     }
     return false;
 }
        public static void AdjustPrice(CLRScriptBase script, uint target, int adjustBy)
        {
            if (script.GetObjectType(target) != OBJECT_TYPE_ITEM)
                return;

            if (adjustBy == 0)
                return;

            string itemKey = PriceChangeVarName + target.ToString();
            if (script.GetItemStackSize(target) > 1)
            {
                stackSizes.Add(itemKey, script.GetItemStackSize(target));
                script.SetItemStackSize(target, 1, FALSE);
            }
            script.StoreCampaignObject(ItemChangeDBName, itemKey, target, script.OBJECT_SELF);
            if (ALFA.Shared.Modules.InfoStore.ModifiedGff.Keys.Contains(itemKey))
            {
                int currentModifyCost = 0;
                currentModifyCost = ALFA.Shared.Modules.InfoStore.ModifiedGff[itemKey].TopLevelStruct["ModifyCost"].ValueInt + adjustBy;
                ALFA.Shared.Modules.InfoStore.ModifiedGff[itemKey].TopLevelStruct["ModifyCost"].ValueInt = currentModifyCost;
                
                script.DestroyObject(target, 0.0f, FALSE);
                script.DelayCommand(0.1f, delegate() 
                { 
                    uint newObject = script.RetrieveCampaignObject(ItemChangeDBName, itemKey, script.GetLocation(script.OBJECT_SELF), script.OBJECT_SELF, script.OBJECT_SELF);
                    if (stackSizes.Keys.Contains(itemKey))
                    {
                        script.SetItemStackSize(newObject, stackSizes[itemKey], FALSE);
                        stackSizes.Remove(itemKey);
                    }
                    if (script.GetObjectType(script.OBJECT_SELF) != OBJECT_TYPE_PLACEABLE)
                    {
                        script.CopyItem(newObject, script.OBJECT_SELF, TRUE);
                        script.DestroyObject(newObject, 0.0f, FALSE);
                    }
                });
            }
        }
        private static void HandleTrapDetected(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint detector)
        {
            trap.Detected = true;
           
            NWEffect vfx = s.SupernaturalEffect(s.EffectNWN2SpecialEffectFile(trap.TrapTriggerVFX, OBJECT_INVALID, s.Vector(0.0f, 0.0f, 0.0f)));
            s.ApplyEffectToObject(DURATION_TYPE_PERMANENT, vfx, s.GetObjectByTag(trap.Tag, 0), 0.0f);

            uint detectWidget = s.CreateObject(OBJECT_TYPE_PLACEABLE, "acr_trap_disarm", s.GetLocation(detector), TRUE, trap.Tag + "_");
            if (!String.IsNullOrEmpty(trap.Description))
            {
                s.SetDescription(detectWidget, trap.Description);
            }
            s.SetFirstName(detectWidget, String.Format("Disarm the {0} trap", trap.SpellTrap ? "Spell" : "Mechanical"));
            
            // If they clicked to walk, let's stop them from walking into the hazard they just found.
            if (s.GetCurrentAction(detector) == ACTION_MOVETOPOINT)
            {
                s.AssignCommand(detector, delegate { s.ClearAllActions(0); });
            }
            s.PlaySound("alert", FALSE);
            s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.SupernaturalEffect(s.EffectNWN2SpecialEffectFile("fx_bang", detector, s.Vector(0.0f,0.0f,0.0f))), detector, 6.0f);
            s.SendMessageToPC(detector, "You spot a trap!");
        }
        public bool LoadArea(CLRScriptBase script)
        {
            if(TemplateAreaId == 0)
            {
                // No template? Can't instance anything. Report failure.
                return false;
            }
            if(AreaId != 0)
            {
                // Got an Id? Great! Job's already done.
                return true;
            }

            // Guess we need an area. Check the cache first.
            if(DungeonStore.CachedAreas.ContainsKey(TemplateAreaId))
            {
                if(DungeonStore.CachedAreas[TemplateAreaId].Count > 0)
                {
                    AreaId = DungeonStore.CachedAreas[TemplateAreaId][0];
                    DungeonStore.CachedAreas[TemplateAreaId].Remove(DungeonStore.CachedAreas[TemplateAreaId][0]);
                    script.SetLocalString(AreaId, "DUNGEON_NAME", DungeonName);
                    PopulateArea(script);
                    return true;
                }
            }

            // No dice? OK, time to make an instance
            AreaId = script.CreateInstancedAreaFromSource(TemplateAreaId);
            if(script.GetIsObjectValid(AreaId) == CLRScriptBase.TRUE)
            {
                script.SetLocalString(AreaId, "DUNGEON_NAME", DungeonName);
                PopulateArea(script);
                return true;
            }

            return false;
        }
 public static int NewPotion(CLRScriptBase script, int maxValue)
 {
     if (maxValue < 50)
     {
         return 0;
     }
     if (maxValue >= 750)
     {
         switch (Generation.rand.Next(3))
         {
             case 0:
                 script.CreateItemOnObject(Level1Potions[Generation.rand.Next(Level1Potions.Count)], script.OBJECT_SELF, 1, "", FALSE);
                 return 50;
             case 1:
                 script.CreateItemOnObject(Level2Potions[Generation.rand.Next(Level2Potions.Count)], script.OBJECT_SELF, 1, "", FALSE);
                 return 300;
             case 2:
                 script.CreateItemOnObject(Level3Potions[Generation.rand.Next(Level3Potions.Count)], script.OBJECT_SELF, 1, "", FALSE);
                 return 750;
         }
     }
     else if (maxValue >= 300)
     {
         switch (Generation.rand.Next(2))
         {
             case 0:
                 script.CreateItemOnObject(Level1Potions[Generation.rand.Next(Level1Potions.Count)], script.OBJECT_SELF, 1, "", FALSE);
                 return 50;
             case 1:
                 script.CreateItemOnObject(Level2Potions[Generation.rand.Next(Level2Potions.Count)], script.OBJECT_SELF, 1, "", FALSE);
                 return 300;
         }
     }
     script.CreateItemOnObject(Level1Potions[Generation.rand.Next(Level1Potions.Count)], script.OBJECT_SELF, 1, "", FALSE);
     return 50;
 }