Jump to content

[LE] Help needed with activator script


TyburnKetch

Recommended Posts

I know it's not pretty. I am very new to scripting:

 

Scriptname THPortalActivator extends ObjectReference

Actor Property PlayerRef auto
Spell Property THPortalGateSpell auto
ObjectReference Property TargetLocation0 auto
ObjectReference Property TargetLocation1 auto
ObjectReference Property TargetLocation2 auto
ObjectReference Property TargetLocation3 auto
ObjectReference Property TargetLocation4 auto
ObjectReference Property TargetLocation5 auto
ObjectReference Property TargetLocation6 auto
ObjectReference Property TargetLocation7 auto


Bool bToggle

Event OnActivate(ObjectReference akActionRef)
bToggle = !bToggle
If bToggle
If (akActionRef as Actor) == PlayerRef
THPortalGateSpell.Cast(TargetLocation0)
THPortalGateSpell.Cast(TargetLocation1)
THPortalGateSpell.Cast(TargetLocation2)
THPortalGateSpell.Cast(TargetLocation3)
THPortalGateSpell.Cast(TargetLocation4)
THPortalGateSpell.Cast(TargetLocation5)
THPortalGateSpell.Cast(TargetLocation6)
THPortalGateSpell.Cast(TargetLocation7)
ElseIf !bToggle
disable(THPortalGateSpell)
Endif
EndIf
EndEvent

 

I'm trying to toggle off the Spell(s)on activation. The activator is off by default. On activate the spell(s) fire. I am trying to work out how when activated again the spell stops firing.

 

Can it be done in one script and on one activator?

 

*UPDATE*

 

I've got the toggle to work by firing a dummy magiceffect / spell that has no visuals - however when i try to reactivate the activator i CTD.

 

Any help to make this not happen? Many thanks.

Scriptname THPortalActivator extends ObjectReference 

Spell Property THPortalGateSpell auto
Spell Property THPortalGateSpell2 auto
ObjectReference Property TargetLocation0 auto
ObjectReference Property TargetLocation1 auto
ObjectReference Property TargetLocation2 auto
ObjectReference Property TargetLocation3 auto
ObjectReference Property TargetLocation4 auto
ObjectReference Property TargetLocation5 auto
ObjectReference Property TargetLocation6 auto
ObjectReference Property TargetLocation7 auto

 Bool bToggle

Event OnActivate(ObjectReference akActionRef)
	bToggle = !bToggle
	If bToggle 
THPortalGateSpell.Cast(TargetLocation0)
THPortalGateSpell.Cast(TargetLocation1)
THPortalGateSpell.Cast(TargetLocation2)
THPortalGateSpell.Cast(TargetLocation3)
THPortalGateSpell.Cast(TargetLocation4)
THPortalGateSpell.Cast(TargetLocation5)
THPortalGateSpell.Cast(TargetLocation6)
THPortalGateSpell.Cast(TargetLocation7)
	ElseIf  !bToggle
THPortalGateSpell2.Cast(TargetLocation0)
THPortalGateSpell2.Cast(TargetLocation1)
THPortalGateSpell2.Cast(TargetLocation2)
THPortalGateSpell2.Cast(TargetLocation3)
THPortalGateSpell2.Cast(TargetLocation4)
THPortalGateSpell2.Cast(TargetLocation5)
THPortalGateSpell2.Cast(TargetLocation6)
THPortalGateSpell2.Cast(TargetLocation7)

EndIf
EndEvent
 
Edited by TyburnKetch
Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

Update:

 

I moved the 2nd spell to another activator (a seperate script) and set it to fire and forget ... and removed the bToggle from both activators. (First spell is concentration)

 

It works! No more CTD. Now i just need the impact data to reliably show up on the xmarkers all the targetlocations are for. After days of testing I am still unsure as to why my projectile from my first (activated visuals) always shows from my magic effect and why my impact data for the projectile only shows occasionally. If anyone reading this has any experience of this I would really like to know.

 

Yet to try it as one script but suspect changing the way the spell was implemented made it work rather than removing the bToggle.

 

If anyone can help me tidy the script up (make it more efficent) I'd be very grateful.

 

Thanks.

Edited by TyburnKetch
Link to comment
Share on other sites

I am not really understand, what are you doing. Nevertheless next source could be helpful.

 

THPortalActivatorScript

 

Scriptname THPortalActivatorScript extends ObjectReference
;https://forums.nexusmods.com/index.php?/topic/7114096-help-needed-with-activator-script/

  Spell PROPERTY THPortalGateSpell auto
  Spell PROPERTY THPortalGateSpell2 auto

  ObjectReference[] PROPERTY TargetArray auto        ; TargetLocation7, .. , TargetLocation0
  Bool bBusy                                         ; False by default


