Jump to content

Arrow to change properties when fired through trigger box


Recommended Posts

Hello

 

I'm trying to write my first mod, and this might be easy, but I can't figure it out.

 

I want to create a magic portal that arrows are fired through, and on doing this will change what type of arrow it is.

 

I've created a trigger box and added an 'onTriggerEnter' event, which can display a message to confirm an arrow has activated the trigger box, and the object ref of the individual arrow in question. But I don't know how to add some script to change the properites of that individual arrow.

 

Changing any property of the arrow would probably do, as I could add a spell that can be cast on the arrow to complete the transformation. This spell could simply remove the arrow and replace it with a different type of arrow. But the spell would have to work only on an arrow that has been fired through the portal, as this is part of the process to create these magical arrows.

 

Any ideas how to do this?

 

Thanks in advance.

Link to comment
Share on other sites

Use the OnTriggerEnter of the trigger volume box. You've already stated that you can get the specific object reference and know that it is entering. So once you confirm that a certain arrow has entered, play some kind of FX, remove the original arrow and place the magical arrow in its spot. I don't think you need to change anything on the original arrow to accomplish this.

 

My question: Is this supposed to be done mid-flight or is there something that stops the arrow from moving after entering the portal?

Link to comment
Share on other sites

In your trigger box change its 'Collision Layer' to "L_PROJECTILEZONE", this way the trigger box will only fire its script when a projectile enters it and not from an arrow or anything else.


This automaticaly relieves you from further scripting or other workarounds by double fireing (the script) when your script spawns an arrow inside it.


To spawn the arrow the easiest way is to put an xMarker in its center and once your script has detect the "Projectile" place the New Arrow at the xMarker position and then disable > delete the projectile.

Edited by maxarturo
Link to comment
Share on other sites

Use the OnTriggerEnter of the trigger volume box. You've already stated that you can get the specific object reference and know that it is entering. So once you confirm that a certain arrow has entered, play some kind of FX, remove the original arrow and place the magical arrow in its spot. I don't think you need to change anything on the original arrow to accomplish this.

 

My question: Is this supposed to be done mid-flight or is there something that stops the arrow from moving after entering the portal?

Hello. Thanks for your prompt response. Yes, this is done mid-flight. The portal will look like a ring and the player aims the arrow through the centre and its flight is unaffected by the portal (as long as the arrow avoids the edges of the portal). I've figured out how to disable the arrow (and make it disappear mid-flight when it enters triggers the box). This may be basis stuff, but what statement would I use within the trigger script to put the new arrow in the place of the original?

Link to comment
Share on other sites

 

In your trigger box change its 'Collision Layer' to "L_PROJECTILEZONE", this way the trigger box will only fire its script when a projectile enters it and not from an arrow or anything else.
This automaticaly relieves you from further scripting or other workarounds by double fireing (the script) when your script spawns an arrow inside it.
To spawn the arrow the easiest way is to put an xMarker in its center and once your script has detect the "Projectile" place the New Arrow at the xMarker position and then disable > delete the projectile.

 

Hello

I'm afraid my modding skills are still pretty basic. How do I place an Xmarker then create a new arrow in the Xmarker position?

Link to comment
Share on other sites

What is about the following, you have the trigger with fx and a target object, like the things ("the shooting targets", Zielscheiben) outside jorrvaskr or in dragonsreach (Whiterun town).

 

xyzTriggerPortalScript

 

Scriptname xyzTriggerPortalScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/8691908-arrow-to-change-properties-when-fired-through-trigger-box/

  ObjectReference PROPERTY myTarget auto    ; the shooting target, which should be the final goal of arrows

; -- EVENTs --

; Part 1: "I want to create a magic portal that arrows are fired through, .."

EVENT OnInit()
    Debug.Trace(" OnInit( Trigger ) - has been reached.. " +self)
ENDEVENT


EVENT OnCellLoad()
    gotoState("Waiting")            ; ### STATE ###
    Debug.Trace(" OnCellLoad() - has been reached.. " +self)
