virginharvester Posted October 30, 2018 Share Posted October 30, 2018 hi sorry for my bad english,i try to convert my all gold ore in player inventory,the event will run if the player added gold ore in their inventory,this is code i try to do: Event xxxxxxxxx(player,OreGold) if (Game.GetPlayer().getItemCount(OreGold) >=2) Count = (Math.Floor( Game.GetPlayer().getItemCount(OreGold) / 2)) Game.GetPlayer().removeItem(OreGold,2 * Count , TRUE) Game.GetPlayer().addItem(IngotGold,1 * Count , TRUE) endif endEvent what even that i must write in that xxxxxxxx ?, and what the parameter? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 30, 2018 Share Posted October 30, 2018 You'll want to use OnItemAdded and run it on a quest alias that points to the player. But you'll need to change your code a bit. MiscObject Property OreGold Auto MiscObject Property IngotGold Auto Event OnInit() AddInventoryEventFilter(OreGold) ;set up filter so we do not waste time and resources running script when not needed EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) Actor PlayerRef = Game.GetPlayer() ;leave script only once to obtain player data and store it locally If akBaseItem == OreGold ;is the added item what we want, should always be true due to the filter but good practice nonetheless if (PlayerRef.getItemCount(OreGold) >=2) ;does player have 2 or more Count = (Math.Floor( PlayerRef.getItemCount(OreGold) / 2)) ;figure out how many ingots can be made PlayerRef.removeItem(OreGold,2 * Count , TRUE) ;remove the ore PlayerRef.addItem(IngotGold,1 * Count , TRUE) ;add the ingots endif EndIf endEvent Link to comment Share on other sites More sharing options...
virginharvester Posted October 30, 2018 Author Share Posted October 30, 2018 You'll want to use OnItemAdded and run it on a quest alias that points to the player. But you'll need to change your code a bit. MiscObject Property OreGold Auto MiscObject Property IngotGold Auto Event OnInit() AddInventoryEventFilter(OreGold) ;set up filter so we do not waste time and resources running script when not needed EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) Actor PlayerRef = Game.GetPlayer() ;leave script only once to obtain player data and store it locally If akBaseItem == OreGold ;is the added item what we want, should always be true due to the filter but good practice nonetheless if (PlayerRef.getItemCount(OreGold) >=2) ;does player have 2 or more Count = (Math.Floor( PlayerRef.getItemCount(OreGold) / 2)) ;figure out how many ingots can be made PlayerRef.removeItem(OreGold,2 * Count , TRUE) ;remove the ore PlayerRef.addItem(IngotGold,1 * Count , TRUE) ;add the ingots endif EndIf endEvent i thought "(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)" must be edit to work, that why i have difficulty this 3 hours, thanks alot for your reply, i appreciate it , i will try it now Link to comment Share on other sites More sharing options...
virginharvester Posted October 30, 2018 Author Share Posted October 30, 2018 You'll want to use OnItemAdded and run it on a quest alias that points to the player. But you'll need to change your code a bit. MiscObject Property OreGold Auto MiscObject Property IngotGold Auto Event OnInit() AddInventoryEventFilter(OreGold) ;set up filter so we do not waste time and resources running script when not needed EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) Actor PlayerRef = Game.GetPlayer() ;leave script only once to obtain player data and store it locally If akBaseItem == OreGold ;is the added item what we want, should always be true due to the filter but good practice nonetheless if (PlayerRef.getItemCount(OreGold) >=2) ;does player have 2 or more Count = (Math.Floor( PlayerRef.getItemCount(OreGold) / 2)) ;figure out how many ingots can be made PlayerRef.removeItem(OreGold,2 * Count , TRUE) ;remove the ore PlayerRef.addItem(IngotGold,1 * Count , TRUE) ;add the ingots endif EndIf endEvent i found some problem, AddInventoryEventFilter is not a function or does not existi google sometime and found this"https://www.creationkit.com/index.php?title=AddInventoryEventFilter_-_ObjectReference" in notes section: In case anyone is wondering, Skyrim does not support passing None to this function; that was added in Fallout 4. You can get identical behavior by adding an empty FormList, though.how to "adding empty formlist" ?note : i use skyrim legendary edition(oldrim) Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 30, 2018 Share Posted October 30, 2018 You will need to post your code if you are having issues. What I shared as an example would work in original Skyrim. AddInventoryEventFilter does support individual items and that is what the example did. I suspect you did something differently than papyrus expected and thus ran into issues. Link to comment Share on other sites More sharing options...
virginharvester Posted October 30, 2018 Author Share Posted October 30, 2018 You will need to post your code if you are having issues. What I shared as an example would work in original Skyrim. AddInventoryEventFilter does support individual items and that is what the example did. I suspect you did something differently than papyrus expected and thus ran into issues.ah thanks, this is the code Scriptname SmeltScript extends Quest MiscObject Property OreGold Auto MiscObject Property IngotGold Auto int property Count auto Event OnInit() AddInventoryEventFilter (OreGold) ;set up filter so we do not waste time and resources running script when not needed EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) Actor PlayerRef = Game.GetPlayer() ;leave script only once to obtain player data and store it locally If akBaseItem == OreGold ;is the added item what we want, should always be true due to the filter but good practice nonetheless if (PlayerRef.getItemCount(OreGold) >=2) ;does player have 2 or more Count = (Math.Floor( PlayerRef.getItemCount(OreGold) / 2)) ;figure out how many ingots can be made PlayerRef.removeItem(OreGold,2 * Count , TRUE) ;remove the ore PlayerRef.addItem(IngotGold,1 * Count , TRUE) ;add the ingots endif EndIf endEvent thanks for your time and effort Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 30, 2018 Share Posted October 30, 2018 You are extending quest this is the reason for compilation errors. For both AddInventoryEventFilter and OnItemAdded to work (in this instance) the script needs to be attached to a quest alias that points to the player. As such the script would extend ReferenceAlias. Once the script extends ReferenceAlias, it will compile without issue. For consistency, I would remove the space between AddInventoryEventFilter and (OreGold). It compiled without error with the space present, but without testing, I do not know if the space will cause an issue with execution in-game. Link to comment Share on other sites More sharing options...
virginharvester Posted October 30, 2018 Author Share Posted October 30, 2018 You are extending quest this is the reason for compilation errors. For both AddInventoryEventFilter and OnItemAdded to work (in this instance) the script needs to be attached to a quest alias that points to the player. As such the script would extend ReferenceAlias. Once the script extends ReferenceAlias, it will compile without issue. For consistency, I would remove the space between AddInventoryEventFilter and (OreGold). It compiled without error with the space present, but without testing, I do not know if the space will cause an issue with execution in-game.thanks again for the reply, i replace "quest" to "ReferenceAlias" and the compile is success,yes, for space, i do try some experiment why AddInventoryEventFilter not work, one of it is add space, Link to comment Share on other sites More sharing options...
ReDragon2013 Posted October 31, 2018 Share Posted October 31, 2018 Just some cosmetic changes for the alias script. SmeltPlayerAliasScript Scriptname SmeltPlayerAliasScript extends ReferenceAlias ; https://forums.nexusmods.com/index.php?/topic/7112681-if-player-added-spesific-item-event-in-papyrus/ MiscObject PROPERTY OreGold auto ; fill by CK MiscObject PROPERTY IngotGold auto ; fill by CK ; -- EVENTs -- 2 EVENT OnInit() ; we want to set up a filter, so we do not waste time and resources of running script when not needed self.AddInventoryEventFilter(OreGold as Form) ENDEVENT EVENT OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) IF (akBaseItem == OreGold as Form) ; should always be TRUE due to the filter above, but is always good practice ELSE RETURN ; - STOP - for some unknown reason safety net is working ENDIF ;--------------------- myF_Action(akBaseItem) ; added the item what we want ENDEVENT ; -- FUNCTION -- FUNCTION myF_Action(Form akBaseItem) ;----------------------------------- actor Player = Game.GetPlayer() ; obtain the player data only once, and store it as local variable int i = Player.GetItemCount(akBaseItem) ; hold the count of "OreGold" also as local variable IF (i < 2) RETURN ; - STOP - player has only one item of "OreGold" ENDIF ;--------------------- and now figure out how many ingots can be transformed i = i - (i % 2) ; use modulo to get the result (0 or 1) Player.RemoveItem(akBaseITem, i, TRUE) ; remove the ores Player.AddItem(IngotGold as Form, i/2, TRUE) ; and add the half count of ingots instead ENDFUNCTION You also asked: "how to adding empty formlist?" use a script variable like this FormList emptyListbut it does not make sense by using the following self.AddInventoryFilter(emptyList)because adding an InventoryFilter of None (no valid formId inside the list) is doing nothing, it does not remove any filter you added before Link to comment Share on other sites More sharing options...
foamyesque Posted October 31, 2018 Share Posted October 31, 2018 (edited) The empty list the CK wiki is talking about is a new FormList you create, with nothing in it. Thus the function will see a valid thing, and set the inventory filter to listen only for the items in that form list... of which there are none at all. Effectively, this will disable OnItemAdded and OnItemRemoved events until such time as some other inventory filter is added or the formlist is removed. Edited October 31, 2018 by foamyesque Link to comment Share on other sites More sharing options...
Recommended Posts