; -- EVENTs

EVENT OnInit()
; https://www.creationkit.com/index.php?title=BlockActivation_-_ObjectReference
    self.BlockActivation(TRUE)                        ; blocks this object from processing activation normally
ENDEVENT


;=========================================
auto state Waiting
;=================
EVENT OnActivate(ObjectReference akActionRef)
IF (akActionRef == Game.GetPlayer() as ObjectReference)
ELSE
    RETURN    ; - STOP -    not the player, do nothing
ENDIF
;---------------------
    bBusy = TRUE            ; *T*
    gotoState("Done")                ; ### STATE ###
    myF_Action()
ENDEVENT
;=======
endState


;=========================================
state Done
;=========
EVENT OnActivate(ObjectReference akActionRef)
IF ( bBusy )
    RETURN    ; - STOP -    I am busy activating!
ENDIF
;---------------------
IF (akActionRef == Game.GetPlayer() as ObjectReference)
ELSE
    RETURN    ; - STOP -    not the player, do nothing
ENDIF
;---------------------
    bBusy = False            ; ***
    gotoState("Waiting")            ; ### STATE ###
ENDEVENT
;=======
endState



; -- FUNCTION --

FUNCTION myF_Action()
;--------------------
int i = TargetArray.Length                           ; length should be 8
    WHILE (i)
        i = i - 1
        objectReference oRef = TargetArray[i]        ; TargetArray[7] == TargetLocation0, .. , TargetArray[0] == TargetLocation0
        IF ( oRef )
            THPortalGateSpell.Cast(oRef)
        ENDIF
    ENDWHILE
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

I'm not totally sure what you're trying to do -- looks like you want an activator to cast a set of spells that open portals to various locations -- but the usual approach to toggling activators is to use Papyrus States: https://www.creationkit.com/index.php?title=States_(Papyrus)

 

 

 
Auto State Off

  Event OnActivate(ObjectReference akActionRef)
    GotoState("On")
  EndEvent
 
EndState
 
State On
  Event OnActivate(ObjectReference akActionRef)
    GotoState("Off")
  EndEvent
EndState

 

You can basically write two entirely separate set of event handlers for the two (or more, potentially!) activation states in this way. It's a powerful and flexible tool.

 

As far as turning the spell on or off, there's a few approaches you might try. InterruptCast() may work -- I've never used it -- or you could insert a condition into the spell itself that a particular GlobalVariable be true, or you could add some script to the active magic effects that register them with the activator and then use Dispel() on the active magic effects.

Link to comment
Share on other sites

Thank you both so much for replying. Some really useful information here with Arrays and States.

 

Have started to implement it.

 

What I'm doing is firing the same projectile spell from the activator (a pedstal) to 8 seperate xmarkers dotted around a stone ring (close to pedstal) to create some portal visuals.

 

I'm also having issues with my impact data registering it's visuals only sporadically. Projectile data always hits and shows it's visuals. I feel the xmarkers may be the issue but after days of testing i'm still at a loss. It may be that it's a concentration spell but having changed it to fire and effect the effect only fires once then fades.

 

I'm also trying to connect a triggerbox to the pedstal activator and have enabled parent and added these lines to my source code on the activator:

 

ObjectReference Property TriggerBox Auto

 

TriggerBox.enable()

; under GotoState ON

 

 

TriggerBox.disable()

; under GotoState OFF

 

But so far they're not talking to each other.

 

Any further help would be seriously appreciated.

Edited by TyburnKetch
Link to comment
Share on other sites

I think you're actually having the >XMarkers< perform the cast, with an unspecified target. The first (and required) parameter of the Cast function is the source of the spell, not the target. The target is the second, optional one. That may explain some of your issues.

 

https://www.creationkit.com/index.php?title=Cast_-_Spell

 

As far as the triggerbox not turning on and off: Did you remember to fill the property?

Link to comment
Share on other sites

Thank you again for replying. You're absolutely right. They were just firing on themselves.

 

Unfortunately having added a source (or 8 to be precise) in the centre of the ring for the spell to fire from I am still only consistantly seeing the projectile visual data and not the data impact. Do you think distance might be an issue?

 

I've tried mixing and matching directions (in to out - out to in) and it doesnt seem to make a difference. Is very odd.

 

As for the triggerbox not turning on and off I have filled the property. The spell on the triggerbox (teleportation visuals and an options message box) keeps firing no matter what state the activator is in.

 

