Jump to content

Elementary Scripting Question


kingtitan

Recommended Posts

Hmm, that looks pretty straight forward to me. It simply exchanges the contents of the NPC's inventory with a temporary holding container, activates this one so you can exchange it contents, and then after you closed it exchanges them back into the NPC's inventory. Equipping the new stuff is done by the NPC itself, which sounds totally fine and legit. It should not be able to prevent OnEquip events from triggering.

 

There's some major trouble with the line "Begin OnEquip self", which could very well be the explanation for it "sometimes" working sometimes not.

"Begin OnEquip self" means execute this block whenever the item this is running on gets equipped by the actor reference "self". I told you already "self" cannot be expected to be initialized or even pointing to its current wearer, thus a line such as this is bound to fail many times. If the item got added and equipped in the same frame, so the GameMode block wasn't executed before the item was equipped, "self" will not hold the actual wearer, yet, and the event will never trigger!

I'd just use "Begin OnEquip" instead.

 

Now, where are we at? What's already working and what still isn't?

Link to comment
Share on other sites

Ahh, my apologies! I should have realized that it should be left ambiguous! Anyway here is the current code:

 

Scn ATPrisonerCollarScript

ref self
ref wearer

Begin GameMode

Set self To GetContainer

if ( wearer != 0 && wearer != self ) ; container changed and still has reference to previous wearer
       wearer.SetFactionRank ATPrisonerFaction, -1
       set wearer to 0 ; delete reference to previous wearer
endif

if ( self.IsActor == 0 ) ; item got dropped, previous wearer got removed from faction by previous check in this case, too
       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

Begin OnEquip

set self to GetContainer

if self.GetIsReference Player
Message "You are now a prisoner of Carcernus", 5
endif

End

 

However it is now "paired" with this scripted spell that I wrote up from scratch (great time to practice what I've learned so far eh?)

 

Scn ATcollarprisonerspell

short collarCount

Begin ScriptEffectStart

if IsActor == 1 && GetItemCount ATPrisonerCollar == 0
	additem ATPrisonerCollar 1
	equipitem2 ATPrisonerCollar
	message "This individual is now a prisoner of Carcernus", 5
elseif IsActor == 1 && GetItemCount ATPrisonerCollar >= 1
	set collarCount to GetItemCount ATPrisonerCollar
	unequipitem ATPrisonerCollar
	removeitem ATPrisonerCollar collarCount
	setfactionrank ATPrisonerFaction, -1
	message "This individual is no longer a prisoner of Carcernus", 5
endif

End

 

These two work together really well, and in my opinion are a much better way of instituting the collar anyway instead of using an outside mod spell. However, if there is a better suggestion, by all means I would love to hear it!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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