Jump to content

RemoveMe & RemoveMeIR Fail to call OnAdd of Scripted Object


Recommended Posts

I am customizing the recently released mod R Takes All so that it only takes things I want and leaves the junk. I got it working perfectly until today, when I discovered that using the RemoveMEIR command with the destination container set to the player, on an item that has a script with an OnAdd block fails to call the OnAdd block.

 

Is there another way to do this while also maintaining the items' ownership setting? I don't want to lose the STOLEN flag, but I see no way to do that if I must use the AddItemNS command.

 

I haven't tested it yet in a situation where the container or interior it's in has it's ownership set (making the items stolen).

 

I am thinking I can use the RemoveMEIR command for anything that isn't scripted, and do the RemoveItem / AddItemNS thing for the ones that have a script.

 

I'm hoping I am missing something that makes this easier.

 

Thanks!!!

Edited by GamerRick
Link to comment
Share on other sites

Well loot everything, and sort it with my mod. Add the sell barrel in my shop and add the junk there and it will get there by auto when you cast the spell Sort the junk. No need to fiddle around in the inventory if you use my spells. :wink:

 

Here I demonstrate it with 3 items and one container.

 

The sell container is in this room and it sell all stuff added to it 20:00 and there is also a fence there, called The Fence:

 

52047-1660745586-593036345.jpeg

 

52047-1660745592-1284526600.jpeg

 

52047-1660745601-1934855272.jpeg

 

52047-1660745615-1379492558.jpeg

 

I also have auto loot spells, well it is a long spell list with many nice spells that makes life easier. https://www.nexusmods.com/oblivion/mods/52047?

 

I am also working on a mercant mod, with similar funtionallity: https://forums.nexusmods.com/index.php?/topic/11354933-wip-the-stall-player-driven-shop-mod/

You add stuff tat you want to autosell one time to a register container.

Edited by Pellape
Link to comment
Share on other sites

Here is the entire script. My additions (to the R Take All script) are in the if (IsBarterMenuActive == 0) If statement.

scriptname RTakesAll
;Why hello there
float fQuestDelayTime
float takeall
float takebook
short curkey
ref rContainer
ref rItem
ref rItemBase
long iObjType
short bTakeIt
short iNumEffects
long iItemValue
long iBipedMask
long iAttackDamage
long iAttackDamageNeeded
float fFloatTemp
long iItemCurrentHealth
long iItemObjectHealth
long iItemHealthDifference
int iNumItems
int iNumRefs
; User set variables
short bAllNeedingRepair
short iMinValueWeapon
short iMinValueArmor
short iMinValueBook
short iMinValueClothing
short iMinValueJewelry
short iMinValueAppartus
short bTakeBooks
short bTakeLockpicks
short bTakeTorches
short iMinValueScroll
short iMinSoulGem
short iMinValueMisc
short iMinValueMiscGems
short iMinValueAlchItem
ref rMinDamageArrow
begin GameMode
if GetGameLoaded || GetGameRestarted
  set bAllNeedingRepair to 1
  set iMinValueWeapon to 75
  set iMinValueArmor to 76
  set iMinValueBook to 25
  set iMinValueClothing to 76
  set iMinValueJewelry to 25
  set iMinValueAppartus to 200
  set bTakeBooks to 1
  set bTakeLockpicks to 1
  set bTakeTorches to 0
  set iMinValueScroll to 75
  set rMinDamageArrow to Arrow3Silver
  set iMinSoulGem to 0
  set iMinValueMiscGems to 5
  set iMinValueMisc to 50
  set iMinValueAlchItem to 50
  ;player.PlaceAtMe RFTESTskull, 1, 150, 0
endif
end
begin MenuMode 1008      ; container, barter menu
if (fQuestDelayTime == 0)
  set fQuestDelayTime to 0.01
endif
if ( curKey && isKeyPressed3 curkey )
  return
else
  set curkey to 0
endif

if ( isKeyPressed3 RFTAKEALLKEY )
 
  if (IsBarterMenuActive == 0)
   ;set takeall to GetMenuFloatValue "cont_background\page_layout\cont_contents\cont_button_take_all\visible" 1008
   set takeall to GetMenuFloatValue "cont_background\page_layout\cont_contents\cont_button_exit\visible" 1008
   if (takeall == 2)
    set rContainer to GetActiveMenuRef 1008
    if rContainer
     foreach rItem <- rContainer
      set rItemBase to rItem.GetBaseObject
      set iObjType to rItem.GetObjectType
      set bTakeIt to 0
     
      if rItem.IsQuestItem   ; Quest item 
       set bTakeIt to 1
      elseif iObjType == 19 ; Apparatus
       if rItem.GetFullGoldValue >= iMinValueAppartus
        set bTakeIt to 1
       endif
      elseif iObjType == 20 ; Armor
       if rItem.IsPlayable2
        ; Current Health is the number between 0 (broken) and the item's ObjectHealth
        if bAllNeedingRepair
         set iItemCurrentHealth to rItem.GetCurrentHealth
         set iItemObjectHealth to GetObjectHealth rItemBase
         set iItemHealthDifference to iItemObjectHealth - iItemCurrentHealth
         if iItemHealthDifference > 0
          set bTakeIt to 1
         elseif rItem.GetFullGoldValue >= iMinValueWeapon
          set bTakeIt to 1
         endif
        elseif rItem.GetFullGoldValue >= iMinValueWeapon
         set bTakeIt to 1
        endif
       else
        PrintC"Item not playable %n" rItem
       endif
      elseif iObjType == 21 ; Book
       if rItem.GetBookCantBeTaken == 0
        if rItem.GetBookIsScroll && rItem.GetFullGoldValue >= iMinValueScroll
         set bTakeIt to 1
        elseif rItem.GetFullGoldValue >= iMinValueBook
         set bTakeIt to 1
        endif
       endif
      elseif iObjType == 22 ; Clothing
       if rItem.IsPlayable2
        set iBipedMask to rItem.GetBipedSlotMask
        if iBipedMask >= 64 && iBipedMask <= 256 ; ring or amulet
         if rITem.GetFullGoldValue >= iMinValueJewelry
          set bTakeIt to 1
         endif
        elseif iBipedMask == 32768  ; Cape
         set bTakeIt to 1
        else
         if rItem.GetFullGoldValue >= iMinValueClothing
          set bTakeIt to 1
         endif
        endif
       endif
      elseif iObjType == 25 ; Ingredient
       set bTakeIt to 1
      elseif iObjType == 26 ; Light
       if bTakeTorches == 1
        set bTakeIt to 1
       endif
      elseif iObjType == 27 ; Misc. Item
       set iItemValue to rItem.GetFullGoldValue
       if iItemValue >= iMinValueMisc
        set bTakeIt to 1
       elseif rItemBase == Lockpick
        if bTakeLockpicks
         set bTakeIt to 1
        endif
       elseif rItemBase == Gold001 || rItemBase == WelkyndStone || rItemBase == cobTiAyleidCoin || rItemBase == RepairHammer
        set bTakeIt to 1
       elseif rItemBase.GetWeight > 0 && rItemBase.GetWeight < 0.5 && iItemValue > iMinValueMiscGems
        set bTakeIt to 1
       endif
      elseif iObjType == 33 ; Weapon
       if bAllNeedingRepair
        set iItemCurrentHealth to rItem.GetCurrentHealth
        set iItemObjectHealth to GetObjectHealth rItemBase
        set iItemHealthDifference to iItemObjectHealth - iItemCurrentHealth
        if iItemHealthDifference > 0
         set bTakeIt to 1
        elseif rItem.GetFullGoldValue >= iMinValueWeapon
         set bTakeIt to 1
        endif
       elseif rItem.GetFullGoldValue >= iMinValueWeapon
        set bTakeIt to 1
       endif
      elseif iObjType == 34 ; Ammo
       set iAttackDamage to rItem.GetAttackDamage
       set iAttackDamageNeeded to GetAttackDamage rMinDamageArrow
       if iAttackDamage >= iAttackDamageNeeded
        set bTakeIt to 1
       endif
      elseif iObjType == 38 || iObjType == 39  ; Soulgem or key
       set bTakeIt to 1
      elseif iObjType == 40   ; Alchemy Item
       if rItem.GetFullGoldValue >= iMinValueAlchItem
        set bTakeIt to 1
       endif
      else
       set bTakeIt to 1
      endif
      if bTakeIt == 1
       if rItem.IsScripted == 0
        rItem.RemovemeIR player
       else
        PrintC"Item %n is Scripted!  Num Items = %g" rItemBase, iNumItems
        Set iNumRefs to rItem.GetRefCount
        set iNumItems to rContainer.GetItemCount rItemBase
        if iNumItems != iNumRefs
         Message "Failed to move Scripted item %n.  Item count %g, ref count %g" rItemBase, iNumItems, iNumRefs
        else
         player.AddItemNS rItemBase iNumItems
         rItem.RemovemeIR
        endif
       endif
      endif
     loop
     PlaySound ITMTakeAll
     ClickMenuButton "#33" 1008
    else
     printC"Container set to NULL"
    endif  
   endif
  
  endif
 
  set curKey to RFTAKEALLKEY
