Jump to content

moving a preexisting npc to player via script


3aq

Recommended Posts

I'm currently trying to move a follower mod which I moved to its own empty cell.

 

I attached to a ring that upon equip will fire a moveto script moving said follower to the player.

 

the script works, as in everything is referenced yet the line for moveto isn't being performed accurately. I am thus stumped on what is causing this problem.

 

here's the script

scriptName _MovetoPlayerOnEquip extends ObjectReference
{script moves follower to Player on equip}

actor property aaaaFollower auto
actor property PlayerRef auto

function onEquipped(actor akActor)
	if (akActor == PlayerRef)
		debug.notification("AFTER TEN THOUSAND YEARS, I AM FREE! ITS TIME TO CONQUER EARTH!")
		aaaaFollower.MoveTo(PlayerRef)
		aaaaFollower.SetAngle(0.0,0.0,0.0)
	elseIf (akActor != PlayerRef)
		Return
	endIf
endFunction

I am unsure if the problem is stemming from the cell that the NPC resides in as it's literally a new cell with the follower's name, or it's due to improper procedures during referencing (I attached the script to the ring which references the follower's refID, or both. Help is deeply appreciated. Thank you.

Edited by 3aq
Link to comment
Share on other sites

Change "function" to "Event" and "endFunction" to "EndEvent" then it should work. Function by itself does nothing unless something calls it and unless you have another script referencing it which you havn't mentioned it'll carry on doing nothing. The OnEquipped - ObjectReference event is called everytime the object is equipped so that will fire.

 

n.b. the "elseIf" and subsequent "return" is redundant as you've already checked to see if akActor is the player (you don't need SetAngle() either as that will be done automatically.) Don't forget to fill the two actor properties too.

 

n.n.b. on reflection you didn't get that from decompiling a .pex by any chance? Because it often adds "Function" instead of "Event". You need to be looking at original source files if you're trying to learn something (decompiled scripts are useful if no source is available but need to be interpreted as they often contain mistakes)

Edited by soupdragon1234
Link to comment
Share on other sites

Appreciate the the response, I will be sure to implementing those changes when time permits.

 

the function/event thing and the nnb I've simply reused scripts that I got functioning previously. The structure of the script worked in another mod script which I applied onto this test script. I figured it may work just the same, unfortunately .. you may be right on the labeling of event.

 

for the set angle, apologies I put that there in order to avoid wiki's "MoveTo doesn't take uneven terrain into account."

Link to comment
Share on other sites

  • 2 weeks later...

Late update:

 

I figured out the reason for my issue and embarrassingly it was because I was referencing Base ID rather than Reference ID.

 

On separate note, I've also did test with both function and event and noted that both works, though for sake of following convention I've opted and used event.

 

I would once more thank soupdragon1234 for the help, appreciations!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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