Jump to content

[LE] Can I clear a reference alias from a magic effect?


Nathan55

Recommended Posts

I'm trying to place actors into quest aliases to change their packages using "refAlias.ForceRefTo(akTarget)" from a magic effect. I can get them into the alias just fine, and the package is working. But, when I call refAlias.Clear(), nothing seems to happen.{the script compiled with the extends magiceffect so I figured it would work}{also, I had to manually fill the alias properties in the properties window.} akTarget just continues using the alias package. I've checked to see if the alias really wasn't clearing with "refAlias.GetRef() == none" as a condition on other actors and they were unable to enter the already filled alias.{was worried that the package had stuck onto the actor for some reason instead of the alias not clearing.} So i know .clear() isn't clearing the alias from the same magic effect that I used to fill it.

 

I've also changed things up with where the ".clear()" script is located. If it's placed inside of the reference alias the alias will clear just fine. However, the way I'm using the alias, it would be much easier to just clear it with the same magic effect that filled it.

 

Edit: The quest alias was tagged as optional as well.

 

So, can I .clear() an alias from a magic effect? If not, can i clear them from the Quest Script? What is the standard for clearing multiple aliases in a quest one at a time?

Edited by Nathan55
Link to comment
Share on other sites

Scriptname EN_Actor_Interaction_Script extends activemagiceffect  
{Handles all interaction with NPCs}
 
Actor Property PlayerRef Auto
GlobalVariable Property EN_GLO_PlayerDetected Auto
Keyword Property ClothingBody Auto
Keyword Property ArmorCuirass Auto
Armor Property ClothesPrisonerRags Auto
ReferenceAlias Property thisNPC_01 Auto
 
ObjectReference refNPC
 
Event OnEffectStart(Actor akTarget, Actor akCaster)
    refNPC = thisNPC_01.GetRef()
if !akTarget.WornHasKeyword(ClothingBody) && !akTarget.WornHasKeyword(ArmorCuirass) && refNPC == none
thisNPC_01.ForceRefTo(akTarget)
        utility.wait(5)
        akTarget.AddItem(ClothesPrisonerRags)
        akTarget.EquipItem(ClothingPrisonerRags) ;This action is completed
        thisNPC_01.Clear()
elseif PlayerRef.IsDetectedBy(akTarget)
EN_GLO_PlayerDetected.SetValue(1)
endif
EndEvent
 
Event OnEffectFinish(Actor akTarget, Actor akCaster)
GoToState("DeadState")
EndEvent
State DeadState
EndState

That's the entire script. All properties are filled. I'm trying to get npcs to have a little self awareness when you steal their clothes and do something about it.

 

Edit: this post was edited due to errors in the script(this was a recreation of the one originally used that didn't have these errors.) I also should mention that this is applied via a cloak.

Edited by Nathan55
Link to comment
Share on other sites

Scriptname EN_Actor_Interaction_Script extends activemagiceffect  
{Handles all interaction with NPCs}
 
Actor Property PlayerRef Auto
GlobalVariable Property EN_GLO_PlayerDetected Auto
Keyword Property ClothingBody Auto
Keyword Property ArmorCuirass Auto
Armor Property ClothesPrisonerRags Auto
ReferenceAlias Property thisNPC_01 Auto
 
ObjectReference refNPC
 
Event OnEffectStart(Actor akTarget, Actor akCaster)
    refNPC = thisNPC_01.GetRef()
if !akTarget.WornHasKeyword(ClothingBody) && !akTarget.WornHasKeyword(ArmorCuirass) && refNPC == none
thisNPC_01.ForceRefTo(akTarget)
        utility.wait(5)
        akTarget.AddItem(ClothesPrisonerRags)
        akTarget.EquipItem(ClothingPrisonerRags) ;This action is completed
        thisNPC_01.Clear()
elseif PlayerRef.IsDetectedBy(akTarget)
EN_GLO_PlayerDetected.SetValue(1)
endif
EndEvent
 
Event OnEffectFinish(Actor akTarget, Actor akCaster)
GoToState("DeadState")
EndEvent
State DeadState
EndState

That's the entire script. All properties are filled. I'm trying to get npcs to have a little self awareness when you steal their clothes and do something about it.

 

Edit: this post was edited due to errors in the script(this was a recreation of the one originally used that didn't have these errors.) I also should mention that this is applied via a cloak.

 

 

Hm. The call looks correct syntax-wise. I'm wondering if the alias might've been re-filled by another instance of the magic effect, since cloak spells can spam them. Could you post the conditions of the spell?

Link to comment
Share on other sites

The "refNPC == None" should have prevented a double fill of the alias.(at least I think it should.) the conditions are:

 

GetDead None == 0

HasMagicEffect "this magic effect" == 0

GetIsPlayableRace None == 1

 

Edit: the conditions are all set to "and" as well.

Edit: Would a call for .Clear() not clear all fills anyway?

Edited by Nathan55
Link to comment
Share on other sites

The "refNPC == None" should have prevented a double fill of the alias.(at least I think it should.) the conditions are:

 

GetDead None == 0

HasMagicEffect "this magic effect" == 0

GetIsPlayableRace None == 1

 

Edit: the conditions are all set to "and" as well.

Edit: Would a call for .Clear() not clear all fills anyway?

 

A Clear() will remove whatever's in the alias, but with a cloak spell it's possible for the magic effect to then be re-applied, with a fresh set of variables and properties. The equipping of the rags should prevent the forceref from firing again, but something's up. Going to a ForceRefIfEmpty and checking whether it was successful sounds like a good idea. Because packages can have latency the NPC flickering in and out of the alias might not be noticeable.

 

Ordinarily I'd ask if the alias was set to optional, but a. you say you've got working clears elsewhere and b. explicitly say that it is.

 

(Also that five second wait makes my teeth grit. I think you'd be better off with a RegisterForSingleUpdate call.)

Edited by foamyesque
Link to comment
Share on other sites

Scriptname EN_Actor_Interaction_Script extends activemagiceffect  
{Handles all interaction with NPCs.}

Actor Property PlayerRef Auto
GlobalVariable Property EN_GLO_PlayerDetected Auto
Keyword Property ClothingBody Auto
Keyword Property ArmorCuirass Auto
Armor Property ClothesPrisonerRags Auto
ReferenceAlias Property NakedNPC_01 Auto
ReferenceAlias Property NakedNPC_02 Auto
ReferenceAlias Property NakedNPC_03 Auto
ReferenceAlias Property NakedNPC_04 Auto
ReferenceAlias Property NakedNPC_05 Auto
ReferenceAlias Property NakedNPC_06 Auto
ReferenceAlias Property NakedNPC_07 Auto
ReferenceAlias Property NakedNPC_08 Auto
ReferenceAlias Property NakedNPC_09 Auto
ReferenceAlias Property NakedNPC_10 Auto

Actor thisActor
int waitTime = 10

Event OnEffectStart(Actor akTarget, Actor akCaster)
	if !akTarget.WornHasKeyword(ClothingBody) && !akTarget.WornHasKeyword(ArmorCuirass)
		thisActor = akTarget
		if NakedNPC_01.GetRef() == none
			NakedNPC_01.ForceRefIfEmpty(thisActor)
			utility.wait(waitTime)
			while thisActor.GetItemCount(ClothesPrisonerRags) < 1
				thisActor.AddItem(ClothesPrisonerRags)
				utility.wait(0.5)
			endwhile
			while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
				thisActor.EquipItem(ClothesPrisonerRags)
				utility.wait(0.5)
			endwhile
			NakedNPC_01.Clear()
		endif
		;checkRef()
	elseif PlayerRef.IsDetectedBy(akTarget)
		EN_GLO_PlayerDetected.SetValue(1)
	endif
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	GoToState("DeadState")
EndEvent
State DeadState
EndState

Function checkRef()
	if NakedNPC_01.GetRef() == none
		NakedNPC_01.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		thisActor.AddItem(ClothesPrisonerRags)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_01.Clear()
		return
	elseif NakedNPC_02.GetRef() == none
		NakedNPC_02.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_02.Clear()
		return
	elseif NakedNPC_03.GetRef() == none
		NakedNPC_03.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_03.Clear()
		return
	elseif NakedNPC_04.GetRef() == none
		NakedNPC_04.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_04.Clear()
		return
	elseif NakedNPC_05.GetRef() == none
		NakedNPC_05.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_05.Clear()
		return
	elseif NakedNPC_06.GetRef() == none
		NakedNPC_06.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_06.Clear()
		return
	elseif NakedNPC_07.GetRef() == none
		NakedNPC_07.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_07.Clear()
		return
	elseif NakedNPC_08.GetRef() == none
		NakedNPC_08.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_08.Clear()
		return
	elseif NakedNPC_09.GetRef() == none
		NakedNPC_09.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_09.Clear()
		return
	elseif NakedNPC_10.GetRef() == none
		NakedNPC_10.ForceRefIfEmpty(thisActor)
		utility.wait(waitTime)
		while !thisActor.WornHasKeyword(ClothingBody) && !thisActor.WornHasKeyword(ArmorCuirass)
			thisActor.EquipItem(ClothesPrisonerRags)
			utility.wait(0.5)
		endwhile
		NakedNPC_10.Clear()
		return
	endif
EndFunction

Good citizen, foamyesque! I do believe you were barking up the right tree! This is the new script. I have placed the gathering of the clothes and the equipping of said clothes in while loops so it absolutely does equip clothing BEFORE the clear event. Seems that sometimes the clothing was not being equipped before the .clear() adding the NPC back to the alias, then stuff was happening that didn't release the actor from the alias even though they had clothing equipped.(I figured this out when I found multiples of the clothing in the NPC's inventory.)

 

Also, I realize that .wait() is really not the best option and fully intend to remove it for a singleupdate once I wrap my head around how to do this with more than one alias.(I have RegisterForSingleUpdateGameTime()s in the other scripts that i've been working on.)(also, i understand that the checkRef() function is totally broken in the new script. It's still a work in progress.)

 

I thank you for the first time, and then again.

 

(P.S. Don't do that, you need those teeth. :laugh:)

Edited by Nathan55
Link to comment
Share on other sites

  • Recently Browsing   0 members

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