endif
end
begin MenuMode 1026
if (fQuestDelayTime == 0)
  set fQuestDelayTime to 0.01
endif
if ( curKey && isKeyPressed3 curkey )
  return
else
  set curkey to 0
endif
set takebook to GetMenuFloatValue "book_background\book_take\visible" 1026

if ( isKeyPressed3 RFTAKEALLKEY )
  if (takebook == 2)
 
   ClickMenuButton "#32" 1026
  endif
 
  set curKey to RFTAKEALLKEY
endif
end

The relevant part is:

if bTakeIt == 1
       if rItem.IsScripted == 0
        rItem.RemovemeIR player
       else
        PrintC"Item %n is Scripted!  Num Items = %g" rItemBase, iNumItems
        Set iNumRefs to rItem.GetRefCount
        set iNumItems to rContainer.GetItemCount rItemBase
        if iNumItems != iNumRefs
         Message "Failed to move Scripted item %n.  Item count %g, ref count %g" rItemBase, iNumItems, iNumRefs
        else
         player.AddItemNS rItemBase iNumItems
         rItem.RemovemeIR
        endif
       endif
      endif

It's working for the specific situation I had with a ring (added by Vampire Hunting Order of the Virtuous Blood). I have code in there to try and catch anything unusual (like a situation were the rItem refers to a stack of items that are different from other items, like a stack of empty GrandSouldGems versus a stack of GrandSoulGems that have a grand soul in them. If that happens on a scripted item, I want to know about it.

 

Pellape, that looks like a really cool mod, but I don't want to download and install it and its requirements, just to see what you did with this situation. Please show me the logic you used to tackle that problem I am discussing.

 

Thanks.

Edited by GamerRick
Link to comment
Share on other sites

Well Just DL it and all scripts are in the Data\Scripts as textfiles. :wink:

 

The base file have 4 requirtements. COBL, OBSE and the Nine. I bet you already have them but maybe not old school dungeons. The addons I added do need more, and that is why I made them addons in the first place as they do require a lot of stuff to work. The base does not. All spells are in the base package.

Edited by Pellape
Link to comment
Share on other sites

Do you know the answer to my question or not? Telling me i have to download your 330MB mod to see if one of your text files has the answer or not is kinda what I would call asinine. If you don't want to take the time to cut/paste the relevant code you think will help, please go away.

Link to comment
Share on other sites

It was the requirements you did complain about but they are not many really.

 

Well thats true. It is the dynamic sorter you want to see?

 

The variables are stored in a quest script, which is the glue between the spells, so lets start with that one. All the spells trigger different parts of the quest script.

scn PekChestSortingQUSTSCR

float fQuestDelayTime

array_var ObjectArr
array_var ChestObjectBelongsToArr
array_var ChestArr
array_var ChestCellArr

string_var ButtonsStr
string_var ObjectStr

Ref Object
Ref Chest
Ref CellRef
Ref NotAChest
Ref ChestCell

Short InitiateArrays
Short AmmountOfChests   								; Number of chests added to the database
Short State
Short ScanningChest
Short ScanningObjects
Short ObjectType
Short NumberOfItems
Short ChestExist
Short DoOnce
Short TempState
Short Button
Short Debugg
Short ChestRemoved
Short ChestIndex
Short ItemIndex
Short MaxChests
Short ArraySizeCurrent
Short TempIndex
Short Round
Short StartItemIndex

