Jump to content

Script: Check if the player's inventory changed


NoCashNoExp

Recommended Posts

Yes, as SKK50 said you can make a new quest, start game enabled, and put a reference alias on it that points at the player. Then use the OnItemAdded and OnItemRemoved events: Something like this

 

Scriptname MyPlayerReferenceAliasScript extends ReferenceAlias  

Form Property SomeItem Auto 

Event OnInit()
    AddInventoryEventFilter(SomeItem) 
    Int CurrentAmount = Self.GetActorRef().GetItemCount(SomeItem)
    Debug.Notification("Current amount is " + CurrentAmount)
EndEvent 

Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    Int CurrentAmount = Self.GetActorRef().GetItemCount(SomeItem)
    Debug.Notification("Current amount is " + CurrentAmount)
EndEvent
   
Event OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)    
    Int CurrentAmount = Self.GetActorRef().GetItemCount(SomeItem)
    Debug.Notification("Current amount is " + CurrentAmount)
EndEvent
Link to comment
Share on other sites

Thank you both for your replies, I will test your code momentarily. I understand how to create quests and attach scripts but I didn't quite understand aliases. I will read aliases on the wiki again. This is the way I originally did it but for some reason it didn't work:

Scriptname testScript extends Quest


Actor Property pPlayerRef Auto Const Mandatory


Event OnInit()
Debug.Notification("Script Init")
RegisterForRemoteEvent(pPlayerRef, "OnItemAdded")
EndEvent


Event ObjectReference.OnItemAdded(ObjectReference origin, Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
Debug.Notification("Item Added")
EndEvent

 

Edit: I managed to setup a player alias and tested your code and it works perfectly. Thanks again.

Edited by NoCashNoExp
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...