Jump to content

[LE] Setting and getting ownership of objects you pick up


Recommended Posts

I'm trying to make a script that does something when you pick up gold and jewels that you don't already own, like when you're getting them from a dungeon chest, but not from your stash in Breezehome.

 

My plan is by assigning ownership to the items: set their ownership to the player or some dummy actorBase whenever you drop said items or place them in a container, and only run the script if the ownership isn't either of those. Here's the code i'm using:


miscObject property gold auto

keyword property gem auto

actorbase property dummy auto

Event OnItemAdded(Form akBaseItem, Int akitemCount, ObjectReference akItemReference, Objectreference akSourceContainer)
	debug.notification(akitemreference.getactorowner().getformid())
	if akitemreference.getactorowner() == dummy
		debug.notification("you already own this")
		return
	elseif akBaseItem.getformID() == gold.getformID() 
		debug.notification("caching!")
	elseif akbaseitem.haskeyword(gem)
		debug.notification("bling bling!")
	endif
endEvent

Event OnItemRemoved(Form akBaseItem,Int akitemcount, ObjectReference akItemReference, ObjectReference akDestContainer)
	if akBaseItem.getformID() == gold.getformID() || akBaseItem.haskeyword(gem)
		akitemreference.setactorowner(dummy)
	endif
endEvent

The problem is, whenever it prints the form id of the item's owner, it's always 0, even if it's something i stole from an NPC, so the code runs as if nobody owns the item taken, even if it was supposed to be assigned to the "dummy" actorBase.

 

So is there something i'm missing? Is an object's ownership supposed to disappear as soon as it's picked up?

Link to comment
Share on other sites

Anytime you transfer an item from a container or another actor the reference, or if the item is considered non persistent, the akItemReference will be None. You only get a reference if it's in the world (ie been dropped or placed in the world) or if it's made persistent either by being in an alias, script property, or placed as a permanent persistent item.

Link to comment
Share on other sites

Anytime you transfer an item from a container or another actor the reference, or if the item is considered non persistent, the akItemReference will be None. You only get a reference if it's in the world (ie been dropped or placed in the world) or if it's made persistent either by being in an alias, script property, or placed as a permanent persistent item.

i was afraid of something like that. looks like i'm going to have to use a much more complicated solution

Link to comment
Share on other sites

Most items won't have any ownership information associated with them. The vast majority of items inherit their ownership status from the container or location where you find them. And the game effectively destroys items when they are placed in containers and instead represents them as a name, a count, and then a list of detail records. So if the player has 5 rubies and then picks up a new one the game generally just destroys the item being "picked up" and changes the player's ruby count to 6. If taking that ruby would be considered stealing, then the game makes a note that the player has one stolen ruby. So trying to manipulate the actual items being collected is impossible unless you replace every single item into a persistent reference which you absolutely don't want to do for something like gold!

 

There's not going to be a clean, completely accurate way to track ownership. You're going to have to make some generalized decisions based on location (and possibly use hidden marker objects to help) to approximate whatever you're trying to do. It's going to be the source container parameter that's most useful to you because with it you can decide where the item came from and take a guess about ownership. And you can use destination container to place special markers if you want to get fancy. The details of what you need to do will depend on what you're really trying to accomplish.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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