Begin GameMode

	;Printc "State = %.0f" State

	If ( State == 0 )
		Set fQuestDelayTime to 1
		Return
	Else 
		If ( DoOnce == 0 )
			Set TempState to State
			Set State to 100
			Set DoOnce to 1
		EndIf
		Set fQuestDelayTime to 0.005
	EndIf

	
	; Creating the Databases
	If ( InitiateArrays == 0 )
		let ObjectArr := ar_Construct Array				; The object in the chest
		let ChestArr := ar_Construct Array				; All chests
		let ChestObjectBelongsToArr := ar_Construct Array     ; Amount of objects in each chests database
		Let ChestCellArr := ar_Construct Array
		
		Message "Initializing the sorter"
		printc "PEK Sorter: Initializing the sorter"
		
		Set NotAChest to 0
		
		Set InitiateArrays to 1
	EndIf

	; Adding a container to the quest database
	If ( State == 1 )
		If eval ( Chest != NotAChest )
			If ( Chest.IsContainer == 1)
				Let ChestExist := Call PekIsChestInDatabaseFUN Chest AmmountOfChests
			
				If ( ChestExist == 0 )
					Message "Adding the Chest to the Database"
					Set ChestCell to Chest.GetParentCell
					Let ChestArr[AmmountOfChests] := Chest
					Let ChestCellArr[AmmountOfChests] := ChestCell
					Let NumberOfItems := ar_Size ObjectArr
					Let AmmountOfChests := ar_Size ChestArr
					Set ChestIndex to AmmountOfChests - 1
					
					;PrintC "Items = %.0f - Chests = %.0f - ChestIndex = %.0f ", NumberOfItems, AmmountOfChests, ChestIndex
					
					Message "Scanning the Chest"
					Call PekChestScannerFUN Chest NumberOfItems ChestIndex

					Let AmmountOfChests := ar_Size ChestArr

					Message "Chest scanned"

				Else
					Message "That chest is already in the database"
				EndIf
			Else
				Message "That is not a Container where you ussually store your items in, is it?"
			EndIf
		Else
			Message "What did you point at? I bet there is no objects stored there."
		EndIf

		Set ButtonsStr to sv_Destruct
		Set ObjectStr to sv_Destruct
		
		Set State to 0
	EndIf
	
	; adding Objects to the sorter
	If ( State == 2 )
		Message "Scanning the chests for new objects"
		
		Set ScanningChest to 0
		
		While ( ScanningChest < AmmountOfChests )
			Let Chest := ChestArr[ScanningChest]
			Let NumberOfItems := ar_Size ObjectArr
			
			;Printc "Chest is %i %n - %.0f of items", Chest, Chest, NumberOfItems
			
			If eval ( Chest != NotAChest )
				If ( Chest.IsContainer == 1)
					Call PekChestScannerFUN Chest NumberOfItems ScanningChest
				EndIf
			EndIf
			
			Set ScanningChest to ScanningChest + 1
		Loop

		Set ButtonsStr to sv_Destruct
		Set ObjectStr to sv_Destruct
		
		Message "Scanning is completed"
		Set State to 0
	EndIf
		
	; Sorting the stuff to containers
	If ( State == 3 )
		Message "Sit on your hands. The sorting is initiated"
		Call PekSortingStuffFUN
		Set State to 0
		Message "The Items are sorted"

		Set ButtonsStr to sv_Destruct
		Set ObjectStr to sv_Destruct
	EndIf
	
	If ( State == 666 )
		Set ScanningChest to 0
		Set ChestRemoved to 0
		
		While ( ScanningChest < AmmountOfChests )
			Let Chest := ChestArr[ScanningChest]
			Let NumberOfItems := ar_Size ObjectArr
			If eval ( Chest == Object )
				Message "Removing the chest from the Sorter"
				ar_Erase ChestArr ScanningChest
				ar_Erase ChestCellArr ScanningChest
				Let AmmountOfChests := ar_Size ChestArr
			
				Set ScanningObjects to 0
				While ( ScanningObjects < NumberOfItems )
					Let chest := ChestObjectBelongsToArr[ScanningObjects]
					
					If ( Chest == Object ) 
						ar_Erase ObjectArr ScanningObjects
						ar_Erase ChestObjectBelongsToArr ScanningObjects
					EndIf
					
					Set ScanningObjects to ScanningObjects + 1
				Loop 
				
				Set ChestRemoved to 1
				Break
			EndIf

			Set ScanningChest to ScanningChest + 1
		Loop
		
		If ( ChestRemoved == 0 )
			Message "That chest is not added in the Sorter at all"
		ElseIf( ChestRemoved == 1 )
			Message "The Chest is removed from the Sorter"
		EndIf

		Set ButtonsStr to sv_Destruct
		Set ObjectStr to sv_Destruct
		
		Set State to 0
	EndIf
	
	
	If ( State == 100 )
		MessageBoxEX "Before you use the sorter, remove all stolen items from your containers as this sorter will clean all items that it sorts to keep database optimal.|Stop Sorting|Continue anyway"
		Set State to 101
	EndIf
	
	If ( State == 101 )
		Set Button to GetButtonPressed
		
		If ( Button == 0 )
			Set State to 0
		ElseIf ( Button == 1 )
			Set State to TempState
		EndIf
		
		If ( Button > -1 )
			MessageBox "A tip: Soul Gems are very special: Open the House settings at the left side of the entrance door or use the House Settings spell to set how you want to handle them with sorting and looting."
		EndIf
		
	EndIf
	
	If ( State == 10 )
		Set ChestIndex to 0
		Set Round to 0
		Let ArraySizeCurrent := ar_Size ChestArr
		If ( ArraySizeCurrent > 7 )
			Set MaxChests to 8
		Else 
			Set MaxChests to ArraySizeCurrent
		EndIf
		Let ButtonsStr := ""
		Set State to 11
	EndIf
	
	If ( State == 11 )
		While ( ChestIndex < MaxChests )
			Let Chest := ChestArr[ChestIndex]
			Let ChestCell := ChestCellArr[ChestIndex]
			Set ButtonsStr to sv_Construct "%z|%n - %n" ButtonsStr Chest ChestCell
			Let ChestIndex += 1
		Loop
		
		MessageBoxEX "Choose a Chest to be removed from the Sorter%z|Next Chests|Cancel" ButtonsStr
		Set State to 12
	EndIf
	
	If ( State == 12 )
		Set Button to GetButtonPressed
		
		If ( Button == 8 )
			Let ButtonsStr := ""
			Set MaxChests to MaxChests + 8
			If ( MaxChests > ArraySizeCurrent )
				Set MaxChests to ArraySizeCurrent
			EndIf
			Set State to 11
			Let Round += 1
		ElseIf ( Button == 9 ) 
			Set ButtonsStr to sv_Destruct
			Set ObjectStr to sv_Destruct
			Set State to 0
		ElseIf ( Button > -1 )
			Set State to 13
			Set TempIndex to Button
			MessageBoxEX "Are you sure you want to remove that chest?|Yes|No"
		EndIf
	EndIf
		
	If ( State == 13 )
		Set Button to GetButtonPressed
		
		If ( Button == 1 )
			Set ButtonsStr to sv_Destruct
			Set ObjectStr to sv_Destruct
			Set State to 0
		ElseIf ( Button == 0 )
			Set ChestIndex to TempIndex + ( Round * 8 )
			Let Object := ChestArr[ChestIndex]
			Object.pms effectDisintegrateArmor 3
			Printc "Chest Index = %g - Chest = %i %n removed" ChestIndex Object Object
			Set State to 666
		EndIf
	EndIf

	If ( State == 20 )
		Set ItemIndex to 0
		Set Round to 0
		Let ArraySizeCurrent := ar_Size ObjectArr
		If ( ArraySizeCurrent > 7 )
			Set MaxChests to 8
		Else 
			Set MaxChests to ArraySizeCurrent
		EndIf
		Let ButtonsStr := ""
		Set State to 21
	EndIf
	
	If ( State == 21 )
	
		Set StartItemIndex to ItemIndex
		While ( ItemIndex < MaxChests )
			Let Object := ObjectArr[ItemIndex]
			Set ButtonsStr to sv_Construct "%z|%n" ButtonsStr Object
			Let ItemIndex += 1
		Loop
		
		MessageBoxEX "Choose an Item to be removed from the Sorter (Easiest to just put the item in the Item Ignore Container really)%z|Next Items|Cancel" ButtonsStr
		Set State to 22
	EndIf
	
	If ( State == 22 )
		Set Button to GetButtonPressed
		
		If ( Button == 8 )
			Let ButtonsStr := ""
			Set MaxChests to MaxChests + 8
			If ( MaxChests > ArraySizeCurrent )
				Set MaxChests to ArraySizeCurrent
			EndIf
			Set State to 21
			Let Round += 1
		ElseIf ( Button == 9 ) 
			Set ButtonsStr to sv_Destruct
			Set ObjectStr to sv_Destruct
			Set State to 0
		ElseIf ( Button > -1 )
			Set State to 23
			Set TempIndex to Button
			MessageBoxEX "Are you sure you want to remove that Item?|Yes|No"
		EndIf
	EndIf

	If ( State == 23 )
		Set Button to GetButtonPressed
		
		If ( Button == 1 )
			Set ButtonsStr to sv_Destruct
			Set ObjectStr to sv_Destruct
			Set State to 0
		ElseIf ( Button == 0 )
			Set ItemIndex to TempIndex + ( Round * 8 )
			Let Object := ObjectArr[ItemIndex]
			Printc "Item Index = %g - Item = %i %n removed" ItemIndex Object Object
			ar_Erase ObjectArr ItemIndex
			ar_Erase ChestObjectBelongsToArr ItemIndex
			Set ItemIndex to StartItemIndex
			Let ButtonsStr := ""
			Set State to 21
		EndIf
	EndIf
	
	If ( State == 30 )
		Let ArraySizeCurrent := ar_Size ChestArr
		Set NumberOfItems to 0
		
		While ( NumberOfItems < ArraySizeCurrent )
			Let Chest := ChestArr[NumberOfItems]
			Let CellRef := ChestCellArr[NumberOfItems]

			If eval ( Object == NotAChest )
				ar_Erase ChestArr NumberOfItems
				ar_Erase ChestCellArr NumberOfItems
			Else
				Set ObjectStr to sv_Construct "%n - %n" chest CellRef
				Printc $ObjectStr
			EndIf
			
			Let NumberOfItems += 1
		Loop
		
		Let ArraySizeCurrent := ar_Size ObjectArr
		Set NumberOfItems to 0
		
		While ( NumberOfItems < ArraySizeCurrent )

			Let Object := ObjectArr[NumberOfItems]
			Let Chest := ChestObjectBelongsToArr[NumberOfItems]

			If eval ( Object == NotAChest )
				ar_Erase ObjectArr NumberOfItems
				ar_Erase ChestObjectBelongsToArr NumberOfItems
			Else
				Set ObjectStr to sv_Construct "%n - %n" Object Chest
				Printc $ObjectStr
			EndIf

			Let NumberOfItems += 1
		Loop

		Set ButtonsStr to sv_Destruct
		Set ObjectStr to sv_Destruct
		
		Set State to 0
	EndIf


	If ( State == 40 )
		Message "Resets all Chests and Items in the Sorter."
		ar_Resize ObjectArr 0
		ar_Resize ChestCellArr 0
		ar_Resize ChestObjectBelongsToArr 0
		ar_Resize ChestArr 0
		Set State to 0
	EndIf
	
