Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scriptname DCS_Quest_Script extends Quest
- { It just works. }
- ; DIAMOND CITY SWAT VERSION 2.0: https://www.nexusmods.com/fallout4/mods/10893/
- ; A FALLOUT 4 MOD BY @THORALDGM | THORALDGM.COM | SCRIPT UPDATED 20170919
- ;
- ; PERMISSIONS:
- ;
- ; - Do not repost my mod. If you want to tweak minor changes, send me the esp and I will post it in Files.
- ; - Language translations are allowed only on same platforms where I posted mod. Please mail link when done.
- ; - This mod may not be folded entirely into a larger work without my written permission and collaboration.
- ; - Please ask if you want to use parts of my code to improve other mods. Must be unique and credit source.
- ;
- ; - If you have any questions, or see a better way to do something, please let me know.
- ;
- ; SCRIPT SECTIONS:
- ;
- ; LINE 025: PROPERTIES
- ; LINE 094: ON INIT
- ; LINE 236: ON ITEM ADDED
- ; LINE 750: ON ITEM REMOVED
- ; LINE 790: GET RANDOM GEAR
- ; ------------------------------------------------------------------------------------------------------------
- ; PROPERTIES
- ; ------------------------------------------------------------------------------------------------------------
- ReferenceAlias Property raGearContainer Auto Mandatory ; Gear container RefAlias
- ObjectReference obGearContainer ; Gear container ObjRef
- Faction Property pPlayerFaction Auto Const Mandatory ; Player faction
- FormList Property flHeadgearArmo Auto Const Mandatory ; Vanilla headgear armors
- FormList Property flHeadgearKywd Auto Const Mandatory ; Vanilla headgear keywords
- FormList Property flEyewearArmo Auto Const Mandatory ; Vanilla eyewear armors
- FormList Property flEyewearKywd Auto Const Mandatory ; Vanilla eyewear keywords
- FormList Property flNeckwearArmo Auto Const Mandatory ; Vanilla neckwear armors
- FormList Property flNeckwearKywd Auto Const Mandatory ; Vanilla neckwear keywords
- FormList Property flGlovesArmo Auto Const Mandatory ; Vanilla gloves/rings armors
- FormList Property flGlovesKywd Auto Const Mandatory ; Vanilla gloves/rings keywords
- FormList Property flLeftArmArmo Auto Const Mandatory ; Vanilla left arm armors
- FormList Property flLeftArmKywd Auto Const Mandatory ; Vanilla left arm keywords
- FormList Property flRightArmArmo Auto Const Mandatory ; Vanilla right arm armors
- FormList Property flRightArmKywd Auto Const Mandatory ; Vanilla right arm keywords
- FormList Property flLeftLegArmo Auto Const Mandatory ; Vanilla left leg armors
- FormList Property flLeftLegKywd Auto Const Mandatory ; Vanilla left leg keywords
- FormList Property flRightLegArmo Auto Const Mandatory ; Vanilla right leg armors
- FormList Property flRightLegKywd Auto Const Mandatory ; Vanilla right leg keywords
- FormList Property flChestArmo Auto Const Mandatory ; Vanilla chest armors
- FormList Property flChestKywd Auto Const Mandatory ; Vanilla chest keywords
- FormList Property flClothingArmo Auto Const Mandatory ; Vanilla clothing/outfit armors
- FormList Property flClothingKywd Auto Const Mandatory ; Vanilla clothing/outfit keywords
- FormList Property flStorageList Auto ; FormList of FormLists
- FormList Property flStorageUnknown Auto ; Catch-all for sorts with no slot kywd
- GlobalVariable Property gvChanceNoHeadgear Auto Mandatory ; Chance of guard not wearing headgear
- GlobalVariable Property gvChanceNoEyewear Auto Mandatory ; Chance of guard not wearing eyewear
- GlobalVariable Property gvNumOtherItems Auto Mandatory ; How many other items do guards choose
- GlobalVariable Property gvDevTracking Auto Mandatory ; Are dev messages turned on
- String[] strSortedItems ; Array of slot strings for dev messages
- Bool bModInstalled ; Is AWKCR mod installed
- Keyword[] ArmorKywds ; Array of AWKCR mod slot keywords
- Keyword AK_Slot30_Hat ; AWKCR keywords competing for slots
- Keyword AK_Slot36_Bracelet
- Keyword AK_Slot46_Headband
- Keyword AK_Slot46_MaskFull
- Keyword AK_Slot49_Mouth
- Keyword AK_Slot50_Scarf
- Keyword AK_Slot54_Pack
- Keyword AK_Slot55_GunOnHip
- Keyword AK_Slot55_Satchel
- Keyword AK_Slot56_Harness
- Keyword AK_Slot58_Piercing
- ; None of the AWKCR properties were created/linked in Creation Kit because that would create a mod dependency!
- ; AWKCR mod recommended, but not required: https://www.nexusmods.com/fallout4/mods/6091/
- ; ------------------------------------------------------------------------------------------------------------
- ; EVENT: ON INIT
- ; ------------------------------------------------------------------------------------------------------------
- Event OnInit()
- ; ********************************************************************************************************
- ; SET OWNERSHIP OF GUARD GEAR CONTAINER SO PLAYER DOESN'T STEAL ITEMS AND GET ATTACKED
- ; ********************************************************************************************************
- obGearContainer = raGearContainer.GetReference() ; Grab ObjRef of the RefAlias
- Cell GearContainerCell = obGearContainer.GetParentCell() ; Grab parent cell of the ObjRef
- GearContainerCell.SetFactionOwner(pPlayerFaction) ; Remove stolen flag from cell/container
- ; This method makes everything in Security Office belong to the player, including the jail key.
- ; I would rather change flag on the container only, but obGearContainer.SetActorOwner(NONE) didn't work.
- ; I may also look into making player ownership of the Security Office a MCM option that can be toggled.
- ; ********************************************************************************************************
- ; WARN PLAYER IF CONTAINER IS STILL DANGEROUS
- ; ********************************************************************************************************
- Bool bPlayerOwns = (GearContainerCell.GetFactionOwner() == pPlayerFaction)
- If !bPlayerOwns
- ; This first notification is a critical warning, so display even if player doesn't want dev messages.
- ; Criticals are rare. Dev messages are spammy. Dev messages default to off in final version.
- Debug.Notification("DCS: SET FACTION FAILED!") ; Show notice on top left screen corner
- Debug.Trace("DIAMOND CITY SWAT: SET FACTION FAILED!") ; Write warning in log file
- Else
- If gvDevTracking.GetValue() == 1 ; If player wants developer messages
- Debug.Notification("DCS: Player owns cell.") ; inform player that faction updated
- EndIf
- EndIf
- ; ********************************************************************************************************
- ; POPULATE LIST OF SLOT NAME STRINGS FOR DEV MESSAGES
- ; ********************************************************************************************************
- strSortedItems = new string[24]
- strSortedItems[0] = "headgear"
- strSortedItems[1] = "outfit"
- strSortedItems[2] = "gloves"
- strSortedItems[3] = "bracelet"
- strSortedItems[4] = "jacket"
- strSortedItems[5] = "top"
- strSortedItems[6] = "leg addon"
- strSortedItems[7] = "bottom"
- strSortedItems[8] = "chestplate"
- strSortedItems[9] = "left arm"
- strSortedItems[10] = "right arm"
- strSortedItems[11] = "left leg"
- strSortedItems[12] = "right leg"
- strSortedItems[13] = "full mask"
- strSortedItems[14] = "eyewear"
- strSortedItems[15] = "partial mask"
- strSortedItems[16] = "neckwear"
- strSortedItems[17] = "ring"
- strSortedItems[18] = "cloak or pack"
- strSortedItems[19] = "satchel"
- strSortedItems[20] = "bandolier"
- strSortedItems[21] = "cargo"
- strSortedItems[22] = "gun on back"
- strSortedItems[23] = "left hand item"
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: Strings filled.")
- EndIf
- ; ********************************************************************************************************
- ; IF PLAYER HAS AWKCR MOD INSTALLED, START INTER-MOD COMMUNICATION AND GRAB NECESSARY FORMS
- ; ********************************************************************************************************
- ArmorKywds = new keyword[24] ; There are 24 biped slots that are most relevant to armors.
- bModInstalled = Game.IsPluginInstalled("ArmorKeywords.esm")
- Utility.Wait(0.1) ; Give stack a moment to find mod before I start grabbing forms.
- If bModInstalled
- ; AWKCR keyword IDs for biped armor slots are from Gambit77's Armorsmith Extended tutorial:
- ; https://forums.nexusmods.com/index.php?showtopic=3687915
- ; See also:
- ; https://www.creationkit.com/fallout4/index.php?title=Biped_Slots
- ; https://www.creationkit.com/fallout4/index.php?title=Inter-mod_Communication
- ArmorKywds[0] = Game.GetFormFromFile(0x01000813, "ArmorKeywords.esm") as Keyword
- ArmorKywds[1] = Game.GetFormFromFile(0x0100081E, "ArmorKeywords.esm") as Keyword
- ArmorKywds[2] = Game.GetFormFromFile(0x0100081D, "ArmorKeywords.esm") as Keyword
- ArmorKywds[3] = Game.GetFormFromFile(0x01000831, "ArmorKeywords.esm") as Keyword
- ArmorKywds[4] = Game.GetFormFromFile(0x01000832, "ArmorKeywords.esm") as Keyword
- ArmorKywds[5] = Game.GetFormFromFile(0x0100081B, "ArmorKeywords.esm") as Keyword
- ArmorKywds[6] = Game.GetFormFromFile(0x01000833, "ArmorKeywords.esm") as Keyword
- ArmorKywds[7] = Game.GetFormFromFile(0x0100081C, "ArmorKeywords.esm") as Keyword
- ArmorKywds[8] = Game.GetFormFromFile(0x0100080E, "ArmorKeywords.esm") as Keyword
- ArmorKywds[9] = Game.GetFormFromFile(0x01000803, "ArmorKeywords.esm") as Keyword
- ArmorKywds[10] = Game.GetFormFromFile(0x01000804, "ArmorKeywords.esm") as Keyword
- ArmorKywds[11] = Game.GetFormFromFile(0x01000805, "ArmorKeywords.esm") as Keyword
- ArmorKywds[12] = Game.GetFormFromFile(0x01000806, "ArmorKeywords.esm") as Keyword
- ArmorKywds[13] = Game.GetFormFromFile(0x0100080F, "ArmorKeywords.esm") as Keyword
- ArmorKywds[14] = Game.GetFormFromFile(0x0100080C, "ArmorKeywords.esm") as Keyword
- ArmorKywds[15] = Game.GetFormFromFile(0x01000801, "ArmorKeywords.esm") as Keyword
- ArmorKywds[16] = Game.GetFormFromFile(0x01000810, "ArmorKeywords.esm") as Keyword
- ArmorKywds[17] = Game.GetFormFromFile(0x0100081F, "ArmorKeywords.esm") as Keyword
- ArmorKywds[18] = Game.GetFormFromFile(0x01000839, "ArmorKeywords.esm") as Keyword
- ArmorKywds[19] = Game.GetFormFromFile(0x01000834, "ArmorKeywords.esm") as Keyword
- ArmorKywds[20] = Game.GetFormFromFile(0x01000838, "ArmorKeywords.esm") as Keyword
- ArmorKywds[21] = Game.GetFormFromFile(0x01000836, "ArmorKeywords.esm") as Keyword
- ArmorKywds[22] = Game.GetFormFromFile(0x0100083E, "ArmorKeywords.esm") as Keyword
- ArmorKywds[23] = Game.GetFormFromFile(0x01000837, "ArmorKeywords.esm") as Keyword
- AK_Slot30_Hat = Game.GetFormFromFile(0x0100080D, "ArmorKeywords.esm") as Keyword
- AK_Slot36_Bracelet = Game.GetFormFromFile(0x01000811, "ArmorKeywords.esm") as Keyword
- AK_Slot46_Headband = Game.GetFormFromFile(0x0100083F, "ArmorKeywords.esm") as Keyword
- AK_Slot46_MaskFull = Game.GetFormFromFile(0x0100083A, "ArmorKeywords.esm") as Keyword
- AK_Slot49_Mouth = Game.GetFormFromFile(0x0100083B, "ArmorKeywords.esm") as Keyword
- AK_Slot50_Scarf = Game.GetFormFromFile(0x0100083D, "ArmorKeywords.esm") as Keyword
- AK_Slot54_Pack = Game.GetFormFromFile(0x01000824, "ArmorKeywords.esm") as Keyword
- AK_Slot55_GunOnHip = Game.GetFormFromFile(0x0100083C, "ArmorKeywords.esm") as Keyword
- AK_Slot55_Satchel = Game.GetFormFromFile(0x01000861, "ArmorKeywords.esm") as Keyword
- AK_Slot56_Harness = Game.GetFormFromFile(0x01000835, "ArmorKeywords.esm") as Keyword
- AK_Slot58_Piercing = Game.GetFormFromFile(0x01000812, "ArmorKeywords.esm") as Keyword
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: AWKCR handled.")
- EndIf
- EndIf
- ; ********************************************************************************************************
- ; REGISTER (START LISTENING) FOR REMOTE EVENTS, SO SCRIPT CAN REACT WITH BADASSERY
- ; ********************************************************************************************************
- AddInventoryEventFilter(None) ; Required filter for OnItemAdded and OnItemRemoved
- Utility.Wait(0.1) ; Give stack a moment to set up required filter before I register events.
- RegisterForRemoteEvent(raGearContainer, "OnItemAdded") ; Do something when items added to gear container
- RegisterForRemoteEvent(raGearContainer, "OnItemRemoved") ; Do something when items removed from gear container
- EndEvent
- ; ------------------------------------------------------------------------------------------------------------
- ; EVENT: ON ITEM ADDED
- ; ------------------------------------------------------------------------------------------------------------
- Event ReferenceAlias.OnItemAdded(ReferenceAlias akSender, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
- String WhatIsIt
- Bool bSorted = False
- bModInstalled = Game.IsPluginInstalled("ArmorKeywords.esm")
- int i = 0 ; AWKCR array iteration
- int arSize = ArmorKywds.Length ; I don't plan on changing array size. Checking length is best practice.
- ; Plus assigning length outside of While loop condition is more efficient.
- ; Since I am using 35 AWKCR keywords to sort into 24 biped armor slots,
- ; there are 9 overlaps to condense, which contain 11 records. (35 - 11 = 24)
- ; The 9 competing slots are at array indexes: 0, 3, 13, 15, 16, 18, 19, 20, 22.
- ; ********************************************************************************************************
- ; WHILE LOOP STARTS HERE!
- ;
- ; ARRAY ALGORITHM:
- ;
- ; 0: IS THE ITEM HEADGEAR?
- ; 1: IS THE ITEM AN OUTFIT?
- ; 2: IS THE ITEM GLOVES?
- ; 3: IS THE ITEM A BRACELET?
- ; 4: IS THE ITEM A JACKET?
- ; 5: IS THE ITEM A TOP?
- ; 6: IS THE ITEM A LEG ADDON?
- ; 7: IS THE ITEM A BOTTOM?
- ; 8: IS THE ITEM A CHESTPLATE?
- ; 9: IS THE ITEM A LEFT ARM?
- ; 10: IS THE ITEM A RIGHT ARM?
- ; 11: IS THE ITEM A LEFT LEG?
- ; 12: IS THE ITEM A RIGHT LEG?
- ; 13: IS THE ITEM A FULL MASK?
- ; 14: IS THE ITEM EYEWEAR?
- ; 15: IS THE ITEM A PARTIAL MASK?
- ; 16: IS THE ITEM NECKWEAR?
- ; 17: IS THE ITEM A RING?
- ; 18: IS THE ITEM A CLOAK OR PACK?
- ; 19: IS THE ITEM A SATCHEL?
- ; 20: IS THE ITEM A BANDOLIER?
- ; 21: IS THE ITEM A CARGO VEST?
- ; 22: IS THE ITEM A GUN ON BACK?
- ; 23: IS THE ITEM A LEFT HAND DECORATIVE EFFECT?
- ; ********************************************************************************************************
- While (i < arSize) && !bSorted ; While iterating array elements and item unsorted...
- ; ****************************************************************************************************
- ; IS THE ITEM HEADGEAR?
- ; ****************************************************************************************************
- If i == 0 ; IS THE ITEM VANILLA?
- If flHeadgearArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flHeadgearKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If AK_Slot30_Hat && akBaseItem.HasKeyword(AK_Slot30_Hat)
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM AN OUTFIT?
- ; ****************************************************************************************************
- If i == 1 ; IS THE ITEM VANILLA?
- If flClothingArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flClothingKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM GLOVES?
- ; ****************************************************************************************************
- If i == 2 ; IS THE ITEM VANILLA?
- If flGlovesArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flGlovesKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- ; Disorderly vanilla keyword system in Creation Kit causes left/right arms to sort as gloves.
- ; This is unwanted behavior, so check if it just happened and fix it.
- If flLeftArmArmo.HasForm(akBaseItem) || flRightArmArmo.HasForm(akBaseItem)
- bSorted = False ; UNDO SORTED FLAG AND LET LATER ITERATIONS SORT INTO LEFT/RIGHT ARM
- EndIf ; Why later? Because i needs to be 9 (left) or 10 (right) when sorted!
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A BRACELET?
- ; ****************************************************************************************************
- If i == 3 ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If AK_Slot36_Bracelet && akBaseItem.HasKeyword(AK_Slot36_Bracelet)
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A JACKET? TOP? LEG ADDON? BOTTOM? RING? CARGO VEST? LEFT HAND DECORATIVE EFFECT?
- ; ****************************************************************************************************
- ; All of these items share the same code in my While loop.
- If ((i > 3) && (i < 8)) || (i == 17) || (i == 21) || (i == 23) ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- ; NO RINGS? BUT THERE ARE WEDDING RINGS IN THE GAME...
- ; Wedding ring and spouse's ring have vanilla keyword ArmorBodyPartHands, but not ClothingRing.
- ; So I currently lump them into my vanilla gloves formlist, and they are the only entries in it.
- ; I chose gloves over rings because I have seen more gloves in mods. Will change this if needed.
- ; AWKCR has keywords for gloves and rings, so I check for them in the array.
- ; This is one reason players will get a better experience over vanilla if they use AWKCR mod.
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A CHESTPLATE?
- ; ****************************************************************************************************
- If i == 8 ; IS THE ITEM VANILLA?
- If flChestArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flChestKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A LEFT ARM?
- ; ****************************************************************************************************
- If i == 9 ; IS THE ITEM VANILLA?
- If flLeftArmArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flLeftArmKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A RIGHT ARM?
- ; ****************************************************************************************************
- If i == 10 ; IS THE ITEM VANILLA?
- If flRightArmArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flRightArmKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A LEFT LEG?
- ; ****************************************************************************************************
- If i == 11 ; IS THE ITEM VANILLA?
- If flLeftLegArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flLeftLegKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A RIGHT LEG?
- ; ****************************************************************************************************
- If i == 12 ; IS THE ITEM VANILLA?
- If flRightLegArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flRightLegKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A FULL MASK?
- ; ****************************************************************************************************
- If i == 13 ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If (AK_Slot46_Headband && akBaseItem.HasKeyword(AK_Slot46_Headband)) || (AK_Slot46_MaskFull && akBaseItem.HasKeyword(AK_Slot46_MaskFull))
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM EYEWEAR?
- ; ****************************************************************************************************
- If i == 14 ; IS THE ITEM VANILLA?
- If flEyewearArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flEyewearKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- ; AWKCR: NO COMPETING SLOTS
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A PARTIAL MASK?
- ; ****************************************************************************************************
- If i == 15 ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If AK_Slot49_Mouth && akBaseItem.HasKeyword(AK_Slot49_Mouth)
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM NECKWEAR?
- ; ****************************************************************************************************
- If i == 16 ; IS THE ITEM VANILLA?
- If flNeckwearArmo.HasForm(akBaseItem) || akBaseItem.HasKeywordInFormList(flNeckwearKywd)
- bSorted = True
- EndIf
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If AK_Slot50_Scarf && akBaseItem.HasKeyword(AK_Slot50_Scarf)
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A CLOAK OR PACK?
- ; ****************************************************************************************************
- If i == 18 ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If AK_Slot54_Pack && akBaseItem.HasKeyword(AK_Slot54_Pack)
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A SATCHEL?
- ; ****************************************************************************************************
- If i == 19 ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If (AK_Slot55_GunOnHip && akBaseItem.HasKeyword(AK_Slot55_GunOnHip)) || (AK_Slot55_Satchel && akBaseItem.HasKeyword(AK_Slot55_Satchel))
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A BANDOLIER?
- ; ****************************************************************************************************
- If i == 20 ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If AK_Slot56_Harness && akBaseItem.HasKeyword(AK_Slot56_Harness)
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IS THE ITEM A GUN ON BACK?
- ; ****************************************************************************************************
- If i == 22 ; IS THE ITEM VANILLA?
- ; NO VANILLA LISTS
- If !bSorted ; IF NOT VANILLA...
- If bModInstalled ; IF AWKCR INSTALLED, IS ITEM AWKCR?
- If ArmorKywds[i] && akBaseItem.HasKeyword(ArmorKywds[i]) ; CHECK AWKCR ARRAY ELEMENT
- bSorted = True
- EndIf
- If !bSorted ; IF STILL UNSORTED, CHECK AWKCR COMPETING SLOTS
- If AK_Slot58_Piercing && akBaseItem.HasKeyword(AK_Slot58_Piercing)
- bSorted = True
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IF ITEM HAS BEEN SORTED, ADD FORM TO CORRECT LIST SO GUARDS CAN CHOOSE GEAR STOCKED BY PLAYER.
- ; ****************************************************************************************************
- If bSorted
- WhatIsIt = strSortedItems[i] as String
- FormList NestedList = flStorageList.GetAt(i) as FormList
- Bool bInListAlready = NestedList.HasForm(akBaseItem)
- If !bInListAlready
- NestedList.AddForm(akBaseItem) ; YO DAWG. Add form to formlist inside formlist array!
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: " + WhatIsIt + " sorted.")
- EndIf
- Else
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: " + WhatIsIt + " is a duplicate.")
- EndIf
- EndIf
- EndIf
- ; ****************************************************************************************************
- ; IF THIS IS THE LAST ITERATION OF THE LOOP AND ITEM STILL HAS NOT BEEN SORTED, SORT INTO CATCH-ALL.
- ;
- ; This robust script casts a pretty wide net to identify items and sort them.
- ;
- ; Each slot comparison includes armor formlists and keyword formlists for that slot,
- ; to minimize the number of items that make it all the way to the end unidentified.
- ;
- ; The items that fail to armor sort will be available to guards as other category inventory.
- ; (ammo, weapons, aid, mods, misc, junk)
- ;
- ; Which can be considered a mod feature if you want every guard to have dog tags or a Nuka Cola.
- ;
- ; Remind me to include a MCM option... Gear container ignores non-armors: YES | NO (default)
- ;
- ; Because players could mass duplicate items if they want to farm guard spawns for inventory.
- ; It's not my job to police the player's play style, so MCM will let player decide if available.
- ;
- ; ****************************************************************************************************
- If (i == (arSize - 1)) && !bSorted
- flStorageUnknown.AddForm(akBaseItem) ; Put item in catch-all list for extra inventory
- bSorted = True
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: other item sorted.")
- EndIf
- EndIf
- i += 1 ; Increment by one
- EndWhile
- ; ********************************************************************************************************
- ; WHILE LOOP ENDS HERE!
- ; ********************************************************************************************************
- EndEvent
- ; ------------------------------------------------------------------------------------------------------------
- ; EVENT: ON ITEM REMOVED
- ; ------------------------------------------------------------------------------------------------------------
- Event ReferenceAlias.OnItemRemoved(ReferenceAlias akSender, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
- Int i = 0
- Int arSize = flStorageList.GetSize()
- FormList NestedList
- String WhatIsIt
- ; Removing is much easier than adding because item was previously sorted!
- While i < arSize
- NestedList = flStorageList.GetAt(i) as FormList
- If NestedList.HasForm(akBaseItem)
- NestedList.RemoveAddedForm(akBaseItem)
- If gvDevTracking.GetValue() == 1
- WhatIsIt = strSortedItems[i] as String
- Debug.Notification("DCS: " + WhatIsIt + " removed.")
- EndIf
- EndIf
- i += 1 ; Increment by one
- EndWhile
- If flStorageUnknown.HasForm(akBaseItem)
- flStorageUnknown.RemoveAddedForm(akBaseItem)
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: other item removed.")
- EndIf
- EndIf
- EndEvent
- ; ------------------------------------------------------------------------------------------------------------
- ; CUSTOM FUNCTION: GET RANDOM GEAR
- ; ------------------------------------------------------------------------------------------------------------
- FormList Function GetRandomGear()
- ; ********************************************************************************************************
- ; GUARDS LOADING WILL CALL FUNCTION TO GET A LIST OF ITEMS RANDOMLY CHOSEN FROM PLAYER-STOCKED GEAR LOCKER
- ;
- ; Players can control the amount of randomness by stocking a variety of wearables, or just a few uniforms.
- ; ********************************************************************************************************
- Form ChosenItem
- FormList ChosenGearList
- FormList NestedList
- Int arSize = flStorageList.GetSize()
- Int i = 0
- Int RandMax
- Int RandIndex
- String WhatIsIt
- Bool bSkipSlot
- ; ********************************************************************************************************
- ; WHILE LOOP STARTS HERE! GUARDS CHOOSE ONE RANDOM ITEM TO WEAR FROM EACH OF THE 24 ARMOR SLOT LISTS
- ; ********************************************************************************************************
- While i < arSize ; Start while loop
- bSkipSlot = False
- If i == 0 ; If list is headgear
- If Utility.RandomInt(1, 100) <= gvChanceNoHeadgear.GetValue() ; and roll is <= chance none (MCM default: 40%)
- bSkipSlot = True ; skip headgear slot
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: Guard refused headgear.") ; notify dev tracker
- EndIf
- EndIf
- EndIf
- If i == 14 ; If list is eyewear
- If Utility.RandomInt(1, 100) <= gvChanceNoEyewear.GetValue() ; and roll is <= chance none (MCM default: 40%)
- bSkipSlot = True ; skip eyewear slot
- If gvDevTracking.GetValue() == 1
- Debug.Notification("DCS: Guard refused eyewear.") ; notify dev tracker
- EndIf
- EndIf
- EndIf
- If !bSkipSlot ; If not skipping slot
- NestedList = flStorageList.GetAt(i) as FormList ; grab list for this index
- If NestedList.GetSize() > 0 ; If list has items
- RandMax = NestedList.GetSize() - 1 ; set upper bound
- RandIndex = Utility.RandomInt(0, RandMax) ; roll random index
- ChosenItem = NestedList.GetAt(RandIndex) ; get form from rolled index
- ChosenGearList.AddForm(ChosenItem) ; add form to chosen gear list
- If gvDevTracking.GetValue() == 1
- WhatIsIt = strSortedItems[i] as String
- Debug.Notification("DCS: Guard chose " + WhatIsIt + ".") ; notify dev tracker
- EndIf
- EndIf
- EndIf
- i += 1 ; Increment by one
- EndWhile ; End while loop
- ; ********************************************************************************************************
- ; WHILE LOOP ENDS HERE!
- ; ********************************************************************************************************
- i = 0
- arSize = gvNumOtherItems.GetValue() as Int ; MCM default: 5 other items.
- ; ********************************************************************************************************
- ; WHILE LOOP STARTS HERE! GUARDS CHOOSE A NUMBER OF OTHER RANDOM ITEMS TO CARRY. (MCM DEFAULT = 5)
- ; ********************************************************************************************************
- While i < arSize ; Start while loop
- If flStorageUnknown.GetSize() > 0 ; If list has items
- RandMax = flStorageUnknown.GetSize() - 1 ; set upper bound
- RandIndex = Utility.RandomInt(0, RandMax) ; roll random index
- ChosenItem = flStorageUnknown.GetAt(RandIndex) ; get form from rolled index
- ChosenGearList.AddForm(ChosenItem) ; add form to chosen gear list
- If gvDevTracking.GetValue() == 1
- WhatIsIt = strSortedItems[i] as String
- Debug.Notification("DCS: Guard chose " + WhatIsIt + ".") ; notify dev tracker
- EndIf
- EndIf
- i += 1 ; Increment by one
- EndWhile ; End while loop
- ; ********************************************************************************************************
- ; WHILE LOOP ENDS HERE!
- ; ********************************************************************************************************
- Return ChosenGearList ; Send gear list to caller!
- EndFunction
Add Comment
Please, Sign In to add comment