Jump to content

Detecting item ownership (steal/trespass code)


dubiousintent

Recommended Posts

Anyone know where the code in vanilla game resides that handles determining that an object is "owned", resulting in the HUD displaying the red label indicating it would be considered stealing (or trespassing or illegal in some manner) if you "grab" the item under the cursor? I'm not interested in the HUD display portion; just where the code that is actually checking that the ownership property is/isn't "player" is located.

 

TIA. -Dubious-

Link to comment
Share on other sites

That's built into the game executable, isn't it? I don't think that you can modify it. I'm pretty sure it's not a script function that the game calls.

 

It's just checking the ownership field of the item, which you configure in the GECK. You can change the ownership of an item using SetOwnership and if you want to check the ownership of an item yourself there's the IsOwner function.

 

The way the game determines if an item is owned is it checks the ownership of a specific reference of an item, and if there is no owner set there, it checks the ownership of the cell that the item is located in. So it is possible that an item will show up as owned even if it has no owner set, just because it is inheriting its ownership from the cell owner. IsCellOwner can be used to check the cell's ownership and SetCellOwnership can be used to set it to a specific NPC (or the player).

Link to comment
Share on other sites

Nuts! Thanks for confirming it functions pretty much as I expected, and the names of the functions involved. But I had hoped to tap into the existing code to add some additional checks, such as determining if the "Owner" is dead. Figure since the game was already doing most of that it made the simplest approach to tap into it.

 

Can't seem to find the function to return the reference of an item currently under the cursor ('about to be but not yet' grabbed)? Seems inefficient to process everything in a cell if only certain objects are of interest.

 

Suggestions on how to trigger my code check before you would get the karma loss for 'stealing/trespassing'? Looking like my initial idea of when it was under the target cursor won't fly.

 

Am I correct that setting a "new" owner is all that would be needed to override an existing owner or inherited cell ownership?

 

All the functions you mentioned for checking ownership require you to already have a NPC or Faction name. Presumably I need to build an array from 'GetRefs 200, 1' for Actors and 'GetRefs 8, 1' for Factions, and walk that array checking each? ('GetActorsByProcessingLevel 0' doesn't seem practical if I am trying to determine if an "owner" is "dead". Or are they still being processed? What if the "owner" never actually existed as an Actor?)

 

-Dubious-

Edited by dubiousintent
Link to comment
Share on other sites

This might be easier to go at it from the opposite direction. Whenever an NPC dies, put an OnDeath in their script and have it set the cell ownership and ownership of any items to the player. That way the ownership is already taken care of when the NPC dies and you don't need to do any fiddling at all afterwards.

Link to comment
Share on other sites

Certainly a viable approach (wish the devs had done that), except it seems to require tracking down every NPC in the game first and modifying their script.

 

It seemed to me that the only time the question of "ownership" comes into play is when the Player is looking to grab something, and a more generic "whose is this" approach would be more efficient (at least in terms of my time and effort).

 

Perhaps a combination approach: Build an array of NPCs in the current cell, then use an EventHandler triggered by the OnDeath event to check which one died and then process the ownership at that time? (I like that idea better.)

 

The potential issues with this I foresee are:

 

* If the "owner" is already "dead" when the cell is entered and thus won't trigger the EventHandler, assuming such is possible. In which case: still need to be able to get the ref of the object under the cursor. Or is there still some "processing level" required for the "dead"?

 

* Does a "Faction" die (trigger the OnDeath event) when the last member is deceased? If not, then each death has to be processed against the Faction membership list to determine if it is now empty.

 

-Dubious-

Edited by dubiousintent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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