End

The spellscript that adds the chests to the sorter

Scn PekAddChestToSortingDatabaseSPLSCR

Ref Chest

Begin ScriptEffectStart

	Set Chest to GetSelf
	Chest.pms effectOpen 4
End

Begin ScriptEffectFinish

    Set PekChestSortingQUST.chest to Chest
	Set PekChestSortingQUST.State to 1

	Dispel PekAddChestToSortingDatabaseSPL
End

When the chest is added to the database, and you add new stuff to a chest, this run this spell

Scn PekAddItemsToSortingDatabaseSPLSCR

Begin ScriptEffectFinish

	Set PekChestSortingQUST.State to 2

	Dispel PekAddItemsToSortingDatabaseSPL
End

The spell that sorts the stuff and removes all the clutter from your inventory

Scn PekSortStuffToContainersSPLSCR

Begin ScriptEffectFinish

	Set PekChestSortingQUST.State to 3

	Dispel PekSortStuffToContainersSPL
End

So the final spell removes a chest from the sorter. Can be useful in case something gets screwed up.

Scn PekRemoveChestToSortingDatabaseSPLSCR

Ref Chest

Begin ScriptEffectStart

	Set Chest to GetSelf
	
	Chest.pms effectDisintegrateArmor 3

End

Begin ScriptEffectFinish

	Set PekChestSortingQUST.Object to Chest

	Set PekChestSortingQUST.State to 666

	Dispel PekRemoveChestToSortingDatabaseSPL
End

I also recalled now that there is a house setting as well, that resets every chest, that cleans the database, removes all chests and items related to them.

Set PekChestSortingQUST.State to 30

As that is part of a very big questscript, it could be added to a button or a spell

 

 

The looting spells use the same script. One was made for touch and one for target. I use both. Target is best used when a companion is close to the body or container.

scn PekLootAllSPLSCR02

Ref TargetREF

Begin ScriptEffectStart

	Set TargetREF to GetSelf

	;TargetREF.Pms effectDisintegrateArmor 2
	TargetREF.pms effectOpen 4
	
End


Begin ScriptEffectFinish

	TargetREF.Pme Open
	
	If ( TargetREF.GetIsCreature == 1 || TargetREF.IsActor == 1 )
		if ( TargetREF.GetDead == 1)
			Call PekLootAllFUN02 TargetREF
			TargetRef.Disable
		Else
			Message "Kill it first, then loot it."
		EndIf
	ElseIf ( TargetREF.IsContainer == 1 )
		Call PekLootAllFUN TargetREF
	EndIf
	
	Dispel PekLootAllSPL
end

The functions:

Scn PekLootAllFUN

string_var LootedItemsSTR
string_var TempSTR

ref EmptyRef
ref RefID
Ref ItemRef

Short NumberOfItems
Short StackSize
Short SafetyBreak
Short State
Short Looted
Short Lootable
Short ItemType
Short Playable 

