Lexluckyluke Posted November 1, 2016 Share Posted November 1, 2016 hi everybody !i'm creating a mod who check player inventory items, for the moment i'm in the very debut, i try to understand scripting logic of papyrus(i'm not nobby at modding, just for skyrim) so there is my work Scriptname harcoreinventorymod extends Quest {the script who edit the player inventory} Event OnInit() Debug.MessageBox( "Player is " + Game.GetPlayer() ) VerifyInventory() EndEvent ;trigger when player add something to its inventory. Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) if !akSourceContainer Debug.MessageBox("I picked up " + aiItemCount + "x " + akBaseItem + " from the world") elseif akSourceContainer == Game.GetPlayer() Debug.MessageBox("The player game me " + aiItemCount + "x " + akBaseItem) else Debug.MessageBox("I got " + aiItemCount + "x " + akBaseItem + " from another container") endIf endEvent ;trigger when player remove something from his inventory Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) if akOldContainer && !akNewContainer Debug.MessageBox("We have been dropped!") elseif akNewContainer && !akOldContainer Debug.MessageBox("We have been picked up!") else Debug.MessageBox("We have switched containers!") endIf endEvent Function VerifyInventory() ;function to count objects in inventory : ;swords : ; if (Game.GetPlayer().GetItemCount(WeapTypeSwordKeyword) > 0) ; Debug.Trace("Player have some swords") ; endIf ;do the same for daggers, 2hands weaps etccc ... Debug.MessageBox("inventory verified") EndFunction explainations : i try to know when player add or remove something from his inventory(the both event have the same function i think, but that not the real problem) if i have understand the logic , events "OnItemAdded" and "OnContainerchanged" apply only to a "ObjectReference" Script ? but is there a way to say something like this ? : Event Game.GetPlayer().OnItemAdded(...) //stuff bla bla endEvnent Event Game.GetPlayer().OnContainerChanged(...) endEvent thanks for responses :) Ps: the creation kit crash many times also for me ;) Link to comment Share on other sites More sharing options...
Lexluckyluke Posted November 2, 2016 Author Share Posted November 2, 2016 (edited) i have found this but there no examples :/ http://www.creationk...Player_Add_Itemhttp://www.creationk...yer_Remove_Item i have try this : Event PlayerAddItem(ObjectReference OriginalContainer, Actor OwnerRef , Location where , Form ObjectForm , String AcquireType) Debug.MessageBox("item added ! ") VerifyInventory() EndEvent but its doesn't work :/ Edited November 6, 2016 by Lexluckyluke Link to comment Share on other sites More sharing options...
Lexluckyluke Posted November 6, 2016 Author Share Posted November 6, 2016 (edited) :( Edited November 6, 2016 by Lexluckyluke Link to comment Share on other sites More sharing options...
cdcooley Posted November 6, 2016 Share Posted November 6, 2016 Your original script is close to the right thing. The problem is you made it a quest script. The OnItemAdded and OnItemRemoved functions are from the ObjectReference script. That means they need to be attached to a script that is attached to some object. In this this case, since you want to check the player's inventory they would be attached to the player. But you should never directly attach scripts to original game items and especially the player. Instead the game allows you to use a ReferenceAlias script. You need to create a reference Alias in your quest and set it to be filled by the player. Events like OnItemAdded will be visible to the script attached to the alias as long as the player is still the reference it's holding. Link to comment Share on other sites More sharing options...
Lexluckyluke Posted November 6, 2016 Author Share Posted November 6, 2016 thanks !You need to create a reference Alias in your quest and set it to be filled by the player. Events like OnItemAdded will be visible to the script attached to the alias as long as the player is still the reference it's holding.okay, i think its good but i have some questions : fill a new reference alias to the player (in red) ?and run scripts in the alias (in green) ?http://img4.hostingpics.net/pics/597554help1.jpg what extends i need to use here ? http://img4.hostingpics.net/pics/485311help2.jpg Link to comment Share on other sites More sharing options...
cdcooley Posted November 6, 2016 Share Posted November 6, 2016 Yes to both the red and green in the first screenshot. And for the script type you want it to extend ReferenceAlias. You should avoid using Game.GetPlayer(). It's an extremely slow function. Since your script will be on a player alias you can use "GetReference() as Actor" instead. I frequently use code like this with a ReferenceAlias script. Function VerifyInventory() Actor PlayerRef = GetReference() as Actor Debug.Trace("Player sword count: " + PlayerRef.GetItemCount(WeapTypeSwordKeyword)) Debug.Trace("Player dagger count: " + PlayerRef.GetItemCount(WeapTypeDaggerKeyword)) ;... EndFunction GetReference() is a pretty fast function, but local variables are even faster and using the variable means I don't have to keep casting it ObjectReference returned to Actor each time when I want to use functions that only work on an actor. Link to comment Share on other sites More sharing options...
Lexluckyluke Posted November 6, 2016 Author Share Posted November 6, 2016 (edited) thanks ! its good, but nothing happens when i pick something or i drop something, events are not triggered, i don't know why ... :/ i have try "OnItemRemoved" & OnItemAdded but its for ObjectReference scripts and its doesn't work too i'm sorry but i feel lost, this game have nosense :wacko: Edited November 7, 2016 by Lexluckyluke Link to comment Share on other sites More sharing options...
Lexluckyluke Posted November 7, 2016 Author Share Posted November 7, 2016 (edited) after long time of search i have try this : Scriptname hardcoreinventorymod extends ReferenceAlias {blabla} Formlist Property HCinventoryfilter Auto Event OnInit() Debug.MessageBox(HCinventoryfilter) ;print the formlist Form (0500xXX) Debug.MessageBox( GetReference() ) ; Print None ! Debug.Notification("loaded okay") EndEvent ;nothing happens --> Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) AddInventoryEventFilter(HCinventoryfilter) Debug.MessageBox("ding ! ") VerifyInventory() RemoveAllInventoryEventFilters() endEvent Function VerifyInventory() ;verify if player can add this item ? (will return bool in future update) ;Debug.MessageBox("Player sword count: " + PlayerRef.GetItemCount(WeapTypeSwordKeyword)) ;Debug.MessageBox("Player dagger count: " + PlayerRef.GetItemCount(WeapTypeDaggerKeyword)) Debug.MessageBox("inventory verified ") EndFunction why print none ? i have filled the alias as the playerRef etcc someone can help me please ? Edited November 7, 2016 by Lexluckyluke Link to comment Share on other sites More sharing options...
FreshTheFallen Posted November 7, 2016 Share Posted November 7, 2016 You mean that your call of "GetReference()" returns "none"?While I do not have the most experience with Papyrus, I don't really think that just calling that function without refering to any object/alias whatsoever would work.Looking at the example given on the wiki here: http://www.creationkit.com/fallout4/index.php?title=GetReference_-_ReferenceAlias ; Get the reference the alias points at ObjectReference bossRef = BossAlias.GetReference() It is specifically asking for the reference of that BossAlias, in your code I can't really see what it should ask for, hence it is returning "None".Also, from the wiki page: Return ValueThe ObjectReference this alias is pointing at, or None if the alias has not been resolved. Link to comment Share on other sites More sharing options...
cdcooley Posted November 8, 2016 Share Posted November 8, 2016 If GetReference() is failing in a ReferenceAlias script then that means the alias isn't filled. Most likely it's because the quest isn't running. Functions that run inside the OnInit() event run even before the game itself has completely started even if the quest isn't running. If you're going to need to use GetReference() in OnInit() then you'll need to make the quest as Start Game Enabled. Link to comment Share on other sites More sharing options...
Recommended Posts