Placing an activator with a spell without a target and FindC

Post » Mon Jun 18, 2012 11:01 am

Hi all!

My idea was creating an aimed or target location spell that places an activator and then uses the FindClosestReference functions to find the closest door that, ehem, needs to be opened :smile:

My progress and issues so far:

1. The self version of the spell using FindClosestReferenceOfAnyTypeInList works like a charm. So I have a spell that opens the closest door to the player if it is in the FormList of course...It would be cooler to not have to add the doors in the FormList, but it's a beginning

Spoiler

scriptName ShanaOpenSelfTestScript extends ActiveMagicEffect{Scripted magic effect blablabla.}import utilityimport gameFormList property ShanaThingsOpenable auto;======================================================================================;;  VARIABLES   /;=============/objectReference CastFromHereReffloat RadiusToFindDoor = 100.0;======================================================================================;;   EVENTS	 /;=============/Event OnInit()  Debug.Trace(" ShanaOpenSelfTestScript OnInit ")EndEventEvent OnEffectStart(Actor Target, Actor Caster)  Debug.Trace(" Looking for doors")  CastFromHereRef = Caster  ObjectReference closestDoor  = Game.FindClosestReferenceOfAnyTypeInListFromRef(ShanaThingsOpenable, CastFromHereRef, RadiusToFindDoor )  if ( closestDoor == None)	Debug.Notification("There is no door near!")  else	Debug.Trace("The closest door is: " + closestDoor)	if( closestDoor.isLocked() )	  Debug.Notification("Opening door!!!")	 closestDoor.Lock(false)	endif  endifEndEvent


2. I have managed to create an activator with PlaceAtMe and modify the previous script to find references closest to it, but it only works when I shoot the spell at some actor feet....My guess is that it needs a target actor, which is not exactly what I was thinking...

Spoiler
scriptName ShanaAimedOpenTestScript extends ActiveMagicEffect{Scripted magic effect Placing and activator and then removing it.}import utilityimport game;======================================================================================;;  PROPERTIES  /;=============/activator property FXEmptyActivator auto{The name of the placed Activator that the spell will come from. (REQUIRED!)}FormList property ShanaThingsOpenable auto;======================================================================================;;  VARIABLES   /;=============/ObjectReference closestDoorobjectReference ActivatorReffloat RadiusToFindDoor = 1000.0;======================================================================================;;   EVENTS	 /;=============/Event OnInit()  Debug.Trace(" ShanaAimedOpenTestScript OnInit ")EndEventEvent OnEffectStart(Actor Target, Actor Caster)  Debug.Trace(" ShanaAimedOpenTestScript OnEffectStart begins")  ActivatorRef = Target.placeAtMe(FXEmptyActivator)  Debug.Trace("After placeAtMe")  if ( ActivatorRef != None)	Debug.Trace("Activator has been placed")  Else	Debug.Trace("Activator has NOT been placed!")  endif  Debug.Trace(" Looking for doors...hopefully")  closestDoor  = Game.FindClosestReferenceOfAnyTypeInListFromRef(ShanaThingsOpenable, ActivatorRef, RadiusToFindDoor )  Debug.Trace(" ShanaAimedOpenTestScript : After FindClosestReferenceOfAnyTypeInListFromRef")  if ( closestDoor == None)	Debug.Trace("There is no door near!")	Debug.Notification("There is no door near!")  else	Debug.Trace("The closest door is: " + closestDoor)	if( closestDoor.isLocked() )	 Debug.Trace("Opening door!!!")	 Debug.Notification("Opening door!!!")	 closestDoor.Lock(false)	else	 Debug.Notification("The door is not closed!")	 Debug.Trace("The door is not closed!")	endif  endif  Debug.Trace(" ShanaAimedOpenTestScript OnEffectStart ends")EndEventEvent OnEffectFinish(Actor Target, Actor Caster)  if (ActivatorRef != none)	ActivatorRef.disable()	ActivatorRef.delete()endifEndEvent

