Jump to content

"Factionalize" Clothing for NPCs


kingtitan

Recommended Posts

GetSelf would make the script refer to the item itself,

 

*groan* I just hate it when that happens. That's what's great about these forums, though: somebody will always come along and put things straight. :thumbsup:

Link to comment
Share on other sites

That's what I was wondering about actually!! But I ran into another strange issue. But before I go any further here is the code at present:

 

 


Scn ATPrisonerCollarScript

ref self

Begin OnEquip
Set self To GetContainer
self.SetFactionRank ATPrisonerFaction, 0
End

Begin OnUnequip
Set self To GetContainer
self.SetFactionRank ATPrisonerFaction, -1
End

 

 

Strangely enough the script works on the player character but not on NPC's... I'm really not sure why though if 'GetContainer' sets the ref as the NPC itself

Link to comment
Share on other sites

Are you using a script to equip the item on the NPC? If so, the onequip block won't run - see the last note on this page. To get around this, you can use the OBSE function EquipItem2. Or you could run a Gamemode script to continuously check if the item is equipped by the "container".

 

As for why GetContainer works, actors are considered to be containers like chests or sacks. If an item is in the actor's inventory, then the actor is considered to be the container.

Link to comment
Share on other sites

Actually, I was using the 'Active Inventory' spell found here to give the NPC the collar which the NPC would equip directly after I closed the "container" menu. If using a script is better, let me know because at this point i'm open to just about anything that will work.

 

As for the 'GetContainer' bit, I meant that I don't understand why it works for the player but not NPC's, apologies if my wording was ambiguous!

Edited by kingtitan
Link to comment
Share on other sites

Actually, I was using the 'Active Inventory' spell found here to give the NPC the collar which the NPC would equip directly after I closed the "container" menu. If using a script is better, let me know because at this point i'm open to just about anything that will work.

 

As for the 'GetContainer' bit, I meant that I don't understand why it works for the player but not NPC's, apologies if my wording was ambiguous!

 

Yep, that spell is a scripted effect, so the OnEquip block won't run. That's why the script works when you equip the item on yourself manually, but doesn't when it is equipped on an NPC via script.

 

Provided you don't have dozens of people wearing these collars, I think most reliable would be to use a gamemode script. Something like this would check whether the collar is equipped and adjust the faction rank every frame:

 

Scn ATPrisonerCollarScript

ref self

Begin GameMode

Set self To GetContainer

if ( self.IsActor == 0 )
Return
endif

if ( self.GetEquipped ATPrisonerCollar )
self.SetFactionRank ATPrisonerFaction, 0
else
       self.SetFactionRank ATPrisonerFaction, -1
endif

End

Link to comment
Share on other sites

Sorry that it has taken me so long to reply, this week of university has kept me rather busy. Anyway to the issue at hand - I actually wondered if that was an effective method of getting the 'OnEquip' to actually activate on an NPC. Lanceor, your gamemode suggestion made quite a bit of sense, I'm really not sure why I didn't think about that myself; then again I am just learning Oblivion scripting! Anyway, I went ahead and used the new script you provided me with to test its mechanics out. The script worked fine to get both the NPC and player character into the faction. However, upon removing the collar the NPC did not get removed from the faction while the player character did. This is becoming very complex, but you guys have helped me make quite a bit of headway! If you guys could help me out just a little more, I'm sure we can get it figured out entirely!

 

Edit: I forgot to include that 99% of my script testing prior to this has been reliant on the "Active Inventory" mod spell. I am approaching the subject from a bit different standpoint now in hopes that I can fix it to work alongside of this spell, as it is the most convenient means of giving/taking away items from an NPC.

 

Edit 2: I would also like to add (in case i have not been very clear) that for the purposes of this script I only need it to work on NPC's and not necessarily the player character. If it functions fine for the player character that is fine but my primary concern is enabling function for NPC's.

Edited by kingtitan
Link to comment
Share on other sites

Going by the last script posted it won't even work for the player, if you don't "unequip" but "drop" the item.

 

As you cannot interact with NPCs' inventories by default, the mod you're using drops all their belongings into a temporary holding container you can interact with and when you close this container again it will drop all its contents back into the NPC's inventory.

 

When an item is "dropped" though GetContainer will return 0, as it now has none anymore. The reference to its previous wearer is lost and as such the wearer can't be removed from the faction.

 

How about you define an additional "ref wearer" and modify your code the following way:

Scn ATPrisonerCollarScript

ref self
ref wearer

Begin GameMode

Set self To GetContainer

if ( self.IsActor == 0 ) ; item got dropped
       if ( wearer != 0 ) ; still has reference to previous wearer
               wearer.SetFactionRank ATPrisonerFaction, -1
               set wearer to 0 ; delete reference to previous wearer
       endif
       Return
endif
set wearer to self ; store reference to current wearer 

if ( self.GetEquipped ATPrisonerCollar )
       self.SetFactionRank ATPrisonerFaction, 0
else
       self.SetFactionRank ATPrisonerFaction, -1
endif

End

 

This sure can be further improved on, but it should do what you want for now. Even if dropped, the item is still able to remove its previous wearer from the faction.

Link to comment
Share on other sites

First off, I posted directly before this, please read that post as it will probably better clarify this one. Anyway, I got around to plugging away with some ideas and came up with something (not necessarily pretty or efficient), however this method nonetheless works. I gave a script (found directly below as a spoiler) to the specific NPC to evaluate if they had the collar in their inventory. If not, they were removed from the faction. Here is the code:

 

 


Scn ATPrisonerCollarFactionRemoval

ref self

Begin GameMode

Set self to GetSelf

if (self.GetItemCount ATPrisonerCollar == 0)
self.SetFactionRank ATPrisonerFaction, -1
elseif (self.GetItemCount ATPrisonerCollar >= 1)
return
endif

End

 

 

If anyone has a 'cleaner' suggestion to implement this, please give me your ideas!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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