Scriptname nDragonVileSporesScript extends activemagiceffect  

import utility

Activator Property nactivatortarget Auto  
Activator Property nactivatorcaster Auto  
Activator Property nactivatorhole Auto  
SPELL Property xSpore Auto  
SPELL Property ThisSpell Auto 
float Property fRand Auto  
float Property fDelay Auto  

objectreference obj
objectreference obc
objectreference obt
actor me
actor he
float fX
float fY
float fZ
float fP

Event OnEffectStart(Actor akTarget, Actor akCaster)
	me = akCaster
	he = akTarget
	obj = he.placeatme(nactivatorhole)
	obt = he.placeatme(nactivatortarget)
	obj.SetAngle(0.0, 0.0, 0.0)
	fX = he.GetPositionX()
	fY = he.GetPositionY()
	fZ = he.GetPositionZ() + 50.0
	obc = he.placeatme(nactivatorcaster)
	obc.SetPosition(fX, fY, fZ)
	fX = he.GetPositionX()
	fY = he.GetPositionY()
	fZ = he.GetPositionZ() + 500.0
	RegisterForSingleUpdate(0.5)
Endevent

Event onUpdate()
If !(me.IsDead())
	obt.setposition(fX + RandomFloat(-fRand, fRand), fY + RandomFloat(-fRand, fRand), fZ)
	xSpore.remotecast(obc, me, obt)
	RegisterForSingleUpdate(0.5 + RandomFloat(-fDelay, fDelay))
Else
	he.dispelspell(ThisSpell)
Endif
Endevent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
obj.disable()
obj.delete()
obc.disable()
obc.delete()
obt.disable()
obt.delete()
Endevent