ENDEVENT


EVENT OnUnLoad()
    gotoState("Done")                ; ### STATE ###
    Debug.Trace(" OnCellLoad() - has been reached.. " +self)    
ENDEVENT


;======================
state Waiting
;============
    EVENT OnTriggerEnter(ObjectReference triggerRef)
        (myTarget as xyzTargetScript).myArrow = triggerRef        ; store the Ref into other script
        Debug.Trace(" OnTriggerEnter() - with " +triggerRef+ ", baseObject = " +triggerRef.GetBaseObject())        ; for debugging only !!
    ENDEVENT
;=======
endState


;======================
state Done  ; do not trigger anything
;=========
    EVENT OnTriggerEnter(ObjectReference triggerRef)
    ENDEVENT
;=======
endState

 

 

 

xyzTargetScript

 

Scriptname xyzTargetScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/8691908-arrow-to-change-properties-when-fired-through-trigger-box/

  Formlist PROPERTY myList auto     ; new formlist created within CK, filled with baseobjects which contain the arrows you want to trigger
  ; IronArrow
  ; SteelArrow
  ; SilverArrow
  ; ..

  Formlist PROPERTY myList2 auto   ; new formlist created within CK, filled with baseobjects to place a new arrow instead
  ; fireArrow
  ; frostArrow
  ; shockArrow
  ; ..

  ObjectReference PROPERTY myArrow auto Hidden        ; the arrow flying trough the trigger


; -- EVENTs --

; Part 2: ".. and on target this will change what type of arrow it is."

EVENT OnInit()
    Debug.Trace(" OnInit( Target ) - has been reached.. " +self)
ENDEVENT


EVENT OnCellDetach()
    myArrow = None        ; jus in case, to release script persistence
ENDEVENT


EVENT OnActivate(ObjectReference actionRef)
    IF (actionRef == myArrow)
        myF_Place(actionRef)
    ENDIF
ENDEVENT


; -- FUNCTION --

;--------------------------------------------
FUNCTION myF_Place(ObjectReference actionRef)
;--------------------------------------------
    myArrow = None                                        ; clean out for next shot
    int i = myList.Find( actionRef.GetBaseObject() )

IF (i < 0)
    RETURN    ; - STOP -    not found within arrow list, do not touch the arrow
ENDIF
;---------------------
    i = myList2.GetSize() - 1
    i = Utility.RandomInt(0, i)        ; get a random entry for new arrow to place

; "remove the original arrow and place the magical arrow in its spot." (IsharaMeradin)
    actionRef.DisableNoWait()                                            ; disable the original arrow
    objectReference oRef = actionRef.PlaceAtMe( myList2.GetAt(i) )       ; place the new arrow
    actionRef.Delete()                                                   ; mark the original arrow for delete
ENDFUNCTION

 

 

 

If you cannot use a script on this target object, then use an invisible layer object (above the target surface) which can be activated and assign this with the script.

Edited by ReDragon2013
Link to comment
Share on other sites

What is about the following, you have the trigger with fx and a target object, like the things ("the shooting targets", Zielscheiben) outside jorrvaskr or in dragonsreach (Whiterun town).

 

xyzTriggerPortalScript

 

Scriptname xyzTriggerPortalScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/8691908-arrow-to-change-properties-when-fired-through-trigger-box/

  ObjectReference PROPERTY myTarget auto    ; the shooting target, which should be the final goal of arrows

; -- EVENTs --

; Part 1: "I want to create a magic portal that arrows are fired through, .."

EVENT OnInit()
    Debug.Trace(" OnInit( Trigger ) - has been reached.. " +self)
ENDEVENT


EVENT OnCellLoad()
    gotoState("Waiting")            ; ### STATE ###
    Debug.Trace(" OnCellLoad() - has been reached.. " +self)
ENDEVENT


EVENT OnUnLoad()
    gotoState("Done")                ; ### STATE ###
    Debug.Trace(" OnCellLoad() - has been reached.. " +self)    
