Scriptname NirnrootACTIVATORScript extends ObjectReference Hidden 
{Script to only be applied to the NirnrootACTIVATOR base object.}

Ingredient Property Nirnroot Auto
Message Property HarvestNirnrootMESSAGE Auto
Activator Property NirnrootGlowACTIVATOR Auto
Activator Property NirnrootEmptyACTIVATOR Auto

ObjectReference Property NirnrootGlowReference Auto Hidden
ObjectReference Property NirnrootEmptyReference Auto Hidden
ObjectReference Property EmptyRef Auto Hidden
Bool Property HasBeenLoaded Auto Hidden



EVENT OnLoad()
; 	;debug.Trace("DARYL - " + self + " has been loaded")
	if (HasBeenLoaded == FALSE)
; 		;debug.Trace("DARYL - " + self + " wasn't previously loaded so we are placing the glow: " + NirnRootGlowACTIVATOR)
		NirnrootGlowReference = PlaceAtMe(NirnRootGlowACTIVATOR)
		NirnrootEmptyReference = PlaceAtMe(NirnRootEmptyACTIVATOR)
		NirnrootEmptyReference.Disable()
; 		;debug.Trace("DARYL - " + self + " setting HasBeenLoaded to TRUE")
		HasBeenLoaded = TRUE
	else
; 		;debug.Trace("DARYL - " + self + " has already been loaded so we assume the " + NirnRootGlowACTIVATOR + " has been placed as " + NirnRootGlowReference)
	endif

endEVENT



EVENT OnReset()

; 	;debug.Trace("DARYL - " + self + " has been Reset!")
	if (self.IsDisabled() == TRUE)
; 		;debug.Trace("DARYL - " + self + " has been picked since it's disabled, so renabling it")
		self.Enable()
	endif
	
endEVENT



Auto STATE WaitingForHarvest

	EVENT onActivate(ObjectReference TriggerRef)
		GoToState("AlreadyHarvested")
; 		;debug.Trace("DARYL - " + self + " has been activated so Adding 1 " + Nirnroot + " to " + TriggerRef + "'s inventory")
		(TriggerRef as Actor).additem(Nirnroot, 1)
		Game.IncrementStat( "Nirnroots Found" )
; 		;;debug.Trace("DARYL - " + self + " popping simulated harvest message: " + HarvestNirnrootMESSAGE)
		;HarvestNirnrootMESSAGE.Show()
; 		;debug.Trace("DARYL - " + self + " disabling the " + NirnrootGlowReference + " glow reference and marking for delete")
		NirnRootGlowReference.Disable()
		NirnRootGlowReference.Delete()
		NirnRootGlowReference = EmptyRef
; 		;debug.Trace("DARYL - " + self + " disabling myself")
		self.Disable()
; 		;debug.Trace("DARYL - " + self + " going to 'AlreadyHarvested' STATE")
		NirnrootEmptyReference.Enable()
	endEVENT

endSTATE



STATE AlreadyHarvested
	
	EVENT OnBeginState()
; 		;debug.Trace("DARYL - " + self + " now in 'AlreadyHarvested' STATE")
		;Do nothing, I've already been harvested.
	endEVENT

endSTATE
