LarannKiar Posted May 22, 2021 Share Posted May 22, 2021 Yes, right, you should use the aiItemCount instead.. If akBaseItem == c_grenade_frag_scrap PlayerRef.RemoveItem(c_grenade_frag_scrap, aiItemCount, abSilent = true) PlayerRef.AddItem(fragGrenade, aiItemCount, abSilent = true) EndIf Link to comment Share on other sites More sharing options...
DieFeM Posted May 22, 2021 Share Posted May 22, 2021 (edited) Well, then I would replace those 4 lines: int c_grenade_frag_scrap_Count = PlayerRef.GetItemCount(c_grenade_frag_scrap) int fragGrenade_Count = PlayerRef.GetItemCount(fragGrenade) PlayerRef.removeItem(c_grenade_frag_scrap, c_grenade_frag_scrap_Count, abSilent = true) PlayerRef.addItem(fragGrenade, fragGrenade_Count, abSilent = true) With those 2: PlayerRef.removeItem(c_grenade_frag_scrap, aiItemCount, abSilent = true) PlayerRef.addItem(fragGrenade, aiItemCount, abSilent = true) This way if 4 c_grenade_frag_scrap enter in to the player inventory this script will convert them in to 4 grenades, by removing (removeItem) the quantity that is entering to the inventory (aiItemCount) of c_grenade_frag_scrap, and adding (addItem) the same quanity (aiItemCount) of grenades (fragGrenade), all of this done without notifications (abSilent = true). Edited May 22, 2021 by DieFeM Link to comment Share on other sites More sharing options...
cerebii Posted May 22, 2021 Author Share Posted May 22, 2021 (edited) Sorry for the late reply, took me a while to figure out I needed to set the properties in the CK, but yes, its working! Thank you so much SKK50, LarannKiar and DiFeM, I will be crediting you all when the mod is fully complete and released! :laugh: Edit: Made a short video of the script in action Edited May 22, 2021 by cerebii Link to comment Share on other sites More sharing options...
DieFeM Posted May 23, 2021 Share Posted May 23, 2021 :thumbsup: Glad it worked. Thanks for the video. Link to comment Share on other sites More sharing options...
cerebii Posted May 23, 2021 Author Share Posted May 23, 2021 (edited) :thumbsup: Glad it worked. Thanks for the video.No, thank you! One quick question, the AddInventoryEventFilter(), do I need to list every item I want the script to filter for, for example AddInventoryEventFilter(c_grenade frag scrap, c_grenade_molotov_scrap, c_grenade_baseball_scrap) Or do I need an event filter for each item, i.e. AddInventoryEventFilter(c_grenade_frag_scrap)AddInventoryEventFilter(c_grenade_molotov_scrap)AddInventoryEventFilter(c_grenade_baseball_scrap) Or something else? Thanks again! Edit: the CK wiki says you can use a formlist? Would that be best? Edited May 23, 2021 by cerebii Link to comment Share on other sites More sharing options...
DieFeM Posted May 23, 2021 Share Posted May 23, 2021 Only the second example would work.Indeed a formlist would be the best option for many objects, but you would need to deal with formlist indexes when you want to access elements individually. For example, if you want to access c_grenade_frag_scrap, and it is the third element of your list, you would need to do: MiscObject c_grenade_frag_scrap = MyScrapList.GetAt(2) As MiscObject That way you get the index 2 of the formlist, which is the third element. Note that the first index is zero. Link to comment Share on other sites More sharing options...
cerebii Posted May 23, 2021 Author Share Posted May 23, 2021 (edited) Only the second example would work.Indeed a formlist would be the best option for many objects, but you would need to deal with formlist indexes when you want to access elements individually. For example, if you want to access c_grenade_frag_scrap, and it is the third element of your list, you would need to do: MiscObject c_grenade_frag_scrap = MyScrapList.GetAt(2) As MiscObject That way you get the index 2 of the formlist, which is the third element. Note that the first index is zero.When you say "access elements individually", how would this relate to the script?Would I need to replace every instance of "c_grenade_frag_scrap" with "MiscObject c_grenade_frag_scrap = MyScrapList.GetAt(2) As MiscObject"? Edit: Tested the script out with a formlist and it seems to just work so I think I'm good, thanks again :smile: Edited May 23, 2021 by cerebii Link to comment Share on other sites More sharing options...
DieFeM Posted May 23, 2021 Share Posted May 23, 2021 (edited) only once in each event where you want to use it. Or you can declare the variables outside of the events, so they are available inside of all events like the properties, I guess that's the best choice if you really need to do that. Or, having in to account that you have 2 objects, the scrap (c_grenade_frag_scrap) and the replacer (fragGrenade), you could use two lists MiscObject Property c_grenade_frag_scrap Auto Const Weapon Property fragGrenade Auto ConstReplace with 2 formlist: FormList Property MyScrapList Auto Const FormList Property MyReplacerList Auto ConstWhen you create the formlist, if you place the scrap and the replacer in the same index in their respective formlists then you can use: int index = MyScrapList.Find(akBaseItem) form scrap = MyScrapList.GetAt(index)to get the current scrap index based on the base item that just triggered the event, so no mater what scrap, you'll get the proper replacer using the resulting index because you placed it in the same spot (index) in the list than the scrap: form Replacer = MyReplacerList.GetAt(index) Edited May 23, 2021 by DieFeM Link to comment Share on other sites More sharing options...
cerebii Posted May 23, 2021 Author Share Posted May 23, 2021 only once in each event where you want to use it. Or you can declare the variables outside of the events, so they are available inside of all events like the properties, I guess that's the best choice if you really need to do that. Or, having in to account that you have 2 objects, the scrap (c_grenade_frag_scrap) and the replacer (fragGrenade), you could use two lists MiscObject Property c_grenade_frag_scrap Auto Const Weapon Property fragGrenade Auto ConstReplace with 2 formlist: FormList Property MyScrapList Auto Const FormList Property MyReplacerList Auto ConstWhen you create the formlist, if you place the scrap and the replacer in the same index in their respective formlists then you can use: int index = MyScrapList.Find(akBaseItem) form scrap = MyScrapList.GetAt(index)to get the current scrap index based on the base item that just triggered the event, so no mater what scrap, you'll get the proper replacer using the resulting index because you placed it in the same spot (index) in the list than the scrap: form Replacer = MyReplacerList.GetAt(index)Ah, I see, yeah, that would definitely be a cleaner way of doing things. At the moment, I've got multiple component items coming from each c_grenade_scrap item, i.e. If akBaseItem == c_grenade_frag_scrap PlayerRef.removeItem(c_grenade_frag_scrap, aiItemCount, abSilent = true) PlayerRef.addItem(c_adhesive_scrap, aiItemCount*2, abSilent = true) PlayerRef.addItem(c_aluminum_scrap, aiItemCount, abSilent = true) PlayerRef.addItem(c_fertilizer_scrap, aiItemCount*2, abSilent = true) PlayerRef.addItem(c_oil_scrap, aiItemCount*2, abSilent = true) PlayerRef.addItem(c_springs_scrap, aiItemCount, abSilent = true) EndIfSo I don't know how or if that could be made to work here. Anyway it works so the less I mess around with it the better lol :laugh: Link to comment Share on other sites More sharing options...
DieFeM Posted May 23, 2021 Share Posted May 23, 2021 There you have an example: FormList Property MyScrapList Auto Const FormList Property MyReplacerList Auto Const Event OnQuestInit() AddInventoryEventFilter(MyScrapList) RegisterForRemoteEvent(Game.GetPlayer(), "OnItemAdded") ;Need to register this script to the "OnItemAdded" event EndEvent Event ObjectReference.OnItemAdded(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) int index = MyScrapList.Find(akBaseItem) form scrap = MyScrapList.GetAt(index) form replacer = MyReplacerList.GetAt(index) Game.GetPlayer().removeItem(scrap, aiItemCount, abSilent = true) Game.GetPlayer().addItem(replacer, aiItemCount, abSilent = true) EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts