Teleport Companion to player script help.

Post » Sun Aug 08, 2010 10:07 pm

I'm just fooling around with the construction set and I made a custom companion to follow my character around.
I was able to get the companion to switch between following and waiting, but my fear is I might get too far ahead of him and he'd disappear.

Would anyone be able to help me out with writing a script that would teleport him to right behind me if he gets too far behind?
I'd appreciate any tips. :laugh:
User avatar
Yung Prince
 
Posts: 3373
Joined: Thu Oct 11, 2007 10:45 pm

Post » Sun Aug 08, 2010 12:39 pm

I did exactly that for my Campaign mod "The Lady Said No".

I developed a bunch of tricks like uber speed spells to make her run faster, warping behind the player when too far away and out of LOS as well as AI to stop her from running off to do things like fight when a creature put her into combat but could not reach her such as over a pony wall.

It is actually not a simple thing, so would you consider instead a spell that moves your companion to you instead?
You would cast it to transport your companion to you.

If not then download my mod "follow that actor" form Tes Alliance and use some of the code in that for your companion. I based the script in that on my Lady Said No mod.


I'm just fooling around with the construction set and I made a custom companion to follow my character around.
I was able to get the companion to switch between following and waiting, but my fear is I might get too far ahead of him and he'd disappear.

Would anyone be able to help me out with writing a script that would teleport him to right behind me if he gets too far behind?
I'd appreciate any tips. :laugh:

User avatar
Red Sauce
 
Posts: 3431
Joined: Fri Aug 04, 2006 1:35 pm

Post » Sun Aug 08, 2010 10:12 pm

Well, I tried to write a script, but it's not entirely working. Could anyone look it over and see if they can figure out what is keeping it from functioning?
Don't laugh at me, lol. I've never written one of these. I was just trying to play around.

ScriptName aaKnightBehavior

Begin GameMode
if AAKnight.Knightfollow == 1 ;Working script result AI condition.
if "02002A2C".GetDistance Player > 100
"02002A2C".moveto Player
endif
if "02002A2C".GetInSameCell player ;If the knight is in another zone than player he will teleport to player.
else "02002A2C".moveto Player
endif
endif
end
User avatar
Sharra Llenos
 
Posts: 3399
Joined: Wed Jan 17, 2007 1:09 pm

Post » Sun Aug 08, 2010 12:27 pm

You need to use the Persistent Reference ID or Editor ID (text in the top field of the reference edit dialog for Persistent Reference IDs, or the text name of the object in the object list in the Construction Set for Editor IDs) instead of the Reference ID or Form ID (hex values of Persistent Reference IDs and Editor IDs, respectively) in scripts. Reference IDs and Form IDs are for use in the console. In this case, you need the Persistent Reference ID of the NPC you are having follow the player.

Otherwise, your script should work fine.

As a side note, 100 units is less than half the size of a basemant section, and it would be natural for a follower to be that distance from its follow target anyway. You may want to raise this value to something much higher so it won't seem like the follower is flickering due to all the teleportation it will be doing.
User avatar
emma sweeney
 
Posts: 3396
Joined: Fri Sep 22, 2006 7:02 pm

Post » Sun Aug 08, 2010 10:04 pm

You need to use the Persistent Reference ID or Editor ID (text in the top field of the reference edit dialog for Persistent Reference IDs, or the text name of the object in the object list in the Construction Set for Editor IDs) instead of the Reference ID or Form ID (hex values of Persistent Reference IDs and Editor IDs, respectively) in scripts. Reference IDs and Form IDs are for use in the console. In this case, you need the Persistent Reference ID of the NPC you are having follow the player.

Otherwise, your script should work fine.

As a side note, 100 units is less than half the size of a basemant section, and it would be natural for a follower to be that distance from its follow target anyway. You may want to raise this value to something much higher so it won't seem like the follower is flickering due to all the teleportation it will be doing.


I appreciate the input. :)
I changed up the script so it referred to him as his reference editor id (and made the range substantially longer).
For some reason it still doesn't seem to want to work.
The script attached to the quest contains "short Knightfollow" and it seemed to work well in all other parts of the editor.
The Script results in the quest window is set to change the value and it is prompting the right dialog. He follows, fights, and ignores friendly fire just fine. He just gets left behind when I travel.
The script saves just fine and doesn't tell me I got it wrong.
After the re-wiring I came out with this.
Any tips that might get it up and running?:

ScriptName aaKnightBehavior

Begin GameMode
if AAKnight.Knightfollow 1
if Knight.GetDistance Player > 500
Knight.moveto Player
endif
if Knight.GetInSameCell player
else Knight.moveto Player
endif
endif
end
User avatar
Da Missz
 
Posts: 3438
Joined: Fri Mar 30, 2007 4:42 pm

Post » Sun Aug 08, 2010 10:12 pm

I think I see the problem. If you attach the script to the Knight, it won't be processed if he's in not the same cell as the player (out of sight, out of mind), which is exactly when you need it to happen. I'd just move all that code into the quest script instead (and then you don't need the qualifier for the "Knightfollow" variable).
User avatar
saxon
 
Posts: 3376
Joined: Wed Sep 19, 2007 2:45 am

Post » Sun Aug 08, 2010 12:18 pm

I finally got it working. :celebration:
Thanks for all your help.
I'm going to post the script so anyone else who has this question can have an easier time figuring it out than I did, lol.
I'll also explain it as I understand it.
The companions's reference editor id is "knight".
I put this in the same script that specifies the quest variable which will be linked directly to the quest.
http://cs.elderscrolls.com/constwiki/index.php/Scripting_Tutorial:_My_Second_Script will help out tremendously.
Good luck, newbie modders like myself. =)


Begin GameMode ;this will continually check for the "if"
if AACompanionQuest.Knightfollow == 1 ;this is questname.questvariable which will be set using the dialog options "follow" and "wait".
if Knight.GetDistance Player > 2000 ;when the knight gets 2000 units away, it will teleport provided the "if" is met.
Knight.moveto Player
endif
if knight.GetInSameCell player ;this means the knight IS in the same cell as the player.
else knight.moveto Player ;there is no way I could figure out to say if he isn't, so there is no command if he is. So otherwise this will teleport him to you.
endif
endif
end
User avatar
Marina Leigh
 
Posts: 3339
Joined: Wed Jun 21, 2006 7:59 pm


Return to IV - Oblivion