Jump to content

[LE] Script help: Secondary Turret Spell


Recommended Posts

I know this script look dumb, but I have little knowledge about the position. I want to simplify the script, but don't know where to start it.

I want to trigger few spells around caster and then make spell separate out like a circle, but I realize if I keep writing the script like this, this may cause my game crash.....

 

Float Property CastHeight = 512.0 Auto
Float Property CastXaxisLength Auto
Float Property CastYaxisLength Auto
Float property fBaseTime = 0.5 Auto
activator property PlacedActivator auto
activator property PlacedActivator2 auto
activator property PlacedActivator3 auto
activator property PlacedTargetActivator auto
activator property PlacedTargetActivator2 auto
activator property PlacedTargetActivator3 auto
activator property PlacedTargetActivator4 auto
activator property PlacedTargetActivator5 auto
activator property PlacedTargetActivator6 auto
activator property PlacedTargetActivator7 auto
activator property PlacedTargetActivator8 auto
activator property PlacedTargetActivator9 auto
Spell property SpellRef auto
Bool property DeletAtEnd = True auto
Bool KeepUpdating = True
;======================================================================================;
; VARIABLES /
;=============/
objectReference ActivatorRef
objectReference ActivatorTargetRef
objectReference ActivatorTargetRef2
objectReference ActivatorTargetRef3
objectReference ActivatorTargetRef4
objectReference ActivatorTargetRef5
objectReference ActivatorTargetRef6
objectReference ActivatorTargetRef7
objectReference ActivatorTargetRef8
objectReference ActivatorTargetRef9
objectReference Trg
Actor CasterActor
Actor TargetActor
Float PosX
Float PosY
Float PosZ
Float TPosX
Float TPosY
Float TPosZ
Float Pos1X
Float Pos1Y
Float Pos1Z
Float TPos2X
Float TPos2Y
Float TPos2Z
Float TPos3X
Float TPos3Y
Float TPos3Z
Float TPos4X
Float TPos4Y
Float TPos4Z
Float TPos5X
Float TPos5Y
Float TPos5Z
Float TPos6X
Float TPos6Y
Float TPos6Z
Float TPos7X
Float TPos7Y
Float TPos7Z
Float TPos8X
Float TPos8Y
Float TPos8Z
Float TPos9X
Float TPos9Y
Float TPos9Z
;======================================================================================;
; EVENTS /
;=============/
Event OnEffectStart(Actor Target, Actor Caster)
CasterActor = Caster
TargetActor = Target
ActivatorRef = TargetActor.placeAtMe(PlacedActivator)
PosX = TargetActor.GetPositionX()+ CastXaxisLength
PosY = TargetActor.GetPositionY()+ CastYaxisLength
PosZ = TargetActor.GetPositionZ()+ CastHeight
ActivatorRef.SetPosition(PosX,PosY,PosZ)
ActivatorRef.SetAngle(0,0,0)
ActivatorTargetRef = TargetActor.placeAtMe(PlacedTargetActivator)
ActivatorTargetRef2 = TargetActor.placeAtMe(PlacedTargetActivator2)
ActivatorTargetRef3 = TargetActor.placeAtMe(PlacedTargetActivator3)
ActivatorTargetRef4 = TargetActor.placeAtMe(PlacedTargetActivator4)
ActivatorTargetRef5 = TargetActor.placeAtMe(PlacedTargetActivator5)
ActivatorTargetRef6 = TargetActor.placeAtMe(PlacedTargetActivator6)
ActivatorTargetRef7 = TargetActor.placeAtMe(PlacedTargetActivator7)
ActivatorTargetRef8 = TargetActor.placeAtMe(PlacedTargetActivator8)
ActivatorTargetRef9 = TargetActor.placeAtMe(PlacedTargetActivator9)
Trg = ActivatorRef
TPosX = Trg.GetPositionX()
TPosY = Trg.GetPositionY()+ 450.0
TPosZ = Trg.GetPositionZ()
TPos2X = Trg.GetPositionX()+ 240.0
TPos2Y = Trg.GetPositionY()+ 240.0
TPos2Z = Trg.GetPositionZ()
TPos3X = Trg.GetPositionX()+ 450.0
TPos3Y = Trg.GetPositionY()
TPos3Z = Trg.GetPositionZ()
TPos4X = Trg.GetPositionX()+ 240.0
TPos4Y = Trg.GetPositionY()- 240.0
TPos4Z = Trg.GetPositionZ()
TPos5X = Trg.GetPositionX()
TPos5Y = Trg.GetPositionY()- 450.0
TPos5Z = Trg.GetPositionZ()
TPos6X = Trg.GetPositionX()- 240.0
TPos6Y = Trg.GetPositionY()- 240.0
TPos6Z = Trg.GetPositionZ()
TPos7X = Trg.GetPositionX()- 450.0
TPos7Y = Trg.GetPositionY()
TPos7Z = Trg.GetPositionZ()
TPos8X = Trg.GetPositionX()- 240.0
TPos8Y = Trg.GetPositionY()- 240.0
TPos8Z = Trg.GetPositionZ()
ActivatorTargetRef.SetPosition(TPosX,TPosY,TPosZ)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef)
ActivatorTargetRef2.SetPosition(TPos2X,TPos2Y,TPos2Z)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef2)
ActivatorTargetRef3.SetPosition(TPos3X,TPos3Y,TPos3Z)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef3)
ActivatorTargetRef4.SetPosition(TPos4X,TPos4Y,TPos4Z)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef4)
ActivatorTargetRef5.SetPosition(TPos5X,TPos5Y,TPos5Z)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef5)
ActivatorTargetRef6.SetPosition(TPos6X,TPos6Y,TPos6Z)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef6)
ActivatorTargetRef7.SetPosition(TPos7X,TPos7Y,TPos7Z)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef7)
ActivatorTargetRef8.SetPosition(TPos8X,TPos8Y,TPos8Z)
SpellRef.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef8)
RegisterForSingleUpdate (0.5)
EndEvent
Event OnEffectFinish(Actor Target, Actor Caster)
KeepUpdating = false
if DeletAtEnd
if (ActivatorRef != none)
ActivatorRef.disable()
ActivatorRef.delete()
endif
if (ActivatorTargetRef != none)
ActivatorTargetRef.disable()
ActivatorTargetRef.delete()
endif
if (ActivatorTargetRef2 != none)
ActivatorTargetRef2.disable()
ActivatorTargetRef2.delete()
endif
if (ActivatorTargetRef3 != none)
ActivatorTargetRef3.disable()
ActivatorTargetRef3.delete()
endif
if (ActivatorTargetRef4 != none)
ActivatorTargetRef4.disable()
ActivatorTargetRef4.delete()
endif
if (ActivatorTargetRef5 != none)
ActivatorTargetRef5.disable()
ActivatorTargetRef5.delete()
endif
if (ActivatorTargetRef6 != none)
ActivatorTargetRef6.disable()
ActivatorTargetRef6.delete()
endif
if (ActivatorTargetRef7 != none)
ActivatorTargetRef7.disable()
ActivatorTargetRef7.delete()
endif
if (ActivatorTargetRef8 != none)
ActivatorTargetRef8.disable()
ActivatorTargetRef8.delete()
endif
if (ActivatorTargetRef9 != none)
ActivatorTargetRef9.disable()
ActivatorTargetRef9.delete()
endif
endif
EndEvent
Link to comment
Share on other sites

  • 2 weeks later...

