Jump to content

How to fixate an actor to a position?


greyspammer

Recommended Posts

Hi there!

 

I am currently working on my first mod and I have a little question: Let's say there's a slave that gets punished by someone else (the player or some other NPC).

 

The slave is bound to a cross, which I did by giving it a package that says: Stay there and use idle animation ZazAPCAO025.

 

Problem is: Once the other NPC starts hitting the slave with a crop (or someone just bumps into her while walking around), the slave (and her cross) get pushed aside. Basically, the slave moves when physics are applied. And I don't want that.

 

I experimented with the Havok settings (like the no havok settle checkbox or the DefaultDisableHavokOnLoad script) but they did not seem to do anything.

 

My current solution is a bit iffy: I scripted an OnHit event that moves the actor back into position. It kind of works. But you can still see that she moves away a bit first and then is positioned back. Also, I have to put her in her own little navmesh so no one can bump into her.

 

So I was wondering if there was a more elegant way to nail an NPC down. Anyone got any tips for me?

Link to comment

Thank you!

 

That was helpful. In case anyone else is having this problem: At first I tried it with a script attached to the actor in the CK (which extends ObjectReference):

Scriptname tir_SlaveCross01_scr extends ObjectReference
 
Event OnLoad()
  Actor a = (GetBaseObject() as Actor)
  a.SetRestrained()  ; won't work
  a.SetDontMove()    ; won't work
EndEvent

But this did not work. Nor did the same code in OnCellAttach. The actor was still moving. Not sure why.

 

But now I made it a magic effect:

Scriptname tir_SlaveEffect_scr extends activemagiceffect

Event OnEffectStart(Actor akTarget, Actor akCaster)
  akTarget.SetRestrained()   ; this will!
  akTarget.SetDontMove()     ; this will!
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
  akTarget.SetRestrained(false)
  akTarget.SetDontMove(false)
EndEvent

And I gave this as spell (ability) to the NPC in the CK. And that works without a hitch!

 

So thanks again!

Link to comment

I think I know now why my first attempt (with the script directly attached to the actor) failed.

 

Let's say you have an actor (NPC) named Joe. Then his script goes like:

Scriptname JoeScript extends ObjectReference

So, JoeScript is a child of ObjectReference. As is Actor. Both are siblings. And the compiler cannot cast between siblings. So the statement:

(Self as Actor).SomeActorFunction()  ; compiler error when Self is a JoeScript

will cause a compiler error.

 

I had this and at the time, didn't understand why. So I called the actor function on GetBaseObject(), which was completely stupid of me. At least if you want to call it on the NPC instance in the game.

 

Instead, you would have to make two casts. One to up to the parent and then another down again to the sibling. Like this:

ObjectReference r = Self as ObjectReference  ; Cast self (a JoeScript) to ObjectReference
Actor a = r as Actor                         ; Cast reference to Actor
a.SomeActorFunction()                        ; Should work

I did not try it with the slaves, as I have solved that already. And I think the magic effect is a better solution for that anyway, because it can be applied dynamically during the game, should need be.

 

But I tried it with something else where I had the same problem and finally figured out what I was doing wrong. So I'd like to publically document it in case someone else might stumble at that point as well.

 

 

Or, the more elegant way: When you already have an Actor, then you can derive your own script from that. So if the CK gives you

Scriptname JoeScript extends ObjectReference

you can safely change that to

Scriptname JoeScript extends Actor

and then just say:

Self.SomeActorFunction() ; Will work
SomeActorFunction()      ; As will this, the "self." is redundant

Just for the sake of completeness.

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use