Begin Function {RefID}
	
	Set State to 0
	Set Looted to 0
	Set NumberOfItems to RefID.GetNumItems
	Set EmptyRef to 0
	
	If ( NumberOfItems == 0 )
		Set State to 666
	EndIf
	
	If ( NumberOfItems == 1 )
		Set ItemRef to RefID.GetInventoryObject 0
		Set TempSTR to sv_construct "%n", ItemRef
		If eval ( TempSTR == "Container Loot Token" )
			Set State to 666
		EndIf
	EndIf

	If ( State == 666 )
		Message "That target does not have any items to loot" 
		Return
	EndIf

	
	
	Set NumberOfItems to NumberOfItems - 1
	
	While ( NumberOfItems > -1 )
		
		Set SafetyBreak to SafetyBreak + 1
		
		Set ItemRef to RefID.GetInventoryObject NumberOfItems
		Set StackSize to RefID.GetItemCount ItemRef
		
		If ( StackSize != 0 || ItemRef != EmptyRef || ItemRef != RefID )
			set TempSTR to sv_construct "%n", ItemRef
			;printc "%i %n - ", ItemRef, ItemRef

			Set ItemType to GetObjectType ItemRef

			If ( ItemType == 22 )
			
				Set Playable to IsPlayable ItemRef
			
				If ( Playable == 1 )
					Set Lootable to 1
				Else
					Set Lootable to 0
				EndIf
				
			ElseIf ( ItemType == 38 )
				If ( PekHobbitHomeSettingsQST.SoulGems == 0 )
					Message "There is a Soul Gem in that container and if you want them looted, open the Hobbit Home house Settings"
					Set Lootable to 0
				ElseIf ( PekHobbitHomeSettingsQST.SoulGems == 2 )
					Set Lootable to 2
				EndIf
			Else 
				Set Lootable to 1
			EndIf

			If ( Lootable > 0 )
				If ( Lootable == 1 )
					Player.AdditemNS ItemRef StackSize
					set TempSTR to sv_construct "%.0f %n - ", StackSize, ItemRef
				ElseIf ( Lootable == 2 )
					Player.AdditemNS SoulGem5Grand5GrandSoul StackSize
					set TempSTR to sv_construct "%.0f Grand Soul Gem - ", StackSize

				EndIf
				RefID.RemoveItemNS ItemRef StackSize
				Let LootedItemsSTR := LootedItemsSTR + TempSTR
				Set Looted to 1
			EndIf

		EndIf
		
		Set NumberOfItems to NumberOfItems - 1
		
		If ( SafetyBreak > 500 )
			Message "There are more Items than 500 in that inventoy so you might want to cast the spell again"
			Break
		EndIf
		
	Loop
	
	If ( Looted == 1 )
		Let LootedItemsSTR := LootedItemsSTR + "...has been looted"
	
		MessageEX $LootedItemsSTR
		Printc $LootedItemsSTR

		Set LootedItemsSTR to sv_Destruct
		Set TempSTR to sv_Destruct
	Else 
		Message "That target does not have any items to loot"
	EndIf
	
End

Number 02

Scn PekLootAllFUN02

string_var LootedItemsSTR
string_var TempSTR

ref EmptyRef
ref RefID
Ref ItemRef

Short NumberOfItems
Short StackSize
Short SafetyBreak
Short State
Short Looted
Short Lootable
Short ItemType
Short Playable 

Begin Function {RefID}
	
	Set State to 0
	Set Looted to 0
	Set NumberOfItems to RefID.GetNumItems
	Set EmptyRef to 0
	
	If ( NumberOfItems == 0 )
		Set State to 666
	EndIf
	
	If ( NumberOfItems == 1 )
		Set ItemRef to RefID.GetInventoryObject 0
		Set TempSTR to sv_construct "%n", ItemRef
		If eval ( TempSTR == "Container Loot Token" )
			Set State to 666
		EndIf
	EndIf

	If ( State == 666 )
		Message "That target does not have any items to loot" 
		Return
	EndIf

	
	
	Set NumberOfItems to NumberOfItems - 1
	
	While ( NumberOfItems > -1 )
		
		Set SafetyBreak to SafetyBreak + 1
		
		Set ItemRef to RefID.GetInventoryObject NumberOfItems
		Set StackSize to RefID.GetItemCount ItemRef
		
		If ( StackSize != 0 || ItemRef != EmptyRef || ItemRef != RefID )
			set TempSTR to sv_construct "%n", ItemRef
			;printc "%i %n - ", ItemRef, ItemRef

			Set ItemType to GetObjectType ItemRef

			If ( ItemType == 22 )
			
				Set Playable to IsPlayable ItemRef
			
				If ( Playable == 1 )
					Set Lootable to 1
				Else
					Set Lootable to 0
				EndIf
				
			ElseIf ( ItemType == 38 )
				If ( PekHobbitHomeSettingsQST.SoulGems == 0 )
					Message "There is a Soul Gem in that container and if you want them looted, open the Hobbit Home house Settings"
					Set Lootable to 0
				ElseIf ( PekHobbitHomeSettingsQST.SoulGems == 2 )
					Set Lootable to 2
				EndIf
			Else 
				Set Lootable to 1
			EndIf

			If ( Lootable > 0 )
				If ( Lootable == 1 )
					Player.AdditemNS ItemRef StackSize
					set TempSTR to sv_construct "%.0f %n - ", StackSize, ItemRef
				ElseIf ( Lootable == 2 )
					Player.AdditemNS SoulGem5Grand5GrandSoul StackSize
					set TempSTR to sv_construct "%.0f Grand Soul Gem - ", StackSize

				EndIf
				RefID.RemoveItemNS ItemRef StackSize
				Let LootedItemsSTR := LootedItemsSTR + TempSTR
				Set Looted to 1
			EndIf

		EndIf
		
		Set NumberOfItems to NumberOfItems - 1
		
		If ( SafetyBreak > 500 )
			Message "There are more Items than 500 in that inventoy so you might want to cast the spell again"
			Break
		EndIf
		
	Loop
	
	If ( Looted == 1 )
		Let LootedItemsSTR := LootedItemsSTR + "...has been looted"
	
		MessageEX $LootedItemsSTR
		Printc $LootedItemsSTR

		If ( RefID.IsActor ==1 )
			If ( RefID.GetDead == 1 )
				RefID.disable
			EndIf
		EndIf

		Set LootedItemsSTR to sv_Destruct
		Set TempSTR to sv_Destruct
	Else 
		Message "That target does not have any items to loot"
	EndIf
	
End

I do not recall why I made 2 as they look similar.

 

Many scripts are nested, and use stuff crossed all over, so just remark the rows that points to other quests, like the housesettingsquest

 

I might missed some functions as I just noticed, this one is used as well:

Scn PekChestScannerFUN

Ref Chest
Ref ObjectInChest
Ref ObjectInDatabase
Ref EmtpyRef

Short NumberOfObjectsCurrent
Short NumberOfObjectsDatabase
Short ObjectExistInDatabase
Short Index
Short ChestIndex

