Jump to content

Papyrus Script Help, What am I missing?


Struckur

Recommended Posts

I'm trying to use the "FindAllReferencesOfType" function to list nearby objects but regardless of the type I use the result is always an empty array:

Form property TYPETOFIND auto mandatory

Event OnActivate(ObjectReference akActionRef)
	ObjectReference[] objs = Self.FindAllReferencesOfType(TYPETOFIND, 200.0)
	Debug.MessageBox( objs.length)	
EndEvent

I've tried setting "TYPETOFIND" to several values in the creation kit UI such as 'STATIC' > 'ShackMetalWallFlat01'. Then built a lot of that object, but regardless the count I get back is always 0.

 

I'm probably missing something simple and obvious so any help is appreciated!

Edited by Struckur
Link to comment
Share on other sites

FindAllReferencesOfType can target a formlist, so you could load all the statics you want to detect into one of those...

Yep the only hesitation I have there is I'm hoping to find all statics, including those added by other mods, so potentially statics that I can't know the type of ahead of time.

 

Essentially I'm working on a copy/paste mod that records all the objects in a given area when the player hits the copy activator and creates a new copy of all those objects when the player hits the paste activator. (This is already working in a primitive form) But I haven't been able to get the copy script to detect everything the player could have built in the area.

 

Simplified Example:

Scriptname ClipboardCopyPylonScript extends ObjectReference Const

Form Property	 TYPETOFIND Auto Const
ClipboardQuest Property CLIPBOARD_QUEST Auto Const

Event OnActivate(ObjectReference akActionRef)
	CLIPBOARD_QUEST.Clear()
	ObjectReference[] objs = Self.FindAllReferencesOfType(TYPETOFIND, 5000.0)
	CLIPBOARD_QUEST.Copy(objs, Self)
EndEvent
Scriptname ClipboardPastePylonScript extends ObjectReference Const

ClipboardQuest Property CLIPBOARD_QUEST Auto Const

Event OnActivate(ObjectReference akActionRef)
	CLIPBOARD_QUEST.Paste(Self)
EndEvent
Scriptname ClipboardQuest extends Quest

int[] CLIPBOARD_OBJECT
float[] CLIPBOARD_POS_X
float[] CLIPBOARD_POS_Y
float[] CLIPBOARD_POS_Z
float[] CLIPBOARD_SCALE
float[] CLIPBOARD_ANGLE_X
float[] CLIPBOARD_ANGLE_Y
float[] CLIPBOARD_ANGLE_Z
int clipboardIndex

Function Clear()
	clipboardIndex = 0
EndFunction

Function Copy(ObjectReference[] objs, ObjectReference baseObj)
	float sin = Math.sin(baseObj.GetAngleZ())
	float cos = Math.cos(baseObj.GetAngleZ())

	int i = 0
	While (i < objs.length)
		CLIPBOARD_OBJECT[clipboardIndex] = objs[i].GetBaseObject().GetFormID()
		CLIPBOARD_SCALE[clipboardIndex] = objs[i].GetScale()
		
		CLIPBOARD_ANGLE_X[clipboardIndex] = objs[i].GetAngleX()
		CLIPBOARD_ANGLE_Y[clipboardIndex] = objs[i].GetAngleY()
		CLIPBOARD_ANGLE_Z[clipboardIndex] = objs[i].GetAngleZ() - baseObj.GetAngleZ()
		
		float relativeX = objs[i].X - baseObj.X 
		float relativeY = objs[i].Y - baseObj.Y 
		CLIPBOARD_POS_X[clipboardIndex] = relativeX * cos - relativeY * sin
		CLIPBOARD_POS_Y[clipboardIndex] = relativeY * cos + relativeX * sin
		CLIPBOARD_POS_Z[clipboardIndex] = objs[i].Z - baseObj.Z
		
		clipboardIndex += 1
		i += 1
	EndWhile
	
	Debug.MessageBox("Copied " + i + " Item(s).")
EndFunction

Function Paste(ObjectReference baseObj)
	float sin = Math.sin(-baseObj.GetAngleZ())
	float cos = Math.cos(-baseObj.GetAngleZ())
	
	int i = 0
	While (i < clipboardIndex)
		Form objForm = Game.GetForm(CLIPBOARD_OBJECT[i])
		ObjectReference newObj = baseObj.PlaceAtMe(objForm)
		
		float relativeX = CLIPBOARD_POS_X[i] * cos - CLIPBOARD_POS_Y[i] * sin
		float relativeY = CLIPBOARD_POS_Y[i] * cos + CLIPBOARD_POS_X[i] * sin
		newObj.MoveTo(baseObj, relativeX, relativeY, CLIPBOARD_POS_Z[i])
		newObj.SetScale(CLIPBOARD_SCALE[i])
		newObj.SetAngle(CLIPBOARD_ANGLE_X[i], CLIPBOARD_ANGLE_Y[i], CLIPBOARD_ANGLE_Z[i] + baseObj.GetAngleZ())
		i += 1
	EndWhile
	Debug.MessageBox("Pasted " + i + " Item(s).")
EndFunction

Event OnInit()
	CLIPBOARD_OBJECT = new int[128]
	CLIPBOARD_POS_X = new float[128]
	CLIPBOARD_POS_Y = new float[128]
	CLIPBOARD_POS_Z = new float[128]
	CLIPBOARD_SCALE = new float[128]
	CLIPBOARD_ANGLE_X = new float[128]
	CLIPBOARD_ANGLE_Y = new float[128]
	CLIPBOARD_ANGLE_Z = new float[128]
	clipboardIndex = 0
	Debug.MessageBox("Clipboard Quest Initialized")
EndEvent
Edited by Struckur
Link to comment
Share on other sites

  • Recently Browsing   0 members

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