ENDEVENT


;======================
state Waiting
;============
    EVENT OnTriggerEnter(ObjectReference triggerRef)
        (myTarget as xyzTargetScript).myArrow = triggerRef        ; store the Ref into other script
        Debug.Trace(" OnTriggerEnter() - with " +triggerRef+ ", baseObject = " +triggerRef.GetBaseObject())        ; for debugging only !!
    ENDEVENT
;=======
endState


;======================
state Done  ; do not trigger anything
;=========
    EVENT OnTriggerEnter(ObjectReference triggerRef)
    ENDEVENT
;=======
endState

 

 

 

xyzTargetScript

 

Scriptname xyzTargetScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/8691908-arrow-to-change-properties-when-fired-through-trigger-box/

  Formlist PROPERTY myList auto     ; new formlist created within CK, filled with baseobjects which contain the arrows you want to trigger
  ; IronArrow
  ; SteelArrow
  ; SilverArrow
  ; ..

  Formlist PROPERTY myList2 auto   ; new formlist created within CK, filled with baseobjects to place a new arrow instead
  ; fireArrow
  ; frostArrow
  ; shockArrow
  ; ..

  ObjectReference PROPERTY myArrow auto Hidden        ; the arrow flying trough the trigger


; -- EVENTs --

; Part 2: ".. and on target this will change what type of arrow it is."

EVENT OnInit()
    Debug.Trace(" OnInit( Target ) - has been reached.. " +self)
ENDEVENT


EVENT OnCellDetach()
    myArrow = None        ; jus in case, to release script persistence
ENDEVENT


EVENT OnActivate(ObjectReference actionRef)
    IF (actionRef == myArrow)
        myF_Place(actionRef)
    ENDIF
ENDEVENT


; -- FUNCTION --

;--------------------------------------------
FUNCTION myF_Place(ObjectReference actionRef)
;--------------------------------------------
    myArrow = None                                        ; clean out for next shot
    int i = myList.Find( actionRef.GetBaseObject() )

IF (i < 0)
    RETURN    ; - STOP -    not found within arrow list, do not touch the arrow
ENDIF
;---------------------
    i = myList2.GetSize() - 1
    i = Utility.RandomInt(0, i)        ; get a random entry for new arrow to place

; "remove the original arrow and place the magical arrow in its spot." (IsharaMeradin)
    actionRef.DisableNoWait()                                            ; disable the original arrow
    objectReference oRef = actionRef.PlaceAtMe( myList2.GetAt(i) )       ; place the new arrow
    actionRef.Delete()                                                   ; mark the original arrow for delete
ENDFUNCTION

 

 

 

If you cannot use a script on this target object, then use an invisible layer object (above the target surface) which can be activated and assign this with the script.

Thanks for providing some scripts to look at. I've studied these and think I understand most of what's happening here (I'm quite new to this). The key thing, I think, is passing the object ref of the arrow from the trigger script to the 2nd script, which will then decide if to change the arrow type.

This script will be used on just one kind of arrow (type created by me) and turn it into a second tupe (created by me), so I'm guessing I can avoid the use of form lists, to simplify things a little.

It's my intention that arrows fired through the portal will not be aimed as at particular target, but will bounced off objects and have to be picked up off the ground (part of the difficulty of the quest will be figuring out how to retrieve the arrow without having to search a whole mountainside). This might be a problem regarding what the 2nd script is attached to (unless I can create an invisible layer object that will cover everywhere that an arrow might land). I'm happy for the player to have to cast a spell on the arrow once it's passed through the portal, in order to complete the transformation. So perhaps the 2nd script could be incorporated into a magic effect script - this would check the spell is being cast on the arrow that just passed through the portal, and only transform the arrow into a different type if this is the case. I notice that active magic effect events apply to actors not objects, so perhaps I'll have to do something similar to the transmute spell, and have the actor pick up the arrow and then use a variation of this spell to change the arrow from one type to another.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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