Begin Function {Chest NumberOfObjectsDatabase ChestIndex} 

	Set EmtpyRef to 0
	Set ObjectExistInDatabase to 0
	Let NumberOfObjectsCurrent := Chest.GetNumItems
	
	PrintC "Scanner FUN: Items = %.0f" NumberOfObjectsCurrent
	
	While ( NumberOfObjectsCurrent > -1 )
		Set ObjectInChest to chest.GetInventoryObject NumberOfObjectsCurrent
		Set Index to NumberOfObjectsDatabase - 1
		
		PrintC "Scanner FUN: Index = %.0f" Index
		
		While ( Index > -1 )
			Let ObjectInDatabase := PekChestSortingQUST.ObjectArr[index] 
			If eval (ObjectInChest == ObjectInDatabase )
				Set ObjectExistInDatabase to 1
				break
			EndIf
		
			Let Index -= 1
		Loop
		
		If ( ObjectExistInDatabase == 0 )
			If eval ( ObjectInChest != EmtpyRef ) 
				Let NumberOfObjectsDatabase := ar_Size PekChestSortingQUST.ObjectArr
				Let PekChestSortingQUST.ObjectArr[NumberOfObjectsDatabase] := ObjectInChest
				Let PekChestSortingQUST.ChestObjectBelongsToArr[NumberOfObjectsDatabase] := Chest
			EndIf
		EndIf
		
		PrintC "Scanner FUN: Database = %.0f - Object = %i %n" NumberOfObjectsDatabase ObjectInChest ObjectInChest
		
		Let NumberOfObjectsCurrent -= 1
	Loop
	
End
Edited by Pellape
Link to comment
Share on other sites

Well it might be easiest if you only which to auto sort clutter and have it sold, is that I make an early beta release of the merchant mod. It is very small right now and has all the basics working.

 

4 meshes so far, thats all + textures for those meshes

  1. adds a container that adds stuff to a database 08:00 daily
  2. add a button that cleans the inventory from clutter and adds the stuff in to the sell container
  3. adds a chest that sell all stuff 20:00 every day
  4. A safe for all your shinies.
Edited by Pellape
Link to comment
Share on other sites

Thanks!! Here is the part of all that code that is related to my question:

If ( Lootable > 0 )
    If ( Lootable == 1 )
     Player.AdditemNS ItemRef StackSize
     set TempSTR to sv_construct "%.0f %n - ", StackSize, ItemRef
    ElseIf ( Lootable == 2 )
     Player.AdditemNS SoulGem5Grand5GrandSoul StackSize
     set TempSTR to sv_construct "%.0f Grand Soul Gem - ", StackSize
    EndIf
    RefID.RemoveItemNS ItemRef StackSize
    Let LootedItemsSTR := LootedItemsSTR + TempSTR
    Set Looted to 1
   EndIf

You just do an AddItemNS/RemoveItemNS on them. You don't even get the question I am asking here.

 

The problems with that are the gist of my question. Those commands operate on base objects, they loose any settings that are at the refID level, like ownership (for all items), soul size (for soulgems), and the current health of an object (for weapons and armor).

 

Also, it looks like you are doing the RemoveItemNS inside of looping through the items in the container container. You can't do that!

Link to comment
Share on other sites

Yes I can do that if I start at the top and go down in the loop, it means that I always remove a object, then count down the loop. If you go from 0 and up, you sure will get problems and the pointers will point at the wrong object or at something that do not exist in the end.

Set Turn to Container.GetObjectCount 

While ( Turn > -1 )

Let Item := container.GetInventoryObject Turn
container.removeitem item count
Let Turn -= 1

Loop

Nothing wrong with that. This loop is perfect. So what is wrong with it?

 

 

References, not Objects?

I did remake the loot reference book script some. It works on references outside containers and loose objects. You must use GetFirstRef and GetNextRef for anything outside a container.

ref pDoor
...
set pDoor to GetFirstRef 24 1
while (pDoor)
  ; do something with pDoor
  set pDoor to GetNextRef
loop

To remove the item, it is easiest to move it to a container and then remove it. Only way to remove loose references in the game is disable. We did had a delete command in Morrowind that was removed.

 

So in Morrowind we could:

object->Disable
Object->Setdelete

I am not sure I used the right syntax here really. I have not coded Morrowind for 2 years. I do recall it use -> intead of . So if an object do not get added to a container, the only way to remove it is disable, nothing else works.

 

So if we add an object to the player with

prid object
activate player

;or

object.activate player

How do the game remove it from the world when it adds it to the player? IDK...

Here is a complete script for loose objects and references, originally made by d4v3 . It loots everything around the player, withing a radies of 300, which can ve adjusted, but 300 makes sence, as it is withing the players reach and are more immersive. You can loot the whole cell with a higher radies.

 

A cloth object called PekDBLToken that is not playable. It has this script.

ScriptName PekDblTokenScript

;Originally made by d4v3 - Book Looting Spell
;Runs on adding DblToken to player

string_var LootedItemsSTR
string_var TempSTR

Ref PekDblItem
Ref PekDblOwner
Ref PekDblWitness
Ref PekDblItemBase

Short PekDblFlag
Short PekDblTakeIt
Short PekDblDoOnce
Short PekDblDetected
Short PekDblValue
Short PekDblScripted
Short PekDblIModIndx
Short PekDblModLoaded

Short State
Short ItemType
Short ClothPlayable
Short SoulGemsGrand
Short Looted

Begin OnAdd
	Set PekDblFlag to 1
	Set PekDblDoOnce to 0
	Set PekDblDetected to 0
	Set State to 0
End