3. I have been trying to use FindClosestReferenceOfTypeFromRef instead of the FormList version to see if it could make a difference, but whatever I try, I always get the runtime error error: None or invalid form type as Base object for FindClosestReferenceOfType
even when I trace the form and it looks ok WRShackDoor01 : [Form < (0000028A)>]
Spoiler


scriptName ShanaOpenSelfTest2Script extends ActiveMagicEffect{Scripted magic effect blablabla.}import utilityimport gameForm property WRShackDoor01 auto;======================================================================================;;  VARIABLES   /;=============/objectReference CastFromHereRefObjectReference closestDoorfloat RadiusToFindDoor = 500.0;======================================================================================;;   EVENTS	 /;=============/Event OnInit()  Debug.Trace(" ShanaOpenSelfTest2Script OnInit ")  Debug.Trace(" WRShackDoor01 : " + WrShackDoor01)EndEventEvent OnEffectStart(Actor Target, Actor Caster)  Debug.Notification(" ShanaOpenSelfTest2Script OnEffectStart ")  Debug.Trace(" ShanaOpenSelfTest2Script OnEffectStart ")  Debug.Trace(" Looking for doors...hopefully")  Debug.Notification(" Looking for doors...hopefully")  CastFromHereRef = Caster  closestDoor  = Game.FindClosestReferenceOfTypeFromRef(WRShackDoor01, CastFromHereRef, RadiusToFindDoor )  if ( closestDoor == None)    Debug.Trace("There is no door near!")    Debug.Notification("There is no door near!")  else    Debug.Trace("The closest door is: " + closestDoor)    if( closestDoor.isLocked() )     Debug.Trace("Opening door!!!")     Debug.Notification("Opening door!!!")     closestDoor.Lock(false)    endif  endif  Debug.Trace(" ShanaOpenSelfTest2Script OnEffectStart End")EndEvent

So my questions are,

- Is there a way to place an activator or whatever type of object in a spell without having a target or a workaround to do what I want? Maybe following a magic projectile last known location and run the FindClosestReference part when it's disabled?
- What's the right way of passing a parameter to FindClosestReferenceOfAnyTypeFromRef? It looks like passing it a Form as it says in the wiki doesn't work, or that I'm missing something...
- (Fixed lol ) THE MOST IMPORTANT: How do I pretty print the code inside the Spoiler tags? lol
User avatar
Elle H
 
Posts: 3407
Joined: Sun Aug 06, 2006 3:15 am

Post » Mon Jun 18, 2012 12:25 pm

If you associate an explosion with your projectile, you can add a "Placed Object" to that explosion and attach a script to that object so that you can use the impact location of a spell even without an actor target.

To print your scripts with pretty formatting, use code tags. This post explains how - http://www.gamesas.com/topic/1347469-how-to-ask-for-scripting-help/

Cipscis

EDIT:

If you try to call FindClosestReferenceOfType in the equivalent way to how you're calling FindClosestReferenceOfTypeFromRef, do you get the same error?

Cipscis
User avatar
Sophie Louise Edge
 
Posts: 3461
Joined: Sat Oct 21, 2006 7:09 pm

Post » Mon Jun 18, 2012 11:58 am

If you associate an explosion with your projectile, you can add a "Placed Object" to that explosion and attach a script to that object so that you can use the impact location of a spell even without an actor target.

To print your scripts with pretty formatting, use code tags. This post explains how - http://www.gamesas.com/topic/1347469-how-to-ask-for-scripting-help/

Cipscis

EDIT:

If you try to call FindClosestReferenceOfType in the equivalent way to how you're calling FindClosestReferenceOfTypeFromRef, do you get the same error?

Cipscis

That sounds neat. I am not sure thought how to reference the placed object or its location from the spell script. Maybe adding a script in the object that save its reference to a quest property or is there any other way? Is there any example ingame that I can check? I haven't checked on quests stuff yet, so if that is the way I guess I have an excuse now hehehe.

Thanks for the editing tips. It seems that tabbing in notepad isn't shown correctly in here, so I've had to double space most lines...but now it looks niiiiice lol.

As for the FindClosestReference functions, I haven't tried that since I've seen in Game.psc this:

; Finds the closest reference of a given base object within a given radius of a referenceObjectReference Function FindClosestReferenceOfTypeFromRef(Form arBaseObject, ObjectReference arCenter, float afRadius) global  return FindClosestReferenceOfType(arBaseObject, arCenter.X, arCenter.Y, arCenter.Z, afRadius)endFunction

So I guessed it would not make a difference. However I guess it's worth trying. I have to go now, but I'll check in a few hours.

Thanks for your answers!
User avatar
Kanaoka
 
Posts: 3416
Joined: Fri Jun 16, 2006 2:24 pm

Post » Mon Jun 18, 2012 4:27 pm

At last I managed to create a No Magnitude and No Hit effect with Target Location delivery that places an object, using a quest to save the ObjectReference. In case anybody wonders, here are the scripts, that now seem too easy :smile:
Quest Script
Spoiler
Scriptname ShanaVarsQuestScript extends QuestObjectReference Property ShanaVarsQuestObject auto ; for Objects
Activator Script
Spoiler
Scriptname ShanaEmptyActivatorScript extends ObjectReferenceShanaVarsQuestScript Property QuestRef AutoEvent OnInit()  Debug.Trace("ShanaEmptyActivatorScript OnInit")  QuestRef.ShanaVarsQuestObject = selfEndEvent
Spell Script
Spoiler
scriptName ShanaPlaceActivatorScript extends ActiveMagicEffect{Scripted magic effect Placing and activator and then removing it.};======================================================================================;; PROPERTIES /;=============/ShanaVarsQuestScript Property QuestRef Auto;======================================================================================;; VARIABLES /;=============/ObjectReference ActivatorRef;======================================================================================;; EVENTS /;=============/Event OnInit()EndEventEvent OnEffectStart(Actor Target, Actor Caster)  Debug.Trace(" ShanaPlaceActivatorScript OnEffectStart begins")  utility.wait(0.1)  ; Activator is supposed to be placed by the explosion  ActivatorRef = QuestRef.ShanaVarsQuestObject  if ( ActivatorRef != None)	Debug.Trace("ActivatorRef = " + ActivatorRef)	Debug.Trace("Do something here")  else	Debug.Trace("ActivatorRef == None !!!")  endif  Debug.Trace(" ShanaPlaceActivatorScript OnEffectStart ends")EndEventEvent OnEffectFinish(Actor Target, Actor Caster)  utility.wait(0.1)  if (ActivatorRef != none)	Debug.Trace("Clearing Activator reference")	ActivatorRef.disable()	ActivatorRef.delete()  endifEndEvent


The only issue I see is that it seems to be placing more than one activator...Maybe it depends on the area of the spell or something...No idea...

As for the FindClosestReferenceOfType functions. Nothing. I am still getting the none or invalid form when tracing. Here is the Magic Effect script:

Spoiler
scriptName ShanaOpenSelfTest2Script extends ActiveMagicEffect{Scripted magic effect blablabla.}import utilityimport gameForm property WRShackDoor01 auto;======================================================================================;;  VARIABLES   /;=============/objectReference CastFromHereRefObjectReference closestDoorfloat RadiusToFindDoor = 100000.0;======================================================================================;;   EVENTS	 /;=============/Event OnInit()  Debug.Trace(" ShanaOpenSelfTest2Script OnInit ")EndEventEvent OnEffectStart(Actor Target, Actor Caster)  Debug.Trace(" ShanaOpenSelfTest2Script OnEffectStart ")  Debug.Trace(" WRShackDoor01 : " + WrShackDoor01)  CastFromHereRef = Caster  closestDoor  = Game.FindClosestReferenceOfTypeFromRef(WRShackDoor01, CastFromHereRef, RadiusToFindDoor )  utility.wait(1)  if ( closestDoor == None)	Debug.Trace("FindClosestReferenceOfTypeFromRef returned no door. Testing Coordenades version")	closestDoor = Game.FindClosestReferenceOfType( WRShackDoor01, CastFromHereRef.X, CastFromHereRef.Y, CastFromHereRef.Z, RadiusToFindDoor)	if ( closestDoor == None )	 Debug.Trace("Still no door!")	else	  Debug.Trace(" Coordenades version returned a door! " + closestDoor)	endif  endif  if( closestDoor != None )	Debug.Trace("The closest door is: " + closestDoor)	if( closestDoor.isLocked() )	 Debug.Trace("Opening door!!!")	 closestDoor.Lock(false)	endif  endif  Debug.Trace(" ShanaOpenSelfTest2Script OnEffectStart End")EndEvent

And the log:

Spoiler
[02/16/2012 - 11:43:07AM] ShanaOpenSelfTest2Script OnInit
[02/16/2012 - 11:43:07AM] ShanaOpenSelfTest2Script OnEffectStart
[02/16/2012 - 11:43:07AM] WRShackDoor01 : [Form < (0000028A)>]
[02/16/2012 - 11:43:07AM] error: None or invalid form type as Base object for FindClosestReferenceOfType
stack:
.Game.FindClosestReferenceOfType() - "" Line ?
.Game.FindClosestReferenceOfTypeFromRef() - "Game.psc" Line ?
[Active effect 1 on (00000014)].ShanaOpenSelfTest2Script.OnEffectStart() - "ShanaOpenSelfTest2Script.psc" Line ?
[02/16/2012 - 11:43:08AM] FindClosestReferenceOfTypeFromRef returned no door. Testing Coordenades version
[02/16/2012 - 11:43:08AM] error: None or invalid form type as Base object for FindClosestReferenceOfType
stack:
.Game.FindClosestReferenceOfType() - "" Line ?
[None].ShanaOpenSelfTest2Script.OnEffectStart() - "ShanaOpenSelfTest2Script.psc" Line ?
[02/16/2012 - 11:43:08AM] Still no door!
[02/16/2012 - 11:43:08AM] ShanaOpenSelfTest2Script OnEffectStart End

Has anyone any hint about how to make it work or any example? The FormList version in the opening post works, but I'm kinda wanting to make this one work too...

Thaaaaanks!

EDIT: Format
User avatar
Quick draw II
 
Posts: 3301
Joined: Thu Nov 08, 2007 4:11 pm

Post » Mon Jun 18, 2012 8:18 pm

It's good that you've got this far :D.

What did you set WRShackDoor01's property to?
User avatar
Matthew Warren
 
Posts: 3463
Joined: Fri Oct 19, 2007 11:37 pm

Post » Tue Jun 19, 2012 12:35 am

It's good that you've got this far :biggrin:.

What did you set WRShackDoor01's property to?

