Jump to content

Any way to detect if an item is being sold before it is?


Recommended Posts

What I'm thinking is that if they try and sell the item (Bag of Holding) then show a menu to ask if they really want to do that.

If they select 'No' then just return it as in your script... but if they select 'yes'... remove the items from the bag, add those to the vendor then return an empty bag.The value of the all items would remain the original estimated value of the bag.

 

 

Hope that makes sense :D

Link to comment
Share on other sites

Ah gotcha, I assume elsewhere you set the bag of holding's value to that of it's contents so selling it is like selling all of its contents? If so you can just do something like this:

 

 

 

MiscObject Property Gold001 Auto 
MiscObject Property BagOfHolding Auto 
ObjectReference Property BagOfHoldingChest Auto
Actor Property PlayerRef Auto 
Int Property PlayerGold Auto Hidden
Bool AddOrRemoveItems
Message Property BagOfholdingSellWarning Auto

Event OnInit() 
    
    AddInventoryEventFilter(Gold001)
    AddInventoryEventFilter(BagOfHolding)
    
    RegisterForMenu("BarterMenu") 
    If UI.IsMenuOpen("BarterMenu")
        GoToState("InBarterMenu")
    Else 
        GoToState("Waiting") 
    EndIf
EndEvent 

State Waiting 
    Event OnMenuOpen(String menuName)
        GoToState("InBarterMenu")
    EndEvent
    
    Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
        ;do nothing
    EndEvent 
    
    Event OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
        ;do nothing
    EndEvent
EndState

State InBarterMenu
    Event OnBeginState()
        PlayerGold = PlayerRef.GetItemCount(Gold001) 
        AddOrRemoveItems = False
    EndEvent
    
    Event OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) 
        If akDestContainer != None && AddOrRemoveItems == False
            If akBaseItem == BagOfHolding ;player is trying to sell bag of holding
                If BagOfholdingSellWarning.Show() == 1 ;the player chose button 1, accept selling the bag contents 
                    AddOrRemoveItems = True ;prevent OnItemAdded and OnItemRemoved functions from running
                    BagOfHoldingChest.RemoveAllItems(akDestContainer) ;give all items in the bag of holding chest to the vendor 
                    akBaseItem.SetgoldValue(0) ;Set bag of holding value back to 0
                    akDestContainer.RemoveItem(akBaseItem, aiItemCount, False, PlayerRef) ;give bag of holding back to player 
                    
                Else ;player chose button 0, cancel selling the bag
                    AddOrRemoveItems = True ;prevent OnItemAdded and OnItemRemoved functions from running
                    Int GoldDiff = PlayerRef.GetItemCount(Gold001) - PlayerGold 
                    akDestContainer.RemoveItem(akBaseItem, aiItemCount, False, PlayerRef) ;give sold items back to player 
                    PlayerRef.RemoveItem(Gold001, GoldDiff, True, akDestContainer) ;give gold gained back to trader
                    Utility.WaitMenuMode(0.01)
                    AddOrRemoveItems = False
                    PlayerGold = PlayerRef.GetItemCount(Gold001) 
                Endif
            Endif
        EndIf
        
        If akBaseItem == Gold001 && AddOrRemoveItems == False
            Utility.WaitMenuMode(0.01)
            PlayerGold = PlayerRef.GetItemCount(Gold001) 
        Endif
    EndEvent
    
    Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) 
        If akBaseItem == Gold001 && AddOrRemoveItems == False 
            Utility.WaitMenuMode(0.01)
            PlayerGold = PlayerRef.GetItemCount(Gold001) 
        Endif
    EndEvent
    
    Event OnMenuClose(String menuName)
        GoToState("Waiting")
    EndEvent
Endstate

Link to comment
Share on other sites

Woow... That's great... looks like what I'm after... and I think I understand what it's doing as well... bonus :D

 

Will tweak what the yes to sell option does a bit... but I think I can figure that out now you've done all the hard stuff :thumbsup:

Just have to get the quest part right ;)

 

will test this out later.

 

 

Thank you so much for all the help... and yes I do include you IsHara here...

don't know what we would all do without all the help you and others give to us lesser mortals. :geek:

Link to comment
Share on other sites

Aggg.... AddInventoryEventFilter(GOLD001) is not a function or does not exist

Any thoughts why?

 

It is set up the same as in your script. I've read what I could find (that's not a lot though) related to the function but that hasn't revealed anything to me :(

Link to comment
Share on other sites

  • Recently Browsing   0 members

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