Begin GameMode


	If PekDblFlag == 1

		If ( State == 0 )
			Set Looted to 0
			Set ItemType to 21
			Set State to 1
		EndIf

		Set SoulGemsGrand to 0
		Set PekDblItem to Apple
		Set PekDblItem to GetFirstRef ItemType ;find first book reference in this cell
		Label 1 ;Start of book loop
		If PekDblItem ;If the current Reference exists
			Set PekDblTakeIt to 0 ;assume it can't be taken, unless:
			If PekDblItem.GetDistance Player < 300 ;is it within radius
				If ( PekDblItem.IsOffLimits 7 == 0 ) ;if player is not stealing
					Set PekDblTakeIt to 1 
				ElseIf Player.IsSneaking ;allow stealing if player is sneaking
					Set PekDblTakeIt to 1
				EndIf
				If PekDblTakeIt ;make sure item is a regular book

					If ( State == 1 ) 
						If PekDblItem.IsQuestItem ;book is a quest item
							Set PekDblTakeIt to 0
						ElseIf PekDblItem.IsScroll ;Book is a scroll
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetBookCantBeTaken ;cant be taken so ignore it
							Set PekDblTakeIt to 0
						ElseIf PekDblItem.GetBookSkillTaught > -1 ;book teaches - leave
							Set PekDblTakeIt to 0
						ElseIf PekDblItem.IsScripted ;has script - leave ; unless IO is loaded and it is vanilla Oblivion book ie don't loot scripted books from other mods
							Set PekDblTakeIt to 0
							If ( IsModLoaded "bookplacing.esm" )
								Set PekDblTakeIt to 2
							EndIf
							If ( IsModLoaded "Intelligence Overhaul.esp" )
								Set PekDblTakeIt to 3
							ElseIf ( IsModLoaded "Intelligence Overhaul BJ.esp" )
								Set PekDblTakeIt to 3
							EndIf	
						EndIf
						If PekDblTakeIt > 1 ;book scripted by another mod - check if it is a vanilla book
							If PekDblItem.GetIsID Book1CheapBiographyofBarenziahvI == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapBiographyofBarenziahvII == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapBiographyofBarenziahvIII == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapBiographyofBarenziahvIV == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapBriefHistoryoftheEmpirev1 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapBriefHistoryoftheEmpirev2 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapBriefHistoryoftheEmpirev3 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapBriefHistoryoftheEmpirev4 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapCharterMagesGuild == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideAnvil == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideBravil == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideBruma == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideCheydinhal == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideChorrol == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideImperialCity == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideLeyawiin == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapGuideSkingrad == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book1CheapReportDisasterIonith == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonBeggarPrince == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonBookofDaedra == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonDarkestDarkness == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonEasternProvinces == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonFrontierConquest == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonFundamentsofAlchemy == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonGalerionTheMystic == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonIstunondsCosmology == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonManualArmor == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonManualArms01 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonManualMixedUnitTactics == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonManualSpellcraft == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonMorrowindImperialProvince == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonMysteriousAkavir == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonOverviewofGodsandWorship == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonRealBarenziahV1 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonRealBarenziahV2 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonRealBarenziahV3 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonRealBarenziahV4 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonRealBarenziahV5 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonRuinsofKemelZe == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonShortLifeUrielSeptim == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonThiefOfVirtue == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2CommonThievesGuildMythOrMenace == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2ReligiousChildrensAnuad == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2ReligiousTenCommandoftheNine == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2ReligiousTheAmuletofKings == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book2ReligiousTrialsofStAlessia == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3Valuable2920v11a == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3Valuable2920v12a == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3Valuable2920v3a == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableAevarStoneSinger == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableArgonianAccountBook2 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableArgonianAccountBook4 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableAzuraandtheBox == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableDwemerHistory == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableFeyfolkenI == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableFeyfolkenII == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableFeyfolkenIII == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableHistoryOfLockPicking == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableLustyArgonianMaid == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableMadnessofPelagius == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableMagicFromTheSky == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableMoreThanMortal == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableOnOblivion == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuablePallav2a == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuablePrincessTalaraV5 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableProvincesofTamriel == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableSnowPrince == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableTamrielicLore == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableTheFirmament == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableTheSeed == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableTheThirdDoor == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableVarietiesofDaedra == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book3ValuableWolfQueenV8 == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareArcanaRestored == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareBrothersofDarkness == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareCharterDarkBrotherhood == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareCharterThievesGuild == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareChildrenoftheSky == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareFiveSongsofKingWulfharth == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareFragmentOnArtaeum == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareGloriesAndLaments == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareHangingGardens == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareLastKingOfAyleids == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareMysticism == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareMysticism == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareNerevarMoonandStar == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareNGastaKvataKvakis == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareOldWays == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareOriginoftheMagesGuild == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RarePigChildren == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RarePostingoftheHunt == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareRedBookofRiddles == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareSancreTor == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareSpiritoftheDaedra == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareTrueNatureofOrcs == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareWatersofOblivion == 1
								Set PekDblTakeIt to 1
							ElseIf PekDblItem.GetIsID Book4RareWildElves == 1
								Set PekDblTakeIt to 1
							EndIf
						EndIf
					EndIf
					
					If PekDblTakeIt == 3 ;IO loaded - check if it is a teaching book
						If PekDblItem.GetIsID Book4RareCharterFightersGuildFirstEdition == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID MQ05CommentariesV2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAcrobatics1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAcrobatics2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAcrobatics3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAcrobatics4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAcrobatics5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlchemy1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlchemy2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlchemy3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlchemy4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlchemy5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlteration1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlteration2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlteration3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlteration4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAlteration5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxArmorer2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxArmorer3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxArmorer4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxArmorer5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAthletics1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAthletics2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAthletics3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAthletics4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxAthletics5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlade1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlade2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlade3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlade4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlade5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlock1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlock2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlock3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlock4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlock5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlunt1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlunt2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlunt3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlunt4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxBlunt5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxConjuration1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxConjuration2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxConjuration3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxConjuration4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxConjuration5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxDestruction1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxDestruction2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxDestruction3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxDestruction4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxDestruction5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHandtoHand1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHandtoHand2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHandtoHand3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHandtoHand4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHandtoHand5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHeavyArmor1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHeavyArmor2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHeavyArmor3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHeavyArmor4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxHeavyArmor5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxIllusion1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxIllusion2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxIllusion3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxIllusion4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxIllusion5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxLightArmor1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxLightArmor2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxLightArmor3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxLightArmor4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxLightArmor5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMarksman1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMarksman2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMarksman3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMarksman4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMarksman5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMercantile1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMercantile2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMercantile3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMercantile4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMercantile5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMysticism1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMysticism2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMysticism3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMysticism4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxMysticism5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxRestoration1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxRestoration2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxRestoration3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxRestoration4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxRestoration5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSecurity1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSecurity2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSecurity3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSecurity4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSecurity5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSneak1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSneak2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSneak3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSneak4 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSneak5 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSpeechcraft1 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSpeechcraft2 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSpeechcraft3 == 1
							Set PekDblTakeIt to 1
						ElseIf PekDblItem.GetIsID SKLxSpeechcraft4 == 1
							Set PekDblTakeIt to 1
						EndIf
					EndIf
					If PekDblTakeIt > 1
						Set PekDblTakeIt to 0
					EndIf
				EndIf
				
				If ( ItemType == 22 )
					Set ClothPlayable to PekDblItem.IsPlayable 
					If ( ClothPlayable == 0 )
						Set PekDblTakeIt to 0
						PrintC "Not Playable"
					EndIf

					If ( PekDblItem == PekDblStealItemRef )
						Set PekDblTakeIt to 0
						PrintC "Found the stolen Item"
					EndIf
				EndIf
				
				If ( ItemType == 38 )
					If ( PekHobbitHomeSettingsQST.SoulGems == 0 )
						Message "There is a Soul Gem close by and if you want them looted, open the Hobbit Home house Settings"
						Set PekDblTakeIt to 0
					ElseIf ( PekHobbitHomeSettingsQST.SoulGems == 2 )
						Set SoulGemsGrand to 1
					EndIf
				EndIf				
				
				If ( PekDblItem.IsScripted )
					Set PekDblTakeIt to 0
				EndIf
				
				
				If PekDblTakeIt ;take it or steal it
					If  ( PekDblItem.IsOffLimits 7 == 0 ) ;if player not stealing
						Set PekDblItemBase to PekDblItem.GetBaseObject
						PekDblItem.Activate PekDblBookShelfRef ;Activate sets book as unreadable when next activated, so
						PekDblBookShelfRef.RemoveAllItems ;remove it and

						If ( SoulGemsGrand == 1 )
							Player.AdditemNS SoulGem5Grand5GrandSoul 1
							Let TempSTR := "Grand Soul Gem - "
						Else
							Player.AddItemNS PekDblItemBase, 1 ;add a new copy to player
							set TempSTR to sv_construct "%n - ", PekDblItemBase
						EndIf

						Set Looted to 1

					Else
						If Player.IsActorDetected && ( PekDblDoOnce == 0 ) ;if observed set crime committed
							Set PekDblDoOnce to 1
							Set PekDblOwner to PekDblItem.GetOwner ;get owner of items - only run once per spell - assume all items are same owner
							If ( PekDblOwner == 0 )
								Set PekDblOwner to PekDblItem.GetParentCellOwner
							EndIf
							Set PekDblWitness to Apple
							Set PekDblWitness to GetFirstRef 35 ;Find first NPC Reference
							Label 2 ;Start of NPC loop
							If PekDblWitness
								If ( PekDblWitness.GetDetectionLevel Player > 1 ) && ( PekDblWitness.GetFactionRank PlayerFaction == -1 ) && ( PekDblWitness.GetAV Responsibility > 29 )
									Set PekDblDetected to 1
								EndIf
								Set PekDblWitness to Apple
								Set PekDblWitness to GetNextRef
								Goto 2
							EndIf
						EndIf
						If PekDblDetected ;make sure the NPC 'steal' dialogue kicks in, and book is taken off you
							PekDblStealItemRef.MoveTo Player -10 0 0 ;move stealitem to cell
							PekDblStealItemRef.SetOwnership PekDblOwner ;set ownership to owner
							Set PekDblValue to PekDblItem.GetGoldValue ;gets value of item
							PekDblStealItemRef.SetGoldValue PekDblValue ;copy value to stealitem
							PekDblStealItemRef.Activate Player ;pick up stealitem to trigger 'steal' on NPC
							Player.Drop PekDblStealItem 1 ;drop item
							PekDblStealItemRef.MoveTo PekDblBookShelfRef -10 0 0 ;move stealitem back to holding cell
							Set PekDblItemBase to PekDblItem.GetBaseObject
							Player.AddItemNS PekDblItemBase, 1 ;add item silently to player, then
							Player.RemoveItem PekDblItemBase, 1 ;remove it to get the usual 'removed' message when stealing
							PekDblItem.Activate PekDblBookShelfRef ;move item to bookshelf then
							PekDblBookShelfRef.RemoveAllItems ;remove it
						Else ;steal it
							Set PekDblItemBase to PekDblItem.GetBaseObject
							PekDblItem.Activate PekDblBookShelfRef ;Activate sets book as unreadable when next activated in the game world therefore
							PekDblBookShelfRef.RemoveAllItems ;remove it and
							PekDblBookShelfRef.AddItem PekDblItemBase, 1 ;add new item to bookshelf so as to 
							PekDblBookShelfRef.RemoveAllItems Player, 1 ;retain 'stolen' ownership
						EndIf
					EndIf
				EndIf
			EndIf
			Let LootedItemsSTR := LootedItemsSTR + TempSTR
			Set PekDblItem to Apple
			Set PekDblItem to GetNextRef
			Goto 1
		EndIf

		; End the script
		If ( State == 10 )
			Set State to 0
			Set PekDblFlag to 0
			
			If ( Looted == 1 )
				Let LootedItemsSTR := LootedItemsSTR + "...has been looted"
				MessageEX $LootedItemsSTR
				;Printc $LootedItemsSTR
			EndIf
			
			Return
		EndIf
		
		; Loot Apparateus
		If ( State == 9 )
			Set State to 10
			Set ItemType to 19
			Return
		EndIf

		; Loot Key
		If ( State == 8 )
			Set State to 9
			Set ItemType to 40
			Return
		EndIf

		; Loot Soulgem
		If ( State == 7 )
			Set State to 8
			Set ItemType to 38
			Return
		EndIf
		
		; Loot Ammo
		If ( State == 6 )
			Set State to 7
			Set ItemType to 34
			Return
		EndIf

		; Loot Weapons
		If ( State == 5 )
			Set State to 6
			Set ItemType to 33
			Return
		EndIf
		
		; Loot Armor
		If ( State == 4 )
			Set State to 5
			Set ItemType to 20
			Return
		EndIf		
		
		; Loot Misc
		If ( State == 3 )
			Set State to 4
			Set ItemType to 27
			Return
		EndIf
		
		; Loot Ingredients
		If ( State == 2 )
			Set State to 3
			Set ItemType to 25
			Return
		EndIf
		
		; Loot Clothes
		If ( State == 1 )
			Set State to 2
			Set ItemType to 22
			Return
		EndIf
		
	Else ;token not in players posession
		Set PekDblFlag to 0
		Set LootedItemsSTR to sv_Destruct
		Set TempSTR to sv_Destruct
		RemoveMe
	EndIf
	
	
	
End

The spell:

ScriptName PekDblSpellScript

;Originally made by d4v3 - Book Looting Spell
;runs when loot spell is cast - adds DblToken to player

Short PekDblCount

Begin ScriptEffectStart
	If Player.GetItemCount PekDblToken == 0
		Player.AddItemNS PekDblToken, 1
	EndIf
End

Begin ScriptEffectFinish
	Set PekDblCount to Player.GetItemCount PekDblToken 
	If PekDblCount > 0
		Player.RemoveItemNS PekDblToken, PekDblCount
	EndIf
End 

PekDblBookShelfRef = Kjajiit NPC, with responsibility of 50, a thief that reports crime, if you get caught using the spell in an owned cell.

 

PekDblStealItem = an Amulet

 

The spell has a duration of 4s

 

I also refer to the house settings at some point, that can be remarked with ;

 

I also saw the script gets the gold value, with GetGoldValue at some point. The more correct function would be

GetFullGoldValue

 

I do not remember why the goldvalue was checked. The script works good as it is.

 

I used this for books only at first. But I wanted it to loot everything, so it does. I filter out the stuff with the sorting spells later and now with my new Shop Mod.

GetFullGoldValue

Edited by Pellape
Link to comment
Share on other sites

  • Recently Browsing   0 members

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