Xander9009 Posted December 15, 2014 Share Posted December 15, 2014 (edited) Terra Nova, why do you say that line isn't setting it to false? Also (not directed at Terra Nova), bools are false by default. "Bool Property IsPlaced Auto Hidden" shoould start with IsPlaced as false. Anyway, yes, it can be expanded. I haven't tested this, but see if it compiles. If so, you should be able to fill up ONE array. It will find the first array that isn't empty and ignore EVERYTHING else. So you can't mix and match with this. Reveal hidden contents ScriptName ItemDisplay_ActivatorScript extends ObjectReference {Generic ItemDisplay script for an activator object that stores an item (or one of a set of leveled items) in a master container and displays a matching static version in the world.} Actor Property PlayerRef Auto ObjectReference Property MasterContainer Auto {The container (possibly shared with other activators) that will hold the real items.} ObjectReference Property ItemToDisplay Auto {The display item to be enabled or disabled. If not filled, the reference linked in the CK will be used instead.} Armor[] Property ArmorToPlace Auto {An item (or group of levelled items) that can be stored in the container and displayed.} Weapon[] Property WeaponToPlace Auto {An item (or group of levelled items) that can be stored in the container and displayed.} MiscObject[] Property MiscObjectToPlace Auto {An item (or group of levelled items) that can be stored in the container and displayed.} Book[] Property BookToPlace Auto {An item (or group of levelled items) that can be stored in the container and displayed.} SoulGem[] Property SoulGemToPlace Auto {An item (or group of levelled items) that can be stored in the container and displayed.} Ammo[] Property AmmoToPlace Auto {An item (or group of levelled items) that can be stored in the container and displayed.} Potion[] Property PotionToPlace Auto {An item (or group of levelled items) that can be stored in the container and displayed.} Form[] ItemToPlace Event OnActivate(ObjectReference akActionRef) {Exchange item between player and MasterContainer (on player activation) and always sync display with contents of MasterContainer. Is activated by MasterContainer to force the display sync if player adds or removes the item without using the activator.} InitializeItemToPlace() if akActionRef == PlayerRef && MasterContainer && ItemToPlace bool searching = true ; first if it is already in the container try to move it to the player int i = ItemToPlace.Length while i > 0 && searching i -= 1 if MasterContainer.GetItemCount(ItemToPlace[i]) > 0 MasterContainer.RemoveItem(ItemToPlace[i], 1, false, PlayerRef) searching = false endif endwhile ; if not, check to see if the player is carrying it and move it to the container i = ItemToPlace.Length while i > 0 && searching i -= 1 if PlayerRef.GetItemCount(ItemToPlace[i]) > 0 PlayerRef.RemoveItem(ItemToPlace[i], 1, false, MasterContainer) searching = false endif endwhile endif ; update the display version (if any) if !ItemToDisplay ItemToDisplay = GetLinkedRef() endif if ItemToDisplay bool shouldHide = true int i = ItemToPlace.Length while i > 0 && shouldHide i -= 1 if MasterContainer.GetItemCount(ItemToPlace[i]) > 0 shouldHide = false endif endwhile if shouldHide ItemToDisplay.Disable() else ItemToDisplay.Enable() endif endif EndEvent bool Function CanDisplayItem(Form akBaseItem) {Can the item be displayed by this activator? Used by the MasterContainer.} InitializeArray() int i = ItemToPlace.Length while i > 0 i -= 1 if ItemToPlace[i] == akBaseItem return true endif endwhile return false EndFunction Function InitializeItemToPlace() If !ItemToPlace If ArmorToPlace InitializeArray(ArmorToPlace.Length) Int j = 0 While j < ArmorToPlace.Length ItemToPlace[j] = ArmorToPlace[j] as Form j += 1 EndWhile ElseIf WeaponToPlace InitializeArray(WeaponToPlace.Length) Int j = 0 While j < WeaponToPlace.Length ItemToPlace[j] = WeaponToPlace[j] as Form j += 1 EndWhile ElseIf MiscObjectToPlace InitializeArray(MiscObjectToPlace.Length) Int j = 0 While j < MiscObjectToPlace.Length ItemToPlace[j] = MiscObjectToPlace[j] as Form j += 1 EndWhile ElseIf BookToPlace InitializeArray(BookToPlace.Length) Int j = 0 While j < BookToPlace.Length ItemToPlace[j] = BookToPlace[j] as Form j += 1 EndWhile ElseIf SoulGemToPlace InitializeArray(SoulGemToPlace.Length) Int j = 0 While j < SoulGemToPlace.Length ItemToPlace[j] = SoulGemToPlace[j] as Form j += 1 EndWhile ElseIf AmmoToPlace InitializeArray(AmmoToPlace.Length) Int j = 0 While j < AmmoToPlace.Length ItemToPlace[j] = AmmoToPlace[j] as Form j += 1 EndWhile ElseIf PotionToPlace InitializeArray(PotionToPlace.Length) Int j = 0 While j < PotionToPlace.Length ItemToPlace[j] = PotionToPlace[j] as Form j += 1 EndWhile EndIf EndIf EndFunction Function InitializeArray(Int InitializationValue) If ( InitializationValue == 1 ) ItemToPlace = New Form[1] ElseIf ( InitializationValue == 2 ) ItemToPlace = New Form[2] ElseIf ( InitializationValue == 3 ) ItemToPlace = New Form[3] ElseIf ( InitializationValue == 4 ) ItemToPlace = New Form[4] ElseIf ( InitializationValue == 5 ) ItemToPlace = New Form[5] ElseIf ( InitializationValue == 6 ) ItemToPlace = New Form[6] ElseIf ( InitializationValue == 7 ) ItemToPlace = New Form[7] ElseIf ( InitializationValue == 8 ) ItemToPlace = New Form[8] ElseIf ( InitializationValue == 9 ) ItemToPlace = New Form[9] ElseIf ( InitializationValue == 10 ) ItemToPlace = New Form[10] ElseIf ( InitializationValue == 11 ) ItemToPlace = New Form[11] ElseIf ( InitializationValue == 12 ) ItemToPlace = New Form[12] ElseIf ( InitializationValue == 13 ) ItemToPlace = New Form[13] ElseIf ( InitializationValue == 14 ) ItemToPlace = New Form[14] ElseIf ( InitializationValue == 15 ) ItemToPlace = New Form[15] ElseIf ( InitializationValue == 16 ) ItemToPlace = New Form[16] ElseIf ( InitializationValue == 17 ) ItemToPlace = New Form[17] ElseIf ( InitializationValue == 18 ) ItemToPlace = New Form[18] ElseIf ( InitializationValue == 19 ) ItemToPlace = New Form[19] ElseIf ( InitializationValue == 20 ) ItemToPlace = New Form[20] ElseIf ( InitializationValue == 21 ) ItemToPlace = New Form[21] ElseIf ( InitializationValue == 22 ) ItemToPlace = New Form[22] ElseIf ( InitializationValue == 23 ) ItemToPlace = New Form[23] ElseIf ( InitializationValue == 24 ) ItemToPlace = New Form[24] ElseIf ( InitializationValue == 25 ) ItemToPlace = New Form[25] ElseIf ( InitializationValue == 26 ) ItemToPlace = New Form[26] ElseIf ( InitializationValue == 27 ) ItemToPlace = New Form[27] ElseIf ( InitializationValue == 28 ) ItemToPlace = New Form[28] ElseIf ( InitializationValue == 29 ) ItemToPlace = New Form[29] ElseIf ( InitializationValue == 30 ) ItemToPlace = New Form[30] ElseIf ( InitializationValue == 31 ) ItemToPlace = New Form[31] ElseIf ( InitializationValue == 32 ) ItemToPlace = New Form[32] ElseIf ( InitializationValue == 33 ) ItemToPlace = New Form[33] ElseIf ( InitializationValue == 34 ) ItemToPlace = New Form[34] ElseIf ( InitializationValue == 35 ) ItemToPlace = New Form[35] ElseIf ( InitializationValue == 36 ) ItemToPlace = New Form[36] ElseIf ( InitializationValue == 37 ) ItemToPlace = New Form[37] ElseIf ( InitializationValue == 38 ) ItemToPlace = New Form[38] ElseIf ( InitializationValue == 39 ) ItemToPlace = New Form[39] ElseIf ( InitializationValue == 40 ) ItemToPlace = New Form[40] ElseIf ( InitializationValue == 41 ) ItemToPlace = New Form[41] ElseIf ( InitializationValue == 42 ) ItemToPlace = New Form[42] ElseIf ( InitializationValue == 43 ) ItemToPlace = New Form[43] ElseIf ( InitializationValue == 44 ) ItemToPlace = New Form[44] ElseIf ( InitializationValue == 45 ) ItemToPlace = New Form[45] ElseIf ( InitializationValue == 46 ) ItemToPlace = New Form[46] ElseIf ( InitializationValue == 47 ) ItemToPlace = New Form[47] ElseIf ( InitializationValue == 48 ) ItemToPlace = New Form[48] ElseIf ( InitializationValue == 49 ) ItemToPlace = New Form[49] ElseIf ( InitializationValue == 50 ) ItemToPlace = New Form[50] ElseIf ( InitializationValue == 51 ) ItemToPlace = New Form[51] ElseIf ( InitializationValue == 52 ) ItemToPlace = New Form[52] ElseIf ( InitializationValue == 53 ) ItemToPlace = New Form[53] ElseIf ( InitializationValue == 54 ) ItemToPlace = New Form[54] ElseIf ( InitializationValue == 55 ) ItemToPlace = New Form[55] ElseIf ( InitializationValue == 56 ) ItemToPlace = New Form[56] ElseIf ( InitializationValue == 57 ) ItemToPlace = New Form[57] ElseIf ( InitializationValue == 58 ) ItemToPlace = New Form[58] ElseIf ( InitializationValue == 59 ) ItemToPlace = New Form[59] ElseIf ( InitializationValue == 60 ) ItemToPlace = New Form[60] ElseIf ( InitializationValue == 61 ) ItemToPlace = New Form[61] ElseIf ( InitializationValue == 62 ) ItemToPlace = New Form[62] ElseIf ( InitializationValue == 63 ) ItemToPlace = New Form[63] ElseIf ( InitializationValue == 64 ) ItemToPlace = New Form[64] ElseIf ( InitializationValue == 65 ) ItemToPlace = New Form[65] ElseIf ( InitializationValue == 66 ) ItemToPlace = New Form[66] ElseIf ( InitializationValue == 67 ) ItemToPlace = New Form[67] ElseIf ( InitializationValue == 68 ) ItemToPlace = New Form[68] ElseIf ( InitializationValue == 69 ) ItemToPlace = New Form[69] ElseIf ( InitializationValue == 70 ) ItemToPlace = New Form[70] ElseIf ( InitializationValue == 71 ) ItemToPlace = New Form[71] ElseIf ( InitializationValue == 72 ) ItemToPlace = New Form[32] ElseIf ( InitializationValue == 73 ) ItemToPlace = New Form[73] ElseIf ( InitializationValue == 74 ) ItemToPlace = New Form[74] ElseIf ( InitializationValue == 75 ) ItemToPlace = New Form[75] ElseIf ( InitializationValue == 76 ) ItemToPlace = New Form[76] ElseIf ( InitializationValue == 77 ) ItemToPlace = New Form[77] ElseIf ( InitializationValue == 78 ) ItemToPlace = New Form[78] ElseIf ( InitializationValue == 79 ) ItemToPlace = New Form[79] ElseIf ( InitializationValue == 80 ) ItemToPlace = New Form[80] ElseIf ( InitializationValue == 81 ) ItemToPlace = New Form[81] ElseIf ( InitializationValue == 82 ) ItemToPlace = New Form[82] ElseIf ( InitializationValue == 83 ) ItemToPlace = New Form[83] ElseIf ( InitializationValue == 84 ) ItemToPlace = New Form[84] ElseIf ( InitializationValue == 85 ) ItemToPlace = New Form[85] ElseIf ( InitializationValue == 86 ) ItemToPlace = New Form[86] ElseIf ( InitializationValue == 87 ) ItemToPlace = New Form[87] ElseIf ( InitializationValue == 88 ) ItemToPlace = New Form[88] ElseIf ( InitializationValue == 89 ) ItemToPlace = New Form[89] ElseIf ( InitializationValue == 90 ) ItemToPlace = New Form[90] ElseIf ( InitializationValue == 91 ) ItemToPlace = New Form[91] ElseIf ( InitializationValue == 92 ) ItemToPlace = New Form[92] ElseIf ( InitializationValue == 93 ) ItemToPlace = New Form[93] ElseIf ( InitializationValue == 94 ) ItemToPlace = New Form[94] ElseIf ( InitializationValue == 95 ) ItemToPlace = New Form[95] ElseIf ( InitializationValue == 96 ) ItemToPlace = New Form[96] ElseIf ( InitializationValue == 97 ) ItemToPlace = New Form[97] ElseIf ( InitializationValue == 98 ) ItemToPlace = New Form[98] ElseIf ( InitializationValue == 99 ) ItemToPlace = New Form[99] ElseIf ( InitializationValue == 100 ) ItemToPlace = New Form[100] ElseIf ( InitializationValue == 101 ) ItemToPlace = New Form[101] ElseIf ( InitializationValue == 102 ) ItemToPlace = New Form[102] ElseIf ( InitializationValue == 103 ) ItemToPlace = New Form[103] ElseIf ( InitializationValue == 104 ) ItemToPlace = New Form[104] ElseIf ( InitializationValue == 105 ) ItemToPlace = New Form[105] ElseIf ( InitializationValue == 106 ) ItemToPlace = New Form[106] ElseIf ( InitializationValue == 107 ) ItemToPlace = New Form[107] ElseIf ( InitializationValue == 108 ) ItemToPlace = New Form[108] ElseIf ( InitializationValue == 109 ) ItemToPlace = New Form[109] ElseIf ( InitializationValue == 110 ) ItemToPlace = New Form[110] ElseIf ( InitializationValue == 111 ) ItemToPlace = New Form[111] ElseIf ( InitializationValue == 112 ) ItemToPlace = New Form[112] ElseIf ( InitializationValue == 113 ) ItemToPlace = New Form[113] ElseIf ( InitializationValue == 114 ) ItemToPlace = New Form[114] ElseIf ( InitializationValue == 115 ) ItemToPlace = New Form[115] ElseIf ( InitializationValue == 116 ) ItemToPlace = New Form[116] ElseIf ( InitializationValue == 117 ) ItemToPlace = New Form[117] ElseIf ( InitializationValue == 118 ) ItemToPlace = New Form[118] ElseIf ( InitializationValue == 119 ) ItemToPlace = New Form[119] ElseIf ( InitializationValue == 120 ) ItemToPlace = New Form[120] ElseIf ( InitializationValue == 121 ) ItemToPlace = New Form[121] ElseIf ( InitializationValue == 122 ) ItemToPlace = New Form[122] ElseIf ( InitializationValue == 123 ) ItemToPlace = New Form[123] ElseIf ( InitializationValue == 124 ) ItemToPlace = New Form[124] ElseIf ( InitializationValue == 125 ) ItemToPlace = New Form[125] ElseIf ( InitializationValue == 126 ) ItemToPlace = New Form[126] ElseIf ( InitializationValue == 127 ) ItemToPlace = New Form[127] Else ItemToPlace = New Form[128] EndIf EndFunction Also, the CanDisplayItem function should be able to be shortened and simplified. I haven't done so, because I won't be testing it, but all it does it checks if an item is in an array. You can try this. If it doesn't work, revert to the previous. If it works, it'll be a lot faster than actually iterating through the array and checking each item (since that's what "find" does, but it's native). Reveal hidden contents bool Function CanDisplayItem(Form akBaseItem) {Can the item be displayed by this activator? Used by the MasterContainer.} InitializeItemToPlace() if ItemToPlace.Find(akBaseItem) >= 0 return true endif return false EndFunction EDIT: I completely forgot that you can't cast one type to another when they're arrays. Had to replace that casting with iterative casting. Also had to include a function to initialize an array to a variable. I've tested if it compiles, and now it does. However, I still haven't tested if it works. Edited December 15, 2014 by Xander9009 Link to comment Share on other sites More sharing options...
Terra Nova Posted December 15, 2014 Share Posted December 15, 2014 (edited) On 12/15/2014 at 1:18 PM, Xander9009 said: Terra Nova, why do you say that line isn't setting it to false? Also (not directed at Terra Nova), bools are false by default. "Bool Property IsPlaced Auto Hidden" shoould start with IsPlaced as false. I've never trusted doing this: (and I think that only applies to variables.)Bool property bMyBool =False autoI mean it doesn't set it to false/true in the property manager. If I'm wrong, then I'm wrong, but I prefer to play safe with this language. Edited December 15, 2014 by Terra Nova Link to comment Share on other sites More sharing options...
Xander9009 Posted December 15, 2014 Share Posted December 15, 2014 On 12/15/2014 at 2:24 PM, Terra Nova said: On 12/15/2014 at 1:18 PM, Xander9009 said: Terra Nova, why do you say that line isn't setting it to false? Also (not directed at Terra Nova), bools are false by default. "Bool Property IsPlaced Auto Hidden" shoould start with IsPlaced as false. I've never trusted doing this: (and I think that only applies to variables.)Bool property bMyBool =False autoI mean it doesn't set it to false/true in the property manager. If I'm wrong, then I'm wrong, but I prefer to play safe with this language. If it was just to play it safe, then that makes sense. I just tested it in game and it does work the way it would be expected to, which makes sense since properties are variables (they're just variables which happen to be editable with the property manager). If it's not set, it's false, if it is set when declared, it's whatever it was initialized to. But no, it doesn't actually show what it's defaulted to in the property manager. That why whenever I set a variable with a default in my own scripts, I always include that information in the property help text. Link to comment Share on other sites More sharing options...
cdcooley Posted December 15, 2014 Share Posted December 15, 2014 All of this is because the CK can't fill a generic Form type even though Papyrus has no problem with them. I had created and tested my own version that looks very much like Xander9009's code. And after read that post have revised my code to use the Find function directly from the master container script. I named the properties so that all of the ItemToPlace arrays would be together. My version actually lets you put items in more than one of the lists since it merges them. I don't know if that would ever be useful, but it was just as easy as using only one list at a time. My NewFormArray function only initializes approximately the right number of slots and I use a variable to record the real length. I'm too lazy to generate all 128 elseif blocks since it's highly unlikely someone would use more than a half-dozen anyway. (And yes I did test that feature.) Here are my two revised and tested scripts. I attached them to some items in my game and they worked just like I expected (after a few edits of course). Reveal hidden contents ScriptName ItemDisplay_MasterContainerScript extends ObjectReference {Generic ItemDisplay script for a container object that stores items and is linked to activators which display matching static versions based on what is in the container.} bool Property AllowOnlyDisplayableItems = false Auto {Defaults to false, but if set to true container will return items that can not be displayed by one of its activators.} ItemDisplay_ActivatorScript[] Property DisplayActivator Auto {The activators that are using this as their container.} Actor Property PlayerRef Auto Event OnActivate(ObjectReference akActionRef) if akActionRef == PlayerRef && DisplayActivator while !Utility.IsInMenuMode() Utility.WaitMenuMode(0.1) ; wait for container to open endwhile Utility.Wait(0.01) ; and then close again ; now signal all of the activators to update their matching display items int i = DisplayActivator.Length while i > 0 i -= 1 DisplayActivator[i].Activate(self) endwhile endif EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) {Ensure nothing is stored in this container that can not be displayed by one of the activators (if configured).} if AllowOnlyDisplayableItems && akSourceContainer bool mustGiveBack = true if DisplayActivator int i = DisplayActivator.Length while i > 0 && mustGiveBack i -= 1 if DisplayActivator[i].ItemToPlace.Find(akBaseItem) mustGiveBack = false endif endwhile endif if mustGiveBack RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer) endif endif EndEvent ScriptName ItemDisplay_ActivatorScript extends ObjectReference {Generic ItemDisplay script for an activator object that stores an item (or one of a set of leveled items) in a master container and displays a matching static version in the world.} ObjectReference Property ItemToDisplay Auto {The display item to be enabled or disabled. If not filled, the reference linked in the CK will be used instead.} Armor[] Property ItemToPlace_Armor Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Ammo[] Property ItemToPlace_Ammo Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Book[] Property ItemToPlace_Book Auto {An item (or group of leveled items) that can be stored in the container and displayed.} MiscObject[] Property ItemToPlace_MiscObject Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Potion[] Property ItemToPlace_Potion Auto {An item (or group of leveled items) that can be stored in the container and displayed.} SoulGem[] Property ItemToPlace_SoulGem Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Weapon[] Property ItemToPlace_Weapon Auto {An item (or group of leveled items) that can be stored in the container and displayed.} ObjectReference Property MasterContainer Auto {The container (possibly shared with other activators) that will hold the real items.} Actor Property PlayerRef Auto Form[] Property ItemToPlace Auto Hidden {Items are copied here from the more specificly typed versions of the script.} int Property ItemToPlaceLength Auto Hidden {The actual number of items in the ItemToPlace array since it might be too big.} Event OnActivate(ObjectReference akActionRef) {Exchange item between player and MasterContainer (on player activation) and always sync display with contents of MasterContainer. Is activated by MasterContainer to force the display sync if player adds or removes the item without using the activator.} if akActionRef == PlayerRef && MasterContainer && ItemToPlace bool searching = true ; first if it is already in the container try to move it to the player int i = ItemToPlaceLength while i > 0 && searching i -= 1 if MasterContainer.GetItemCount(ItemToPlace[i]) > 0 MasterContainer.RemoveItem(ItemToPlace[i], 1, false, PlayerRef) searching = false endif endwhile ; if not, check to see if the player is carrying it and move it to the container i = ItemToPlaceLength while i > 0 && searching i -= 1 if PlayerRef.GetItemCount(ItemToPlace[i]) > 0 PlayerRef.RemoveItem(ItemToPlace[i], 1, false, MasterContainer) searching = false endif endwhile endif ; update the display version (if any) if !ItemToDisplay ItemToDisplay = GetLinkedRef() endif if ItemToDisplay bool shouldHide = true int i = ItemToPlaceLength while i > 0 && shouldHide i -= 1 if MasterContainer.GetItemCount(ItemToPlace[i]) > 0 shouldHide = false endif endwhile if shouldHide ItemToDisplay.Disable() else ItemToDisplay.Enable() endif endif EndEvent Event OnInit() {Copy the contents of the more specific lists into the ItemToPlace list. With the possibility of more than one type of item being collected together.} ItemToPlaceLength = ItemToPlace_Armor.Length + ItemToPlace_Ammo.Length + ItemToPlace_Book.Length + ItemToPlace_MiscObject.Length ItemToPlaceLength += ItemToPlace_Potion.Length + ItemToPlace_SoulGem.Length + ItemToPlace_Weapon.Length if ItemToPlaceLength < 1 || ItemToPlaceLength > 128 return ; can not continue with that many items! endif ItemToPlace = NewFormArray(ItemToPlaceLength) int k = 0 if ItemToPlace_Weapon int i = ItemToPlace_Weapon.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Weapon[i] k += 1 endwhile endif if ItemToPlace_SoulGem int i = ItemToPlace_SoulGem.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_SoulGem[i] k += 1 endwhile endif if ItemToPlace_Potion int i = ItemToPlace_Potion.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Potion[i] k += 1 endwhile endif if ItemToPlace_MiscObject int i = ItemToPlace_MiscObject.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_MiscObject[i] k += 1 endwhile endif if ItemToPlace_Book int i = ItemToPlace_Book.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Book[i] k += 1 endwhile endif if ItemToPlace_Ammo int i = ItemToPlace_Ammo.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Ammo[i] k += 1 endwhile endif if ItemToPlace_Armor int i = ItemToPlace_Armor.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Armor[i] k += 1 endwhile endif EndEvent Form[] Function NewFormArray(int size) {Create an new form array with approximately the right length.} if size == 1 return new Form[1] elseif size == 2 return new Form[2] elseif size == 3 return new Form[3] elseif size == 4 return new Form[4] elseif size == 5 return new Form[5] elseif size == 6 return new Form[6] elseif size <= 8 return new Form[8] elseif size <= 10 return new Form[10] elseif size <= 12 return new Form[12] elseif size <=16 return new Form[16] elseif size <= 20 return new Form[20] elseif size <= 25 return new Form[25] elseif size <= 30 return new Form[30] elseif size <= 35 return new Form[35] elseif size <= 40 return new Form[40] elseif size <= 50 return new Form[50] elseif size <= 60 return new Form[60] elseif size <= 80 return new Form[80] elseif size <= 100 return new Form[100] else return new Form[128] endif EndFunction Link to comment Share on other sites More sharing options...
Xander9009 Posted December 15, 2014 Share Posted December 15, 2014 The trick to getting all 128 is to use Notepad++ and use its macro feature. List 1-128, and then record yourself correcting one using only the keyboard, and then pres ctrl-shift-p until you're done. However, since I've already got the 1-128, just copy that to a text editor and do a find replace. Reveal hidden contents If ( size == 1 ) return New Form[1] ElseIf ( size == 2 ) return New Form[2] ElseIf ( size == 3 ) return New Form[3] ElseIf ( size == 4 ) return New Form[4] ElseIf ( size == 5 ) return New Form[5] ElseIf ( size == 6 ) return New Form[6] ElseIf ( size == 7 ) return New Form[7] ElseIf ( size == 8 ) return New Form[8] ElseIf ( size == 9 ) return New Form[9] ElseIf ( size == 10 ) return New Form[10] ElseIf ( size == 11 ) return New Form[11] ElseIf ( size == 12 ) return New Form[12] ElseIf ( size == 13 ) return New Form[13] ElseIf ( size == 14 ) return New Form[14] ElseIf ( size == 15 ) return New Form[15] ElseIf ( size == 16 ) return New Form[16] ElseIf ( size == 17 ) return New Form[17] ElseIf ( size == 18 ) return New Form[18] ElseIf ( size == 19 ) return New Form[19] ElseIf ( size == 20 ) return New Form[20] ElseIf ( size == 21 ) return New Form[21] ElseIf ( size == 22 ) return New Form[22] ElseIf ( size == 23 ) return New Form[23] ElseIf ( size == 24 ) return New Form[24] ElseIf ( size == 25 ) return New Form[25] ElseIf ( size == 26 ) return New Form[26] ElseIf ( size == 27 ) return New Form[27] ElseIf ( size == 28 ) return New Form[28] ElseIf ( size == 29 ) return New Form[29] ElseIf ( size == 30 ) return New Form[30] ElseIf ( size == 31 ) return New Form[31] ElseIf ( size == 32 ) return New Form[32] ElseIf ( size == 33 ) return New Form[33] ElseIf ( size == 34 ) return New Form[34] ElseIf ( size == 35 ) return New Form[35] ElseIf ( size == 36 ) return New Form[36] ElseIf ( size == 37 ) return New Form[37] ElseIf ( size == 38 ) return New Form[38] ElseIf ( size == 39 ) return New Form[39] ElseIf ( size == 40 ) return New Form[40] ElseIf ( size == 41 ) return New Form[41] ElseIf ( size == 42 ) return New Form[42] ElseIf ( size == 43 ) return New Form[43] ElseIf ( size == 44 ) return New Form[44] ElseIf ( size == 45 ) return New Form[45] ElseIf ( size == 46 ) return New Form[46] ElseIf ( size == 47 ) return New Form[47] ElseIf ( size == 48 ) return New Form[48] ElseIf ( size == 49 ) return New Form[49] ElseIf ( size == 50 ) return New Form[50] ElseIf ( size == 51 ) return New Form[51] ElseIf ( size == 52 ) return New Form[52] ElseIf ( size == 53 ) return New Form[53] ElseIf ( size == 54 ) return New Form[54] ElseIf ( size == 55 ) return New Form[55] ElseIf ( size == 56 ) return New Form[56] ElseIf ( size == 57 ) return New Form[57] ElseIf ( size == 58 ) return New Form[58] ElseIf ( size == 59 ) return New Form[59] ElseIf ( size == 60 ) return New Form[60] ElseIf ( size == 61 ) return New Form[61] ElseIf ( size == 62 ) return New Form[62] ElseIf ( size == 63 ) return New Form[63] ElseIf ( size == 64 ) return New Form[64] ElseIf ( size == 65 ) return New Form[65] ElseIf ( size == 66 ) return New Form[66] ElseIf ( size == 67 ) return New Form[67] ElseIf ( size == 68 ) return New Form[68] ElseIf ( size == 69 ) return New Form[69] ElseIf ( size == 70 ) return New Form[70] ElseIf ( size == 71 ) return New Form[71] ElseIf ( size == 72 ) return New Form[32] ElseIf ( size == 73 ) return New Form[73] ElseIf ( size == 74 ) return New Form[74] ElseIf ( size == 75 ) return New Form[75] ElseIf ( size == 76 ) return New Form[76] ElseIf ( size == 77 ) return New Form[77] ElseIf ( size == 78 ) return New Form[78] ElseIf ( size == 79 ) return New Form[79] ElseIf ( size == 80 ) return New Form[80] ElseIf ( size == 81 ) return New Form[81] ElseIf ( size == 82 ) return New Form[82] ElseIf ( size == 83 ) return New Form[83] ElseIf ( size == 84 ) return New Form[84] ElseIf ( size == 85 ) return New Form[85] ElseIf ( size == 86 ) return New Form[86] ElseIf ( size == 87 ) return New Form[87] ElseIf ( size == 88 ) return New Form[88] ElseIf ( size == 89 ) return New Form[89] ElseIf ( size == 90 ) return New Form[90] ElseIf ( size == 91 ) return New Form[91] ElseIf ( size == 92 ) return New Form[92] ElseIf ( size == 93 ) return New Form[93] ElseIf ( size == 94 ) return New Form[94] ElseIf ( size == 95 ) return New Form[95] ElseIf ( size == 96 ) return New Form[96] ElseIf ( size == 97 ) return New Form[97] ElseIf ( size == 98 ) return New Form[98] ElseIf ( size == 99 ) return New Form[99] ElseIf ( size == 100 ) return New Form[100] ElseIf ( size == 101 ) return New Form[101] ElseIf ( size == 102 ) return New Form[102] ElseIf ( size == 103 ) return New Form[103] ElseIf ( size == 104 ) return New Form[104] ElseIf ( size == 105 ) return New Form[105] ElseIf ( size == 106 ) return New Form[106] ElseIf ( size == 107 ) return New Form[107] ElseIf ( size == 108 ) return New Form[108] ElseIf ( size == 109 ) return New Form[109] ElseIf ( size == 110 ) return New Form[110] ElseIf ( size == 111 ) return New Form[111] ElseIf ( size == 112 ) return New Form[112] ElseIf ( size == 113 ) return New Form[113] ElseIf ( size == 114 ) return New Form[114] ElseIf ( size == 115 ) return New Form[115] ElseIf ( size == 116 ) return New Form[116] ElseIf ( size == 117 ) return New Form[117] ElseIf ( size == 118 ) return New Form[118] ElseIf ( size == 119 ) return New Form[119] ElseIf ( size == 120 ) return New Form[120] ElseIf ( size == 121 ) return New Form[121] ElseIf ( size == 122 ) return New Form[122] ElseIf ( size == 123 ) return New Form[123] ElseIf ( size == 124 ) return New Form[124] ElseIf ( size == 125 ) return New Form[125] ElseIf ( size == 126 ) return New Form[126] ElseIf ( size == 127 ) return New Form[127] Else return New Form[128] EndIf The find/replace method only took about 10 seconds :) 'Cause trust me, I'm lazy too hahaha. Link to comment Share on other sites More sharing options...
Xander9009 Posted December 15, 2014 Share Posted December 15, 2014 (edited) I'd edit my last post, but I don't want this to be missed: your find function will fail if it finds the item as the first element of the array and if it doesn't find the item at all. When it doesn't find the item, it returns -1. If it does, it returns the element index, which is 0 for the first element, and so on. Meaning, "if DisplayActivator.ItemToPlace.Find(akBaseItem)" will be true if the item isn't found, since it'll be -1, and a negative int is true (only 0 is false). It needs to be "if DisplayActivator.ItemToPlace.Find(akBaseItem) >= 0" Edited December 15, 2014 by Xander9009 Link to comment Share on other sites More sharing options...
cdcooley Posted December 15, 2014 Share Posted December 15, 2014 You're right. Lazy programming on my part both about the array declaration and the bad test for find. Thanks. Link to comment Share on other sites More sharing options...
cdcooley Posted December 15, 2014 Share Posted December 15, 2014 OK, for anyone else who might be interested. I've fixed up the scripts and added a few more utility functions. In theory other scripts could use some of the new functions to trigger some extra events that aren't handled by default. Some examples of the new features are: The activators now have a TransferAllMatchingItems property so that they can be set to grab all of the items configured instead of just one. That means clicking the activator might take all of your ebony ingots instead of just one. You could configure an activator with all of the ingot items and then use a matching display item of a pile of ingots. Separate TakeItemsFromPlayer(), ReturnAllItemsToPlayer(), and UpdateDisplay() can be called on each activator from other scripts. Those same three scripts are also in the MasterContainer script, along with a DisableActivationByPlayer property. Setting that property to true would allow you to attach another script to the container to capture the OnActivate event. It could display a menu of choices like "Open", "Retrieve All Items", "Store Matching Items", etc. I didn't try to write some sort of alternate activation function because it would have to be linked to a message and I'm still trying to keep these general purpose scripts. So here are the new versions. Hopefully without bugs this time. Reveal hidden contents ScriptName ItemDisplay_MasterContainerScript extends ObjectReference {Generic ItemDisplay script for a container object that stores items and is linked to activators which display matching static versions based on what is in the container.} bool Property AllowOnlyDisplayableItems = false Auto {Defaults to false, but if set to true container will return items that can not be displayed by one of its activators.} bool Property DisableActivationByPlayer = true Auto {Defaults to false, but if set to true the player will not be able to open the container by activating it.} ItemDisplay_ActivatorScript[] Property DisplayActivator Auto {The activators that are using this as their container.} Actor Property PlayerRef Auto ;===================================================================== ; Functions that could be called by some other script to manipulate displays in other ways. ;===================================================================== Function TakeItemsFromPlayer(bool forceGreedyMode = false) {Signal all of the linked activators to take items from the player (like clicking on all of the activators at once). If forceGreedyMode is set to true all possible matching items will be stored even if the activators would normally just take one.} if DisplayActivator int i = DisplayActivator.Length while i > 0 i -= 1 DisplayActivator[i].TakeItemsFromPlayer(forceGreedyMode) endwhile endif EndFunction Function ReturnAllItemsToPlayer() {Return all stored items to the player and disable all of the linked display items.} RemoveAllItems(PlayerRef, true, true) UpdateDisplay() EndFunction Function UpdateDisplay() {Update all of the display items. Could also be called if some other script modifies the contents of the storage container.} if DisplayActivator int i = DisplayActivator.Length while i > 0 i -= 1 DisplayActivator[i].UpdateDisplay() endwhile endif EndFunction ;===================================================================== ; Standard events that probably should not be accessed from other scripts. ;===================================================================== Event OnActivate(ObjectReference akActionRef) {If the player accesses the container directly the displays still need to get updated.} if akActionRef == PlayerRef && !DisableActivationByPlayer while !Utility.IsInMenuMode() Utility.WaitMenuMode(0.1) ; wait for container to open endwhile Utility.Wait(0.01) ; and then close again UpdateDisplay() ; now update endif EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) {Ensure nothing is stored in this container that can not be displayed by one of the activators (if configured).} if AllowOnlyDisplayableItems && akSourceContainer bool mustGiveBack = true if DisplayActivator int i = DisplayActivator.Length while i > 0 && mustGiveBack i -= 1 if DisplayActivator[i].ItemToPlace.Find(akBaseItem) >= 0 mustGiveBack = false endif endwhile endif if mustGiveBack RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer) endif endif EndEvent Event OnInit() BlockActivation() EndEvent Event OnLoad() BlockActivation() EndEventScriptName ItemDisplay_ActivatorScript extends ObjectReference {Generic ItemDisplay script for an activator object that stores an item (or one of a set of leveled items) in a master container and displays a matching static version in the world.} ObjectReference Property ItemToDisplay Auto {The display item to be enabled or disabled. If not filled, the reference linked in the CK will be used instead.} Armor[] Property ItemToPlace_Armor Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Ammo[] Property ItemToPlace_Ammo Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Book[] Property ItemToPlace_Book Auto {An item (or group of leveled items) that can be stored in the container and displayed.} MiscObject[] Property ItemToPlace_MiscObject Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Potion[] Property ItemToPlace_Potion Auto {An item (or group of leveled items) that can be stored in the container and displayed.} SoulGem[] Property ItemToPlace_SoulGem Auto {An item (or group of leveled items) that can be stored in the container and displayed.} Weapon[] Property ItemToPlace_Weapon Auto {An item (or group of leveled items) that can be stored in the container and displayed.} ObjectReference Property MasterContainer Auto {The container (possibly shared with other activators) that will hold the real items.} Actor Property PlayerRef Auto bool Property TransferAllMatchingItems = false Auto {Should activating transfer all possible items instead of just one?} Form[] Property ItemToPlace Auto Hidden {Items are copied here from the more specificly typed versions of the script.} ;===================================================================== ; Functions that can be called from the MasterContainer and other scripts. ;===================================================================== Function TakeItemsFromPlayer(bool forceGreedyMode = false) {Try to take a matching item (or all matching items) from the player then update the display. The forceGreedyMode setting will cause a transfer of all matching items even if the activator would normally only transfer one.} TransferItems(PlayerRef, MasterContainer, TransferAllMatchingItems || forceGreedyMode) UpdateDisplay() EndFunction Function ReturnAllItemsToPlayer() {Return all matching items to the player and update the display.} TransferItems(MasterContainer, PlayerRef, true) UpdateDisplay() EndFunction Function UpdateDisplay() {Refresh the display item to match the master container contents.} if ItemToDisplay bool shouldHide = true int i = ItemToPlace.Length while i > 0 && shouldHide i -= 1 if MasterContainer.GetItemCount(ItemToPlace[i]) > 0 shouldHide = false endif endwhile if shouldHide ItemToDisplay.Disable() else ItemToDisplay.Enable() endif endif EndFunction ;===================================================================== ; Internal functions and events not meant to be called from other scripts. ;===================================================================== Event OnActivate(ObjectReference akActionRef) {Exchange item between player and MasterContainer and always sync display.} if akActionRef == PlayerRef if !TransferItems(MasterContainer, PlayerRef, TransferAllMatchingItems) TransferItems(PlayerRef, MasterContainer, TransferAllMatchingItems) endif UpdateDisplay() endif EndEvent bool Function TransferItems(ObjectReference source, ObjectReference destination, bool greedy) {Utility function to do the transfer of just the first match or all matches (if greedy). Returns false when no items are moved.} bool searching = true if MasterContainer && ItemToPlace int count int i = ItemToPlace.Length while i > 0 && (searching || greedy) i -= 1 count = source.GetItemCount(ItemToPlace[i]) if count > 0 if !greedy count = 1 endif source.RemoveItem(ItemToPlace[i], count, false, destination) searching = false endif endwhile endif return !searching EndFunction Event OnInit() {Copy the contents of the more specific lists into the ItemToPlace list. With the possibility of more than one type of item being collected together.} if !ItemToDisplay ; if property not set, try to get display item from a linked ref ItemToDisplay = GetLinkedRef() endif int size = ItemToPlace_Armor.Length + ItemToPlace_Ammo.Length + ItemToPlace_Book.Length + ItemToPlace_MiscObject.Length size += ItemToPlace_Potion.Length + ItemToPlace_SoulGem.Length + ItemToPlace_Weapon.Length if size < 1 || size return ; can not continue with that many items! endif ItemToPlace = NewFormArray(size) int k = 0 if ItemToPlace_Weapon int i = ItemToPlace_Weapon.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Weapon[i] k += 1 endwhile endif if ItemToPlace_SoulGem int i = ItemToPlace_SoulGem.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_SoulGem[i] k += 1 endwhile endif if ItemToPlace_Potion int i = ItemToPlace_Potion.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Potion[i] k += 1 endwhile endif if ItemToPlace_MiscObject int i = ItemToPlace_MiscObject.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_MiscObject[i] k += 1 endwhile endif if ItemToPlace_Book int i = ItemToPlace_Book.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Book[i] k += 1 endwhile endif if ItemToPlace_Ammo int i = ItemToPlace_Ammo.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Ammo[i] k += 1 endwhile endif if ItemToPlace_Armor int i = ItemToPlace_Armor.Length while i > 0 i -= 1 ItemToPlace[k] = ItemToPlace_Armor[i] k += 1 endwhile endif EndEvent Form[] Function NewFormArray(int size) {Create a new form array with the right length.} if size == 1 return new Form[1] elseif size == 2 return new Form[2] elseif size == 3 return new Form[3] elseif size == 4 return new Form[4] elseif size == 5 return new Form[5] elseif size == 6 return new Form[6] elseif size == 7 return new Form[7] elseif size == 8 return new Form[8] elseif size == 9 return new Form[9] elseif size == 10 return new Form[10] elseif size == 11 return new Form[11] elseif size == 12 return new Form[12] elseif size == 13 return new Form[13] elseif size == 14 return new Form[14] elseif size == 15 return new Form[15] elseif size == 16 return new Form[16] elseif size == 17 return new Form[17] elseif size == 18 return new Form[18] elseif size == 19 return new Form[19] elseif size == 20 return new Form[20] elseif size == 21 return new Form[21] elseif size == 22 return new Form[22] elseif size == 23 return new Form[23] elseif size == 24 return new Form[24] elseif size == 25 return new Form[25] elseif size == 26 return new Form[26] elseif size == 27 return new Form[27] elseif size == 28 return new Form[28] elseif size == 29 return new Form[29] elseif size == 30 return new Form[30] elseif size == 31 return new Form[31] elseif size == 32 return new Form[32] elseif size == 33 return new Form[33] elseif size == 34 return new Form[34] elseif size == 35 return new Form[35] elseif size == 36 return new Form[36] elseif size == 37 return new Form[37] elseif size == 38 return new Form[38] elseif size == 39 return new Form[39] elseif size == 40 return new Form[40] elseif size == 41 return new Form[41] elseif size == 42 return new Form[42] elseif size == 43 return new Form[43] elseif size == 44 return new Form[44] elseif size == 45 return new Form[45] elseif size == 46 return new Form[46] elseif size == 47 return new Form[47] elseif size == 48 return new Form[48] elseif size == 49 return new Form[49] elseif size == 50 return new Form[50] elseif size == 51 return new Form[51] elseif size == 52 return new Form[52] elseif size == 53 return new Form[53] elseif size == 54 return new Form[54] elseif size == 55 return new Form[55] elseif size == 56 return new Form[56] elseif size == 57 return new Form[57] elseif size == 58 return new Form[58] elseif size == 59 return new Form[59] elseif size == 60 return new Form[60] elseif size == 61 return new Form[61] elseif size == 62 return new Form[62] elseif size == 63 return new Form[63] elseif size == 64 return new Form[64] elseif size == 65 return new Form[65] elseif size == 66 return new Form[66] elseif size == 67 return new Form[67] elseif size == 68 return new Form[68] elseif size == 69 return new Form[69] elseif size == 70 return new Form[70] elseif size == 71 return new Form[71] elseif size == 72 return new Form[32] elseif size == 73 return new Form[73] elseif size == 74 return new Form[74] elseif size == 75 return new Form[75] elseif size == 76 return new Form[76] elseif size == 77 return new Form[77] elseif size == 78 return new Form[78] elseif size == 79 return new Form[79] elseif size == 80 return new Form[80] elseif size == 81 return new Form[81] elseif size == 82 return new Form[82] elseif size == 83 return new Form[83] elseif size == 84 return new Form[84] elseif size == 85 return new Form[85] elseif size == 86 return new Form[86] elseif size == 87 return new Form[87] elseif size == 88 return new Form[88] elseif size == 89 return new Form[89] elseif size == 90 return new Form[90] elseif size == 91 return new Form[91] elseif size == 92 return new Form[92] elseif size == 93 return new Form[93] elseif size == 94 return new Form[94] elseif size == 95 return new Form[95] elseif size == 96 return new Form[96] elseif size == 97 return new Form[97] elseif size == 98 return new Form[98] elseif size == 99 return new Form[99] elseif size == 100 return new Form[100] elseif size == 101 return new Form[101] elseif size == 102 return new Form[102] elseif size == 103 return new Form[103] elseif size == 104 return new Form[104] elseif size == 105 return new Form[105] elseif size == 106 return new Form[106] elseif size == 107 return new Form[107] elseif size == 108 return new Form[108] elseif size == 109 return new Form[109] elseif size == 110 return new Form[110] elseif size == 111 return new Form[111] elseif size == 112 return new Form[112] elseif size == 113 return new Form[113] elseif size == 114 return new Form[114] elseif size == 115 return new Form[115] elseif size == 116 return new Form[116] elseif size == 117 return new Form[117] elseif size == 118 return new Form[118] elseif size == 119 return new Form[119] elseif size == 120 return new Form[120] elseif size == 121 return new Form[121] elseif size == 122 return new Form[122] elseif size == 123 return new Form[123] elseif size == 124 return new Form[124] elseif size == 125 return new Form[125] elseif size == 126 return new Form[126] elseif size == 127 return new Form[127] else return new Form[128] endif EndFunction Link to comment Share on other sites More sharing options...
Xander9009 Posted December 15, 2014 Share Posted December 15, 2014 I haven't looked over every line, but a quick glance looks good :) Nicely done. The only thing I noticed was that there's no inclusion of ingredients (something I also overlooked with my version). I'm not sure if I'd bother adding it, since it's both easy for others to add and not too likely to be displayed, but just a thought. Since it's generic, those new functions should prove quite useful :) Link to comment Share on other sites More sharing options...
thejadeshadow Posted December 16, 2014 Author Share Posted December 16, 2014 I will do some testing with my mod and let you know how it goes soon. :) Link to comment Share on other sites More sharing options...
Recommended Posts