Jump to content

[LE] Script help: Turret Spell


Recommended Posts

I have to mention this before getting to the topic. I referred Beyond Reach ( https://www.nexusmods.com/skyrim/mods/48467 ) and VIGILANT ( https://www.nexusmods.com/skyrim/mods/67103 ) to make my new script, so the style and variable name were same as the author used in their script.
As my topic, the turret sometimes won't fire, or fire in wrong time (I set to fire for every 1 seconds while the magic effect is activated, but it sometimes takes 3 - 5 seconds). I assumed this was because the enemies were not in searching area, so I tried to increase the search radius and made enemies as close as possible to the turret. However, the turret sometimes cast spell on enemy, but sometimes not.....
I tried to use CasterActor.GetCombatTarget() instead using FindRandomActorFromRef. I tried to put CasterActor.GetCombatTarget() in Event OnEffectStart. This only worked for one enemy. If the magic effect have already started, the turret will not change target even if my front sight cross is pointing another enemy. In addition, if the enemy target is not being pointed by front sight cross before magic effect begin, then the turret will cast spell somewhere else rather than enemy target even if you later then point out the front sight cross to a enemy target. (I guess the direction of magic projectile depend on how I set the angle of the turret, but I have no clue of this even if I have read the Creation Kit wiki)
I also tried to put CasterActor.GetCombatTarget() in Event OnUpdate. And then I have to keep my front sight cross to be pointed to a one of enemy target. If there is no actor that is being pointed during the magic effect, the turret will cast spell somewhere else............
I think the FindRandomActorFromRef is better than CasterActor.GetCombatTarget() only the time issue can be fixed...... (Therefore, I do need help with this and I do really appreciate you take time to read this long post and your advices).
Below is the script:
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
Spell property SpellRef auto
;======================================================================================;
; VARIABLES /
;=============/
objectReference ActivatorRef3
bool KeepUpdating = true
Actor CasterActor
Actor TargetActor
Float PosX
Float PosY
Float PosZ
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()
ActivatorRef3.SetPosition(PosX,PosY,PosZ)
PosZ = (PosZ + CastHeight)
ActivatorRef3.SetPosition(PosX,PosY,PosZ)
ActivatorRef3.SetAngle(0,0,0)
RegisterForSingleUpdate(0.5)
EndEvent
Event OnUpdate()
Enemy = CasterActor.GetCombatTarget()
If Enemy == none
elseIf Enemy != CasterActor && Enemy.Ishostiletoactor(CasterActor) && Enemy.Isdead() != 1 && ActivatorRef3.isdisabled() != 1
SpellRef.remotecast(ActivatorRef3, CasterActor, Enemy)
endif
RegisterForSingleUpdate(fBaseTime)
endEvent
Event OnEffectFinish(Actor Target, Actor Caster)
if ActivatorRef3 != none
ActivatorRef3.disable()
ActivatorRef3.delete()
endif
EndEvent

 

Link to comment
Share on other sites

Hey, I think that using FindRandomActorFromRef would be best. I looked at your script and made some modifications, try it out and see if it works:

 

 

 

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

Spell property SpellRef auto

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

objectReference ActivatorRef3


bool KeepUpdating = true
Actor CasterActor
Actor TargetActor
Float PosX 
Float PosY  
Float PosZ 
Float TPosX 
Float TPosY  
Float TPosZ 

Actor player
Actor Enemy

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

Event OnEffectStart(Actor akTarget, Actor akCaster)
    CasterActor = akCaster
    TargetActor = akTarget
     
    ActivatorRef3 = TargetActor.placeAtMe(PlacedActivator)
    PosX = TargetActor.GetPositionX()
    PosY = TargetActor.GetPositionY()
    PosZ = TargetActor.GetPositionZ()
    ActivatorRef3.SetPosition(PosX,PosY,PosZ)
     
    PosZ = (PosZ + CastHeight)
    ActivatorRef3.SetAngle(0,0,0)


    RegisterForSingleUpdate(0.5)
EndEvent

Event OnUpdate()
    Enemy = FindRandomActorFromRef(ActivatorRef3, SpellRadius)
    
    If ActivatorRef3.isdisabled() == 1
        ;stop the updates
    ElseIf Enemy == none
        RegisterForSingleUpdate(0.25) ;attempts to find another enemy
    Elseif Enemy == CasterActor || Enemy.Ishostiletoactor(CasterActor) == 0 || Enemy.Isdead()
        RegisterForSingleUpdate(0.25) ;attempts to find another enemy
    Else
        SpellRef.remotecast(ActivatorRef3, CasterActor, Enemy)
        RegisterForSingleUpdate(fBaseTime)
    endif
     
EndEvent
     
Event OnEffectFinish(Actor Target, Actor Caster)
    if ActivatorRef3 != none
        ActivatorRef3.disable()
        ActivatorRef3.delete()
    endif
EndEvent

Edited by dylbill
Link to comment
Share on other sites

I agree with dylbill.

Here is the part of my script that's fully working in-game and that interests you, it will fire at 3 different targets (twice) or in the sequence that the script will find actors, one actor can be hit more than one time on the 'Update' event.


* I'm not posting the whole script because i don't think it'll help you, since my turrets work in a completely different way than yours.


Event OnUpdate()
Actor AActor = Game.FindRandomActorFromRef(SpellCaster01, SeekRange)
Actor BActor = Game.FindRandomActorFromRef(SpellCaster01, SeekRange)
Actor CActor = Game.FindRandomActorFromRef(SpellCaster01, SeekRange)
SpellCount = SpellCount + 1
If AActor
If ( AActor.IsDead() == False )
If ( SpellCount == 1 )
SpellFIre.Cast(SpellCaster01, AActor)
SpellFIre.Cast(SpellCaster02, AActor)
ElseIf ( SpellCount == 2 )
SpellFrost.Cast(SpellCaster01, AActor)
SpellFrost.Cast(SpellCaster02, AActor)
ElseIf ( SpellCount == 3 )
SpellSun.Cast(SpellCaster01, AActor)
SpellSun.Cast(SpellCaster02, AActor)
ElseIf ( SpellCount >= 4 )
SpellShock.Cast(SpellCaster01, AActor)
SpellShock.Cast(SpellCaster02, AActor)
EndIf
EndIf
EndIf

If BActor
If ( BActor.IsDead() == False )
Utility.Wait(0.5)
If ( SpellCount == 1 )
SpellFIre.Cast(SpellCaster01, BActor)
SpellFIre.Cast(SpellCaster02, BActor)
ElseIf ( SpellCount == 2 )
SpellFrost.Cast(SpellCaster01, BActor)
SpellFrost.Cast(SpellCaster02, BActor)
ElseIf ( SpellCount == 3 )
SpellSun.Cast(SpellCaster01, BActor)
SpellSun.Cast(SpellCaster02, BActor)
ElseIf ( SpellCount >= 4 )
SpellShock.Cast(SpellCaster01, BActor)
SpellShock.Cast(SpellCaster02, BActor)
EndIf
EndIf
EndIf

If CActor
If ( CActor.IsDead() == False )
Utility.Wait(0.5)
If ( SpellCount == 1 )
SpellFIre.Cast(SpellCaster01, CActor)
SpellFIre.Cast(SpellCaster02, CActor)
ElseIf ( SpellCount == 2 )
SpellFrost.Cast(SpellCaster01, CActor)
SpellFrost.Cast(SpellCaster02, CActor)
ElseIf ( SpellCount == 3 )
SpellSun.Cast(SpellCaster01, CActor)
SpellSun.Cast(SpellCaster02, CActor)
ElseIf ( SpellCount >= 4 )
SpellShock.Cast(SpellCaster01, CActor)
SpellShock.Cast(SpellCaster02, CActor)
SpellCount = 0
EndIf
EndIf
EndIf
If ( CasterTriggered == True )
RegisterForSingleUpdate(3.0)
EndIf
EndEvent



I hope it helps you.

Edited by maxarturo
Link to comment
Share on other sites

  • Recently Browsing   0 members

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