As for the WRShackDoor01 is the form of a couple of doors in Whiterun, Ysolde′s house and another one I think. Still, FindClosestReferenceOfTypeFromRef retunrs that error :(

Using FindClosestReferenceOfAnyTypeInListFromRef(ShanaThingsOpenable, CastFromHereRef, RadiusToFindDoor ) with drag and dropping all the Whiterun doors in the FormList made it work though.

I am still wondering if it's possible to target directly a door with a spell and cast actor into ObjectReference to not have to list all doors, but I haven't been able to make it work, thus the placing activator on spell explosion to use FindClosestReference :(
User avatar
Mélida Brunet
 
Posts: 3440
Joined: Thu Mar 29, 2007 2:45 am

Post » Mon Jun 18, 2012 4:25 pm

Yeah I haven't been able to make it work. We'll just have to hope the SKSE team find a way of getting a reference that's in the player's crosshair, then we can manipulate that object a lot easier. This way is very messy.
User avatar
Dan Scott
 
Posts: 3373
Joined: Sun Nov 11, 2007 3:45 am

Post » Mon Jun 18, 2012 9:43 pm

Bump begging for a FindClosestReferenceOfType working example. I've searched through all scripts and there isn't any...one wonders why :(
User avatar
Suzie Dalziel
 
Posts: 3443
Joined: Thu Jun 15, 2006 8:19 pm

Post » Mon Jun 18, 2012 2:51 pm

Ok...I got it...

The thing is trying to use a Form property to auto-fill does not seem to work

Form property WRShackDoor01 auto

But instead using a child type does.

Door property WRShackDoor01 auto
So I guess one idea for Form properties will be to use them in parent scripts and fill them with other types in childs...


Spoiler
scriptName OpenShackDoorScript extends ActiveMagicEffect{Script for a Self Spell that opens the nearest Whiterun shack door}import gameDoor property WRShackDoor01 auto;======================================================================================;;  VARIABLES   /;=============/objectReference CastFromHereRefObjectReference closestDoorfloat RadiusToFindDoor = 1000.0;======================================================================================;;   EVENTS	 /;=============/Event OnEffectStart(Actor Target, Actor Caster)  CastFromHereRef = Caster  closestDoor  = Game.FindClosestReferenceOfTypeFromRef(WRShackDoor01, CastFromHereRef, RadiusToFindDoor )  if ( closestDoor == None)	Debug.Notification("There is no shack door near!")  else	if( closestDoor.isLocked() )	 Debug.Notification("Opening door!")	 closestDoor.Lock(false)	else	 Debug.Notification("The door is not locked!")	endif  endifEndEvent

I have added the example in the wiki as well.
User avatar
Lyd
 
Posts: 3335
Joined: Sat Aug 26, 2006 2:56 pm

Post » Mon Jun 18, 2012 1:52 pm

I just went through the entire same process.

Decided I didn't want to go through every lockable container and door in the creation kit and add a script to them for onHit events.

So I spent 5 hours figuring out magic effects, projectiles, explosions, activators, then thought yay! I can use the findclosestref function now to get the closest container, and it turns out you can't unless you pass in a ref manually set to a specific door or container, or a formlist listing all the relevant doors and containers. So I'm back where I started, great

Previously when I was trying to use the findclosestactor function to find an actor closest to the player and it always just returns the player, I thought I had come across the most useless, inept bit of script design I had ever seen. Seems I was wrong.

Papyrus is a bloody disgrace, whoever designed this is a total moron.
User avatar
glot
 
Posts: 3297
Joined: Mon Jul 17, 2006 1:41 pm

Post » Mon Jun 18, 2012 4:22 pm

I just went through the entire same process.

Decided I didn't want to go through every lockable container and door in the creation kit and add a script to them for onHit events.

So I spent 5 hours figuring out magic effects, projectiles, explosions, activators, then thought yay! I can use the findclosestref function now to get the closest container, and it turns out you can't unless you pass in a ref manually set to a specific door or container, or a formlist listing all the relevant doors and containers. So I'm back where I started, great

Previously when I was trying to use the findclosestactor function to find an actor closest to the player and it always just returns the player, I thought I had come across the most useless, inept bit of script design I had ever seen. Seems I was wrong.

Papyrus is a bloody disgrace, whoever designed this is a total moron.

Oops. I hadn't checked the forums in a while. At the end I found out a more neat way of getting the nearest locked container/door. Check it http://www.gamesas.com/topic/1352976-a-working-open-door-spell
User avatar
Vincent Joe
 
Posts: 3370
Joined: Wed Sep 26, 2007 1:13 pm


Return to V - Skyrim