Jump to content

Need a little script help


DaemonGrin

Recommended Posts

Wanting to create a script that causes an npc to flee when the player and only the player gets near. I don't want it to flee out of the cell just run until the set distance is met. I know I need to use the getDistance player and forceflee. The getDistance is pretty easy to figure out but forceflee not sure. I looked at the BlackBirdSinging script and there is a lot of stuff I dont need in it but can't quite see how to modify it for my needs.

 

Thanks,

Geoff

 

 

Link to comment
Share on other sites

EDIT:

 

Nevermind, I just realised that I misread your post. Ignore this, I didn't notice that you had a specific NPC in mind, which renders this completely moot! :D

 

To start with, you'll need to find the reference you want to flee, the easiest way to do this is ref-walking. As I understand it, ref-walking scans a set area for references that are of a specific type. To do this you'll need the functions GetFirstRef and GetNextRef. These functions perform the actual scanning function and allow you to find the objects you want to do stuff with.

 

The second part of Ref-walking is a loop, so that you can affect more than one object. Loops are pretty simple, and their function is pretty self-explanatory. To use a loop you need the functions Label and GoTo.

 

So, when put together, you can do something like:

Scn ExampleScript
 
ref rScannedActor
 
begin GameMode
 
set rScannedActor to GetFirstRef 200 1 0 ; This will scan for any actor in one cell.
Label 1
     if rScannedActor ; This checks to see if there's anything still to scan.
        rScannedActor.ForceFlee ; This makes the actor you've found flee.
        set rScannedActor to Pencil01 ; This prevents a bug where the variable will not correctly update.
        set rScannedActor to GetNextRef ; This scans the nest actor
        GoTo 1 ; This resets the loop so that you can scan more than one actor.
    endif
end

This is set up for a quest script. If you have it constantly running everyone will flee from the player, assuming that "ForceFlee" works. I can't say that I've ever had any experience with it myself, but I imagine that it would do what you think it should.

 

I hope this helps! Good luck! :smile:

Edited by Jojash
Link to comment
Share on other sites

well would something like this work

 

Begin GameMode

if player getDistance <= 512

npc.forceflee

else

playidle whatevertheanimis

endif

end

 

would that get the desired effect?

Link to comment
Share on other sites

tried it but the script wouldn't save so something was wrong in the coding lol. trying the AI Package in a sec.

 

EDIT: Well the AI Package Flee doesn't work just keeps running, I had to hit it to initiate the flee. So think a custom script is the way to go. I know I can use the getDistance function with player. But my scripting skills are still very basic.

Edited by DaemonGrin
Link to comment
Share on other sites

Is that the exact script that you used? If it is, you need to give it a name first. :P

 

Just add in "Scn" and then whatever you want the script to be called and it'll save. Let me know what happens after that. :smile:

 

Also, what are you attaching it to?

Edited by Jojash
Link to comment
Share on other sites

No thats just the action, I give it the scn lol. I'm attaching it to a custom creature Walking Eye for a side quest in a mod I am building gotta catch all the walking eyes. To add a little sport to it I just want them to run away when the player gets near.

Link to comment
Share on other sites

Alright, then. When a script fails to save, it's usually just a syntax error, so you've probably either mistyped something or you're calling a function incorrectly. It could also be to do with how you're finding the NPC. May I see the script in question? It's kind of hard to help with it if I can't see it. :smile:

Edited by Jojash
Link to comment
Share on other sites

Its set up with a defaultsandbox256 AI Package and currently the script is open with just

 

scn VRFleeEyeScript
Begin GameMode
if player getDistance <= 256
VRCrWalkingEye.forceflee
endif
end
I've also made an eye a reference with
scn VRFleeEyeScript
ref VRWalkingEye01
Begin GameMode
if player getDistance <= 256
VRWalkingEye01.forceflee
endif
end

 

but neither save.

Edited by DaemonGrin
Link to comment
Share on other sites

  • Recently Browsing   0 members

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