Jump to content

Unable to reference a property value from an object in my spell script


Jerevalaron

Recommended Posts

I'm attempting to create a spell that the player can cast to teleport himself to a particular location based on what trigger box he is currently in.

 

So, for example, if the player casts the spell while within triggerArea1, then teleport the player to Destination1. If the player casts the spell within triggerArea2, then teleport the player to Destination2. And vice versa. As part of my intended level design, I need it to work this way.

 

I have two different scripts, one for trigger box and one for the spell. However, since one is an object reference and the other is an active magic effect, I'm having trouble getting one script to access properties declared in the other.

 

I know some of the code shown below probably has a lot of issues (and if anyone knows a better way to handle this, please help).

 

My triggerbox script:

Scriptname Area1 extends ObjectReference  

ObjectReference Location1
Actor Property PlayerREF Auto
Bool Property EnableTeleport Auto

Function TeleportEnable()
EnableTeleport = True
return
EndFunction

Function TeleportDisable()
EnableTeleport = False
return
EndFunction


Event OnTriggerEnter(ObjectReference akActionRef) 
	If akActionRef == PlayerREF
		TeleportEnable()
EndIf
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
	If akActionRef == PlayerREF
	TeleportDisable()
EndIf
EndEvent

My spell script (partial):

Scriptname JR_Teleportation extends activemagiceffect  
{Teleports the caster to a different domain.}

ObjectReference property teleDest auto
ObjectReference property teleBegin auto
Bool Property EnableTeleport Auto


Event OnEffectFinish(Actor target, Actor caster)

	if EnableTeleport = True
	target.MoveTo(teleDest)
EndIf
EndEvent

What I want to do is pass the boolean value for "EnableTeleport" from the trigger box script to the spell script. But I've been unable to figure out a way to do this. I read somewhere that property values can only be passed between scripts if those scripts are attached to objects that are linked. However, I can't use a linked ref between my two scripts because my active magic effect is not something that can be dragged into the render window (like a trigger can).

 

I would appreciate any help in getting my code to work for my idea.

Link to comment
Share on other sites

In order to reference a property in a script attached to an object, you have to tell the current script that the object has that script attached. The way to do that is to either cast the object as the script type or to declare it as the script to begin with.

 

So in your case you need a property on your JR_Teleportation script that is:

Area1 property MyArea1 auto

The MyArea1 property will have access to all of the functions, events, and properties of an ObjectReference AS WELL AS all of the functions and properties that you declare in the Area1 script.

 

In order to determine if your Area1 trigger box currently has teleportation enabled, you would call:

if (MyArea1.EnableTeleport == True)
	target.MoveTo(teleDest)
endif
Link to comment
Share on other sites

I was attempting to get that to work, but no luck. Don't know what I'm missing there. The code you gave me compiled fine, but the teleport just isn't happening.

 

If I instead do something like this code below for each trigger box, how would I edit this code so that the teleport only happens after the player casts the spell while within the trigger area:

ObjectReference Property teleDest Auto
Spell Property TeleportSpell Auto
ObjectReference Player

Event OnTriggerEnter (ObjectReference akActionRef)

	TeleportSpell.Cast(self, akActionRef)

	Utility.Wait(2.5)

	akActionRef.MoveTo(teleDest)

EndEvent

So in this case I want to be able to point to a specific location for each trigger box to teleport the player to, but only after the player casts the specific Teleport Spell while within that trigger area.

 

I don't know how to get the trigger box script to wait for when the player casts the specific spell before performing the teleportation.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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