Jump to content

Difference between inventory object and base object, attempting to decrement enchantment charge of inventory item


MaxYari

Recommended Posts

I'm quite confused with what the difference between base object and inventory object?
I understand that inventory object is kinda base object and it's not a reference, but it also includes some additional info, for example it current enchantment charge and maybe inventory slot number (I assume if you have multiple objects with different enchantment charges, so they are not displayed as a stack - then providing RemoveItem with inventory reference of that object - will only remove that object, but I might be wrong)

So can someone please explain?

And to be specific I'm trying to edit enchantment charge of the item in the inventory, I can do that by setting charge to specific value on temporal reference and then inserting it back into container, but I want to decrement value so I need to have access to specific inventory item and not just base full enchantment, or at least a way to get a hold of that current enchantment value of the specific item and not just it's base, which will always return max enchantment.

What i'm currently doing:

begin OnEquip	
	set item to GetBaseObject
	...
	let AAEHquest.activeFistWeapon := item ; this is used as "item" in a function below
	...
end
;===Edit weapon charge through temporal reference===
	Print "Attempting to edit temp ref charge"	
	containerRef.RemoveItem item 1
	Print "Getting temp ref"
	let itemRef := CreateTempRef item
	
	Print "Editing charge of " + $itemRef.GetName
	let enchantment := GetEnchantment item
	let chargeCost := GetEnchantmentCost enchantment
	let currentCharge := itemRef.GetCurrentCharge
	if currentCharge >= chargeCost
		let chargeCost := chargeCost * -1
		itemRef.ModCurrentCharge chargeCost
		Print "Subtracted " + $chargeCost + " from " + $currentCharge
	else
		Print "Not enough charge!"
		Message "Not enough charge!"
	endif	
	
	Print "Putting edited weapon into " + $containerRef + " container"
	itemRef.CopyIR containerRef
	let itemRef := 0
	Print "Done editing temp ref"
	;==========================================

As a result I get an item with a charge decremented from it's max and not it's current since ModCurrentCharge, as i assume was run on a temporal reference created from the base and not from my specific item... which makes sense since item is from GetBaseObject from onEquip, but I haven't found any way to get more of a proper inventory item reference and not just base object, so, what do?

Update:

I've used this now to get proper inventory reference now:

let inventoryRefs := containerRef.GetInvRefsForItem item
	Print "Array " + $inventoryRefs + " " + $ar_Size inventoryRefs	
	ForEach ir <- inventoryRefs
		Print $itemRef
   		let itemRef := ir["value"]
	Loop

but itemRef.GetCurrentCharge still returns max charge and not current :sad:

Thank you in advance!

Update 2: Ok i poked around and i think i solved it in some strange quirky way by using RemoveMeIR with a destination being player inventory which somehow actually properly replaces reference of the item in inventory with this temporary in a way that even the initial itemRef gets updated!
I'll post my code changes tomorrow, too tired rn, have a good night/day everyone!

Edited by SinnerSmile
Link to comment
Share on other sites

I think the items you enchant your self gets a complete new base ID and even get independent of the mod they comes from at the first place and I base this on my own experiance.

 

I added an axe in my mod and I followed its progress some. I enchanted it and gave it a new name and it got a base ID of FFxxxxxx and it will remain in my inventory even if I uncheck my mod. Stuff in the inventory do have the base ID.

Link to comment
Share on other sites

If you provide additional info to the OnEquip part, there's no need to list entire inventory. And for a charge modification you can use ModEquippedCurrentCharge command.

begin OnEquip

set item to GetBaseObject
set actor to GetContainer
set slot to GetEquipmentSlot item

set AAEHquest.activeFistWeapon to item
set AAEHquest.containerRef to actor
set AAEHquest.slotFistWeapon to slot

end

And then:

if activeFistWeapon != 0 && containerRef != 0 && slotFistWeapon != 0
        let test_item := containerRef.GetEquippedObject slotFistWeapon ;still equipped on actor?
	if test_item == activeFistWeapon ; yes
		let enchantment := GetEnchantment activeFistWeapon
		if enchantment != 0
                        print $activeFistWeapon+" is magical."
			let ench_max := GetObjectCharge activeFistWeapon
			let currentCharge := containerRef.GetEquippedCurrentCharge slotFistWeapon
			print "Charged to "+$currentCharge+" /"+$ench_max+"."
			containerRef.ModEquippedCurrentCharge -1 slotFistWeapon
		endif
	endif
endif

I simplified the example for showing the technicals, you should see the charge of this item slowly decreasing.

Edited by Guest
Link to comment
Share on other sites

Yes

 

I think the items you enchant your self gets a complete new base ID and even get independent of the mod they comes from at the first place and I base this on my own experiance.

 

I added an axe in my mod and I followed its progress some. I enchanted it and gave it a new name and it got a base ID of FFxxxxxx and it will remain in my inventory even if I uncheck my mod. Stuff in the inventory do have the base ID.

Oh well, this is for the weapon that is NOT equipped so i had to do that inventory lookup, but doing

let inventoryRefs := containerRef.GetInvRefsForItem item
let itemRef := inventoryRefs[0]
;edit item charge
itemRef.RemoveMeIR playerRef 

Did the trick. I've written this from memory so i migh have butchered someting, but the idea is to get ref, edit it and then remove original from inventory while inserting edited ref (that what RemoveMeIR suppose to do).

Link to comment
Share on other sites

I think the items you enchant your self gets a complete new base ID and even get independent of the mod they comes from at the first place and I base this on my own experiance.

 

I added an axe in my mod and I followed its progress some. I enchanted it and gave it a new name and it got a base ID of FFxxxxxx and it will remain in my inventory even if I uncheck my mod. Stuff in the inventory do have the base ID.

Hey, interesting that you mentioned it, my mod suppose to allow people to enchant mod weapons but enchanting one seem to remove the script attached to a weapon, which is pretty crucial... any idea what to do about it? Maybe it's possible to reattach script after enchantment?

I mostly use onEquip block in the item script which i can replace with OBSE event, but it will still have no idea how to determine that this enchanted item is the modded item on which that block should run.

 

I just did this:

let baseItem := GetEnchMenuBaseItem
	Print "Created enchanted item: " + $enchantedItem + " from " + $baseItem
	let baseScript := GetScript baseItem;
	Print "Moving script " + $baseScript + GetEditorID baseScript + " to " + $enchantedItem	
	SetScript baseScript enchantedItem

And it seems to kinda work but only after i drop and pickup said enchanted item, so now I'm trying to figure out how to "activate" that inventory item through script (so onEquip block works) :\

 

Upd: Oh, actually it seems that it works even without doing setscript, only issue is that script on enchanted item gets deactivated until you drop and pick it up.

Edited by SinnerSmile
Link to comment
Share on other sites

The trick might be to attach the script to the enchant instead of the weapon? But then it always require that specific enchant. It doesn't look like we can use specific enchants in the enchanter anyway, only the base effects of the known spells. But still, if yoiu add the weapon pre-enchanted, add the script to the enchant but then it must be a magic effect, like an ability if you want a constant effect that is.

Link to comment
Share on other sites

The trick might be to attach the script to the enchant instead of the weapon? But then it always require that specific enchant. It doesn't look like we can use specific enchants in the enchanter anyway, only the base effects of the known spells. But still, if yoiu add the weapon pre-enchanted, add the script to the enchant but then it must be a magic effect, like an ability if you want a constant effect that is.

But then weapon will not be enchantable, having it enchantable and having the script attached to it is like the whole point of the mod. Seems my option is either to activate that item somehow or to track onequip from OBSE event instead while saving those enchanted references into array for further lookup or something.

 

Upd: Since this discussion is not related to the topic anymore, i've created a new one https://forums.nexusmods.com/index.php?/topic/10067718-enchanting-item-with-script-disables-script-execution-until-item-is-dropped-and-picked-up/

Edited by SinnerSmile
Link to comment
Share on other sites

  • Recently Browsing   0 members

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