Current state of script on activator: (I need to sort out Arrays)

Scriptname THPortalActivator extends ObjectReference 

Spell Property THPortalGateSpell auto
Spell Property THPortalGateSpell2 auto
ObjectReference Property TargetLocationCentre0 auto
ObjectReference Property TargetLocationCentre1 auto
ObjectReference Property TargetLocationCentre2 auto
ObjectReference Property TargetLocationCentre3 auto
ObjectReference Property TargetLocationCentre4 auto
ObjectReference Property TargetLocationCentre5 auto
ObjectReference Property TargetLocationCentre6 auto
ObjectReference Property TargetLocationCentre7 auto
ObjectReference Property TargetLocation0 auto
ObjectReference Property TargetLocation1 auto
ObjectReference Property TargetLocation2 auto
ObjectReference Property TargetLocation3 auto
ObjectReference Property TargetLocation4 auto
ObjectReference Property TargetLocation5 auto
ObjectReference Property TargetLocation6 auto
ObjectReference Property TargetLocation7 auto
ObjectReference Property TriggerBox Auto


Auto State Off
Event OnActivate(ObjectReference akActionRef)
GotoState("On")
TriggerBox.enable()
THPortalGateSpell.Cast(TargetLocationCentre0, TargetLocation0)
THPortalGateSpell.Cast(TargetLocationCentre1, TargetLocation1)
THPortalGateSpell.Cast(TargetLocationCentre2, TargetLocation2)
THPortalGateSpell.Cast(TargetLocationCentre3, TargetLocation3)
THPortalGateSpell.Cast(TargetLocationCentre4, TargetLocation4)
THPortalGateSpell.Cast(TargetLocationCentre5, TargetLocation5)
THPortalGateSpell.Cast(TargetLocationCentre6, TargetLocation6)
THPortalGateSpell.Cast(TargetLocationCentre7, TargetLocation7)
EndEvent
EndState

State On
  Event OnActivate(ObjectReference akActionRef)
    GotoState("Off")
TriggerBox.disable()
THPortalGateSpell2.Cast(TargetLocationCentre0, TargetLocation0)
THPortalGateSpell2.Cast(TargetLocationCentre1, TargetLocation1)
THPortalGateSpell2.Cast(TargetLocationCentre2, TargetLocation2)
THPortalGateSpell2.Cast(TargetLocationCentre3, TargetLocation3)
THPortalGateSpell2.Cast(TargetLocationCentre4, TargetLocation4)
THPortalGateSpell2.Cast(TargetLocationCentre5, TargetLocation5)
THPortalGateSpell2.Cast(TargetLocationCentre6, TargetLocation6)
THPortalGateSpell2.Cast(TargetLocationCentre7, TargetLocation7)

EndEvent
EndState

I found having just one centre marker firing at the 8 xmarkers would only fire the spell at one location which is why I've created 8 centre markers for the eight around the ring. The effect is great - just wish is could be perfect with the impact data consistantly firing.

Link to comment
Share on other sites

*Update*

 

I've resolved the impact data issue ... I am simply not using it. I am now using two projectiles without impact data that are giving a very good result. I'm disappointed to not know why the impact data would only sporadically show up (it looks incredible when it does) and would still like to pursue an answer - but for now very good visuals are fine.

 

Xmarker position is very important to getting the spells to hit. Ran into issues with the new layout of xmarkers - with only the projectiles operating in my magiceffect - and after a few xmarker tweaks and rotations the spells now seem solid in making contact with their hit location markers. (I want to do a lot more testing)

 

I've also resolved the triggerbox / activator communication issue:

 

https://www.creationkit.com/index.php?title=Enable

 

Found out Enable will never work if the object has an Enable Parent. Swiched to Activate Parent (makes sense i guess) and the script on the activator - Triggerbox.Enable() - is now working as intended. Is this practice correct?

 

Just need to set Arrays up.

 

Thank you for all your help.

Link to comment
Share on other sites

  • 3 weeks later...

Thank you.

 

I have ran into another issue that I hope someone can help me with.

 

The portal can be seen through a window in an interior cell that is linked to the exterior cell the portal is in. I have reconstructed the portal in the interior cell where it would be seen through the window. I have set up all the markers and added a script to my activator (that is in the ext cell) pointing to the markers in the interior cell. It is not working. I need to be able to see the portal visuals from the interior cell when activated from the exterior activator.

 

I have ran multiple tests - It all works as intended if the activator and the markers are in the same cell but not when in different cells.

 

What am i missing?

 

Many thanks.

Edited by TyburnKetch
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...