I made some change with my code, but it was still rough. I just post here and anyone is welcome to leave a comment or advice. Also, some of codes I took advices from Dylbill and Maxarturo were from my first post.

 

Here is the code, the turret will cast 8 spells to 8 different directions, and then the turret will automatically fire when enemy are in the range.

import weather
import utility
import game
;======================================================================================;
;  PROPERTIES  /
;=============/
Float Property CastHeight = 256.0 auto
Float Property fBaseRandom = 512.0 auto
Float Property fBaseTime = 1.0 auto
Float Property SpellRadius = 2000.0 auto

activator property PlacedActivator auto
activator property PlacedActivator2 auto
activator property PlacedTargetActivator auto
activator property PlacedTargetActivator2 auto
activator property PlacedTargetActivator3 auto
activator property PlacedTargetActivator4 auto
activator property PlacedTargetActivator5 auto
activator property PlacedTargetActivator6 auto
activator property PlacedTargetActivator7 auto
activator property PlacedTargetActivator8 auto
activator property PlacedTargetActivator9 auto

Float Property CastXaxisLength Auto
Float Property CastYaxisLength Auto


Spell property SpellRef auto
Spell property SpellRef2 auto

;======================================================================================;
;  VARIABLES   /
;=============/


objectReference ActivatorRef3
objectReference ActivatorRef
objectReference ActivatorTargetRef     
objectReference ActivatorTargetRef2
objectReference ActivatorTargetRef3
objectReference ActivatorTargetRef4
objectReference ActivatorTargetRef5
objectReference ActivatorTargetRef6
objectReference ActivatorTargetRef7
objectReference ActivatorTargetRef8
objectReference ActivatorTargetRef9
objectReference Trg


Actor CasterActor
Actor TargetActor
Float PosX 
Float PosY  
Float PosZ
Float CPosX 
Float CPosY  
Float CPosZ
Float TPosX 
Float TPosY  
Float TPosZ

Actor player
Actor Enemy

;======================================================================================;
;   EVENTS     /
;=============/

