Laerithryn Posted May 31, 2021 Share Posted May 31, 2021 Need help writing a script to check player's inventory for items (journal parts), if all are found remove them and add a single item (whole journal). I have no clue how to go about doing this, nor what type of event would be used. Any help would be greatly appreciated. Event ? If akActionRef == Game.GetPlayer() if (Game.GetPlayer().GetItemCount(JournalPart1) > 0) Debug.Trace("Player has Part 1 of journal") RemoveItem(JournalPart1) endif If akActionRef == Game.GetPlayer() if (Game.GetPlayer().GetItemCount(JournalPart2) > 0) Debug.Trace("Player has Part 2 of journal") RemoveItem(JournalPart2) endif If akActionRef == Game.GetPlayer() if (Game.GetPlayer().GetItemCount(JournalPart3) > 0) Debug.Trace("Player has Part 3 of journal") RemoveItem(JournalPart3) AddItem(WholeJournal) endif EndEvent Link to comment Share on other sites More sharing options...
dylbill Posted May 31, 2021 Share Posted May 31, 2021 The event you use depends on when you want to check for the entries. It looks like you want the player to use an activator to check. If so you can do something like this: Book Property JournalPart1 Auto Book Property JournalPart2 Auto Book Property JournalPart3 Auto Book Property WholeJournal Auto Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() CheckJournalEntries() Endif EndEvent Function CheckJournalEntries() If Game.GetPlayer().GetItemCount(JournalPart1) > 0 && Game.GetPlayer().GetItemCount(JournalPart2) > 0 && Game.GetPlayer().GetItemCount(JournalPart3) > 0 Game.GetPlayer().RemoveItem(JournalPart1, 1) Game.GetPlayer().RemoveItem(JournalPart2, 1) Game.GetPlayer().RemoveItem(JournalPart3, 1) Game.GetPlayer().AddItem(WholeJournal, 1) Endif EndFunction Link to comment Share on other sites More sharing options...
Laerithryn Posted June 3, 2021 Author Share Posted June 3, 2021 Thank you Dylbill. Actually I was trying to figure out what Event to use to achieve the same result by having all three parts in inventory as the only requirement, not a trigger or activator. Apologies for not making that clear to begin with. Link to comment Share on other sites More sharing options...
Laerithryn Posted June 3, 2021 Author Share Posted June 3, 2021 (edited) Dyblbill, so in the case mentioned in my previous post, the only requirements to make the journal whole being the player having all three parts in their inventory, what would that event be then? I assume something like Event OnItemAdded, but I'm often wrong? If that assumption is right, how do I use it properly? Do I simply swap out OnActivate for OnItemAdded? If so , I'm confused on how to use akItemReference in this case. Does akItemReference refer to only the third Journal part or all three? Does it have to be declared beforehand above with the properties? Book Property JournalPart1 Auto Book Property JournalPart2 Auto Book Property JournalPart3 Auto Book Property WholeJournal Auto Event OnItemAdded(ObjectReference akItemReference) If akItemReference == Game.GetPlayer() CheckJournalEntries() Endif EndEvent Function CheckJournalEntries() If Game.GetPlayer().GetItemCount(JournalPart1) > 0 && Game.GetPlayer().GetItemCount(JournalPart2) > 0 && Game.GetPlayer().GetItemCount(JournalPart3) > 0 Game.GetPlayer().RemoveItem(JournalPart1, 1) Game.GetPlayer().RemoveItem(JournalPart2, 1) Game.GetPlayer().RemoveItem(JournalPart3, 1) Game.GetPlayer().AddItem(WholeJournal, 1) Endif EndFunction Edited June 3, 2021 by Laerithryn Link to comment Share on other sites More sharing options...
dylbill Posted June 3, 2021 Share Posted June 3, 2021 For that I would put your script on a reference alias pointing to the player. Make a new quest, leave it start game enabled. Under the Quest Alias's tab, make a new reference alias. Fill type Specific reference, cell Any, Player. Then put a script like this on the reference alias: Scriptname TM_ReferenceAliasScript extends ReferenceAlias ;script on a ReferenceAlias in a quest pointing to the player. Book Property JournalPart1 Auto Book Property JournalPart2 Auto Book Property JournalPart3 Auto Book Property WholeJournal Auto Event OnInit() ;add event filters so the OnItemAdded Event only fires for JournalParts 1 2 and 3 AddInventoryEventFilter(JournalPart1) AddInventoryEventFilter(JournalPart2) AddInventoryEventFilter(JournalPart3) EndEvent Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) ;Player added a journal part to their inventory CheckJournalEntries() EndEvent Function CheckJournalEntries() If Game.GetPlayer().GetItemCount(JournalPart1) > 0 && Game.GetPlayer().GetItemCount(JournalPart2) > 0 && Game.GetPlayer().GetItemCount(JournalPart3) > 0 Game.GetPlayer().RemoveItem(JournalPart1, 1) Game.GetPlayer().RemoveItem(JournalPart2, 1) Game.GetPlayer().RemoveItem(JournalPart3, 1) Game.GetPlayer().AddItem(WholeJournal, 1) Self.GetOwningQuest().Stop() ;stop the quest this ReferenceAlias is on Endif EndFunction Change the scriptname to something more unique. Whenever writing events, make sure you have all the passed in forms. You can check in the CK wiki: https://www.creationkit.com/index.php?title=Category:Papyrus or in the source .psc file the event comes from. Link to comment Share on other sites More sharing options...
Laerithryn Posted June 4, 2021 Author Share Posted June 4, 2021 (edited) Thank you Dylbill, question, I already have a quest for these journal parts that's completed once the third part is read/picked-up. Can I just add a new alias to it or should I create a new quest as you said? Oh and for the Specific Reference fill type it wants me to select in the review window, I'm I correct that I have to make it point to where I placed the third journal in game? Drat, tried that and it doesn't work unfortunately. I know it's me I'm doing something wrong. Edited June 4, 2021 by Laerithryn Link to comment Share on other sites More sharing options...
ReDragon2013 Posted June 5, 2021 Share Posted June 5, 2021 Laerithryn wrote: "Need help writing a script to check player's inventory for items (journal parts), if all are found remove them and add a single item (whole journal)."dylbill has already given some answers here. Laeirithryn asked: "Can I just add a new alias to it or should I create a new quest as you said?"It should be fine to use the existing quest. As dylbill wrote: "Under the Quest Alias's tab, make a new reference alias." and attach the script as follow. laerTM_PlayerAliasScript Scriptname laerTM_PlayerAliasScript extends ReferenceAlias ; https://forums.nexusmods.com/index.php?/topic/10086563-need-script-to-remove-journalpages-and-add-wholejournal-to-inventory/ ; Make sure this script is attached to a ReferenceAlias in a quest pointing to the player. ; Do not forget to fill all properties with CK. Book PROPERTY JournalPart1 auto Book PROPERTY JournalPart2 auto Book PROPERTY JournalPart3 auto Book PROPERTY WholeJournal auto ; -- EVENTs -- 2 EVENT OnInit() ; add filters here, so the OnItemAdded() event only fires for these three books self.AddInventoryEventFilter(JournalPart1) self.AddInventoryEventFilter(JournalPart2) self.AddInventoryEventFilter(JournalPart3) ENDEVENT EVENT OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) CheckJournalEntries() ENDEVENT ; -- FUNCTION -- ;------------------------ FUNCTION JournalEntries() ;------------------------ actor player = self.GetActorReference() ; playeralias script only IF (player.GetItemCount(JournalPart1) > 0) IF (player.GetItemCount(JournalPart2) > 0) IF (player.GetItemCount(JournalPart3) > 0) player.RemoveItem(JournalPart1, 1) player.RemoveItem(JournalPart2, 1) player.RemoveItem(JournalPart3, 1) player.AddItem(WholeJournal, 1) self.GetOwningQuest().Stop() ; stop the quest this ReferenceAlias is on, if required at this moment !! ENDIF ENDIF ENDIF ENDFUNCTION dyllbill wrote: "Fill type Specific reference, cell Any, Player. Then put a script like this on the reference alias"Laeirithryn asked: "Oh and for the Specific Reference fill type it wants me to select in the review window, I'm I correct that I have to make it point to where I placed the third journal in game?"no,, no.. select "unique player" should be enough, you do not have to place this ReferenceAlias anywhere Link to comment Share on other sites More sharing options...
Laerithryn Posted June 5, 2021 Author Share Posted June 5, 2021 (edited) Tried both ways, Dylbill's and ReDragon2013, no go. Scripts compile on both accounts but not working in game. Pickup all 3 parts and never get the whole journal. Tried selecting "unique player" pointing to the player as well as Specific Reference but pointing to the third part. I don't know what I'm doing wrong. Edit1: Ok so far the script DOES remove the 3 journal parts, but it is not adding the whole journal.These are my Reference Alias window choices: Reference Name: Part3Fill Type: Unique Actor: PlayerScripts: ReferenceAliasScript Edit2: AWESOME it finally WORKS!!! Many thanks to both Dylbill & ReDragon2013 for your respective help. Just gotta say, it's folks you two that make modding worth while. You are both a blessing to the modding community! It was me all along I never rechecked the properties on the WholeJournal and it was pointing to an earlier ID of it. FIXED! Edited June 5, 2021 by Laerithryn Link to comment Share on other sites More sharing options...
dylbill Posted June 5, 2021 Share Posted June 5, 2021 So your journal parts are already alias's? If so, you can put the same script on each journal part alias that checks if the player has all three, instead of using a player alias. script on journal part alias Book Property JournalPart1 Auto Book Property JournalPart2 Auto Book Property JournalPart3 Auto Book Property WholeJournal Auto Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) If akNewContainer == Game.GetPlayer() ;did this journal part enter the player's inventory? CheckJournalEntries() Endif EndEvent Function CheckJournalEntries() If Game.GetPlayer().GetItemCount(JournalPart1) > 0 && Game.GetPlayer().GetItemCount(JournalPart2) > 0 && Game.GetPlayer().GetItemCount(JournalPart3) > 0 Game.GetPlayer().RemoveItem(JournalPart1, 1) Game.GetPlayer().RemoveItem(JournalPart2, 1) Game.GetPlayer().RemoveItem(JournalPart3, 1) Game.GetPlayer().AddItem(WholeJournal, 1) Self.GetOwningQuest().Stop() ;stop the quest this ReferenceAlias is on Endif EndFunction Link to comment Share on other sites More sharing options...
dylbill Posted June 5, 2021 Share Posted June 5, 2021 Don't to fill properties in the CK after compiling and attaching the script. Link to comment Share on other sites More sharing options...
Recommended Posts