Jump to content

Items stolen flag


Recommended Posts

If that's distracting, here's what I would do. Make a new empty interior dummy cell and place a chest in it. Move items from the player inventory to the chest, then drop objects from the chest to check:

 

Actor Property PlayerRef Auto 
ObjectReference Property PlayerChest Auto ;empty chest in an empty interior dummy cell
MiscObject Property Gold001 Auto


Event OnInit()
    Int StolenItems = CountPlayerStolenItems()
    Debug.Notification("Player stolen item count: " + CountPlayerStolenItems())
EndEvent


Int Function CountPlayerStolenItems()
    PlayerChest.RemoveAllItems()
    Int iCount = PlayerRef.GetNumItems()
    Int StolenCount = 0
    Int ItemCount = 0


    While iCount
        iCount -= 1
        Form checkItem = PlayerRef.GetNthForm(iCount)
        If checkItem != Gold001 ;discount gold
            ItemCount = PlayerRef.GetItemCount(checkItem) 
            PlayerRef.RemoveItem(checkItem, ItemCount, True, PlayerChest) ;move all of the checkitem's to the playerchest silently 
            While ItemCount > 0 
                ItemCount -= 1
                ObjectReference DroppedObject = PlayerChest.DropObject(checkItem, 1)
                If DroppedObject == None ;sometimes a ref isn't detected when dropping objects, if they are a permanent ref. 
                    DroppedObject = Game.FindClosestReferenceOfTypeFromRef(checkItem, PlayerChest, 10000) ;attempt to find the reference. 
                Endif
                
                If DroppedObject == None ;failsafe, if droppedObject still wasn't found, just add an item back to player. 
                    PlayerRef.AddItem(checkItem, 1, true) 
                Else 
                    If DroppedObject.IsOffLimits()
                        StolenCount += 1 
                    Endif 
                    PlayerRef.AddItem(DroppedObject, 1, true) 
                Endif
            EndWhile 
            
            Debug.Notification("item... " +iCount+"  Stolen..."+StolenCount)  
        Endif   
    EndWhile
    
    Return StolenCount
EndFunction

Another option is to use RemoveAllItems on the player.

 

Actor Property PlayerRef Auto 
ObjectReference Property PlayerChest Auto ;empty chest in an empty interior dummy cell
MiscObject Property Gold001 Auto


Event OnInit()
    Int StolenItems = CountPlayerStolenItems()
    Debug.Notification("Player stolen item count: " + CountPlayerStolenItems())
EndEvent


Int Function CountPlayerStolenItems()
    PlayerChest.RemoveAllItems()
    PlayerRef.RemoveAllItems(PlayerChest, True, False) ;remove all player items, keeping ownership, except quest items to the playerChest.
    Int StolenCount = 0
    Int ItemCount = 0
    Int iCount = PlayerChest.GetNumItems()
    
    While iCount
        iCount -= 1
        Form checkItem = PlayerChest.GetNthForm(iCount)
        ItemCount = PlayerChest.GetItemCount(checkItem) 
        While ItemCount > 0 
            ItemCount -= 1
            ObjectReference DroppedObject = PlayerChest.DropObject(checkItem, 1)
            If DroppedObject == None ;sometimes a ref isn't detected when dropping objects, if they are a permanent ref. 
                DroppedObject = Game.FindClosestReferenceOfTypeFromRef(checkItem, PlayerChest, 10000) ;attempt to find the reference. 
            Endif
            
            If DroppedObject == None ;failsafe, if droppedObject still wasn't found, just add an item back to player. 
                PlayerRef.AddItem(checkItem, 1, true) 
            Else 
                If DroppedObject.IsOffLimits()
                    StolenCount += 1 
                Endif 
                PlayerRef.AddItem(DroppedObject, 1, true) 
            Endif
        EndWhile 
        
        Debug.Notification("item... " +iCount+"  Stolen..."+StolenCount)  
      
    EndWhile
    
    Return StolenCount
EndFunction
Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Oh one more thing for reference. The SKSE function's CreateArray doesn't have the 128 limit. I once checked that function, creating an int array the size of 1 million and tracing it's elements to a debug log and it worked. It took a long time, over 15 minutes, but it did work.

Link to comment
Share on other sites

Great to know about the array limits :)

 

I can see how those scripts would solve the flashing but... as this can take a very long time to process (in my test anyway) wouldn't that mean the player would not have access to the items until they where returned... I can see that being a even bigger problem :(

 

But giving that I'll test it out anyway... it would always be a good to know :)

Link to comment
Share on other sites

A quick q.

Doesn't RemoveAllItems also remove items being worn and/or favorited ?

Yes.

 

You can avoid that by cycling the player's inventory and dealing with each item individually. But this can take time (i.e. the more items there are, the longer it takes) and will require the use of SKSE.

 

The following can be used in place of RemoveAllItems to keep favorited and equipped objects in the player inventory. However, quest objects will be transferred. And if the container receiving the items happens to be owned, it may be possible for ownership to change.

 

Int index = PlayerRef.GetNumItems() - 1
While index >= 0
  Form Entry = PlayerRef.GetNthForm(index)
  If Entry && !(PlayerRef.IsEquipped(Entry)) && !(Game.IsObjectFavorited(Entry))
    Int num = PlayerRef.GetItemCount(Entry)
    PlayerRef.RemoveItem(Entry,num,true,PlayerChest)
  EndIf
  index -= 1
EndWhile
Link to comment
Share on other sites

any suggestions on how is the best way to also exclude items such as arrows or torches etc.

 

I've tried using a form list but can't get that to work :(

e.g. ExclueStolen.HasForm( checkItem) ; where ExclueStolen is a form list.

Link to comment
Share on other sites

Oh... it's that simple :smile:

 

I'll add that in and test....

 

BTY... script is now sorting all stolen items as it should... except for 1 knife :D

 

umm... checkItem as arrow

compiler error unkowntype arrow ???

 

Is there a list of these items anywhere?

 

A bit more testing and....

Item.HasKeyword(VendorItemArrow) appears to work :)

Edited by TheWanderer001
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...