Event OnEffectStart(Actor Target, Actor Caster)
		CasterActor = Caster
		TargetActor = Target

		ActivatorRef3 = TargetActor.placeAtMe(PlacedActivator)
		PosX = TargetActor.GetPositionX()
		PosY = TargetActor.GetPositionY()
		PosZ = TargetActor.GetPositionZ()
		PosZ = (PosZ + CastHeight)
		ActivatorRef3.SetPosition(PosX,PosY,PosZ)
		ActivatorRef3.SetAngle(0,0,0)
		
		ActivatorRef = TargetActor.placeAtMe(PlacedActivator2)
		CPosX = TargetActor.GetPositionX()+ CastXaxisLength
		CPosY = TargetActor.GetPositionY()+ CastYaxisLength
		CPosZ = TargetActor.GetPositionZ()+ 150
		ActivatorRef.SetPosition(CPosX,CPosY,CPosZ)
		ActivatorRef.SetAngle(0,0,0)
		
		ActivatorTargetRef = TargetActor.placeAtMe(PlacedTargetActivator)
		ActivatorTargetRef2 = TargetActor.placeAtMe(PlacedTargetActivator2)
		ActivatorTargetRef3 = TargetActor.placeAtMe(PlacedTargetActivator3)
		ActivatorTargetRef4 = TargetActor.placeAtMe(PlacedTargetActivator4)
		ActivatorTargetRef5 = TargetActor.placeAtMe(PlacedTargetActivator5)
		ActivatorTargetRef6 = TargetActor.placeAtMe(PlacedTargetActivator6)
		ActivatorTargetRef7 = TargetActor.placeAtMe(PlacedTargetActivator7)
		ActivatorTargetRef8 = TargetActor.placeAtMe(PlacedTargetActivator8)
		ActivatorTargetRef9 = TargetActor.placeAtMe(PlacedTargetActivator9)
		
		Trg = ActivatorRef
			TPosX = Trg.GetPositionX() 
			TPosY = Trg.GetPositionY()
			TPosZ = Trg.GetPositionZ()
			
			utility.Wait(1.0)
			
			ActivatorTargetRef.SetPosition(TPosX,TPosY+ 450.0 ,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef)
			
			ActivatorTargetRef2.SetPosition(TPosX+ 240.0,TPosY+ 240.0,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef2)
			
			ActivatorTargetRef3.SetPosition(TPosX+ 450.0,TPosY,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef3)
			
			ActivatorTargetRef4.SetPosition(TPosX+ 240.0 ,TPosY- 240.0,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef4)
			
			ActivatorTargetRef5.SetPosition(TPosX,TPosY- 450.0,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef5)
			
			ActivatorTargetRef6.SetPosition(TPosX- 240.0  ,TPosY- 240.0  ,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef6)
			
			ActivatorTargetRef7.SetPosition(TPosX- 450.0 ,TPosY,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef7)
			
			ActivatorTargetRef8.SetPosition(TPosX- 240.0 ,TPosY+ 240.0 ,TPosZ- 20)
			SpellRef2.RemoteCast(ActivatorRef,TargetActor,ActivatorTargetRef8)

		

		RegisterForSingleUpdate(1.0)
EndEvent


Event OnUpdate()
	Enemy = FindRandomActorFromRef(ActivatorRef3,SpellRadius)
	If ActivatorRef3.isdisabled() == 1
	
	elseIf Enemy == none
		RegisterForSingleUpdate(0.10)
	elseIf Enemy == CasterActor || Enemy.Ishostiletoactor(CasterActor)== 0 || Enemy.Isdead()
		RegisterForSingleUpdate(0.10)
	else
		SpellRef.remotecast(ActivatorRef3, CasterActor, Enemy)
		RegisterForSingleUpdate(fBaseTime)
	endif
endEvent


Event OnEffectFinish(Actor Target, Actor Caster)
	if ActivatorRef3 != none
		ActivatorRef3.disable()
		ActivatorRef3.delete()
		
		ActivatorRef != none
		ActivatorRef.disable()
		ActivatorRef.delete()

		ActivatorTargetRef != none
		ActivatorTargetRef.disable()
		ActivatorTargetRef.delete()
		
		ActivatorTargetRef2 != none
		ActivatorTargetRef2.disable()
		ActivatorTargetRef2.delete()
			
		ActivatorTargetRef3 != none
		ActivatorTargetRef3.disable()
		ActivatorTargetRef3.delete()
			
		ActivatorTargetRef4 != none
		ActivatorTargetRef4.disable()
		ActivatorTargetRef4.delete()
		
		ActivatorTargetRef5 != none
		ActivatorTargetRef5.disable()
		ActivatorTargetRef5.delete()
		
		ActivatorTargetRef6 != none
		ActivatorTargetRef6.disable()
		ActivatorTargetRef6.delete()
			
		ActivatorTargetRef7 != none
		ActivatorTargetRef7.disable()
		ActivatorTargetRef7.delete()
			
		ActivatorTargetRef8 != none
		ActivatorTargetRef8.disable()
		ActivatorTargetRef8.delete()
		
		ActivatorTargetRef9 != none
		ActivatorTargetRef9.disable()
		ActivatorTargetRef9.delete()
	endif
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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