Jump to content

Actor scripting questions


inawe

Recommended Posts

I would like to make a mod that randomizes the hair that spawned NPCs have. I have a few questions on how to make it work.

 

The script will be attached to the NPC in the CK. Here is the basic version that I have so far, minus the randomization:

ScriptName ChangeMyHeadParts extends Actor Hidden

bool CMHPAlreadyRan = false

Event OnLoad()
	if CMHPAlreadyRan = false
		Self.ChangeHeadPart(HairMale13)
		CMHPAlreadyRan = true
	endif
endEvent

My first question is, does the variable I am declaring get reset every time the script runs, or is the value retained? I only want the hair to be changed when the NPC is first spawned, not every time the game or their cell is loaded. There doesn't seem to be a "RunOnceAfterSpawning" event, or something like that.

 

Is OnLoad the very first event that will trigger on an actor, or is there another event that triggers before the actor's 3D is loaded?

 

Is "Self." the correct way to refer to the actor that the script is attached to?

 

Thanks in advance for any guidance.

Link to comment
Share on other sites

After some more digging, it looks like "Self" is a reference to the script itself, not the actor it is attached to. So how do I refer to the actor that the script is attached to if I don't know that in advance due to it being a spawned instance?

 

For the specific thing I am trying to do I will be working with spawned NPCs, so I need to be able to refer to the particular instance of a base actor, not the base actor itself. For example, lets say I attach a script to a leveled raider. If I'm understanding how things work correctly, when the cell that the raider is placed in is loaded for the first time, a new instance of that base raider is created. Events like OnLoad and OnInit don't pass in a property, so I won't receive a pointer to the actor instance from them. All the functions require that you already know what you want them to act on as far as I can tell, so I can't get the pointer from one of them.

 

Hopefully I am just misunderstanding or missing something obvious here.

 

Thanks again for any help.

Link to comment
Share on other sites

OK, strike that last bit. It looks like Self does refer to the actor or item the script is attached to. Confusing since Google found me one reference that says it points to the script and now another couple that say it points to the object. I guess I'll find out for sure when I try out the script.

Link to comment
Share on other sites

OK, strike that last bit. It looks like Self does refer to the actor or item the script is attached to. Confusing since Google found me one reference that says it points to the script and now another couple that say it points to the object. I guess I'll find out for sure when I try out the script.

"Self" can refer to both. The object that has the script and the script itself. In some cases you have to clarify it like this : (Self as ObjectReference) , (Self as Actor) , (SomeObject as Scriptname (your script name)), etc. For example If you use a function that is only valid for actors on an object that was defined as something else , you`d type it like this :

(MyObject as Actor).DoSomething, otherwise the compiler will moan about incompatible types. In some other cases you`d have to set a pause in your script or to check if 3d is loaded. Some functions won`t work on unloaded actors. You need to look at some existing scripts . Look at workshopnpcscript , it has many useful examples.

Link to comment
Share on other sites

 

ScriptName ChangeMyHeadParts extends Actor Hidden

bool CMHPAlreadyRan = false

Event OnLoad()
	if CMHPAlreadyRan = false
		Self.ChangeHeadPart(HairMale13)
		CMHPAlreadyRan = true
	endif
endEvent

 

You made a small boo boo...

 

	if CMHPAlreadyRan == false
btw, "Self" is redundant.
Link to comment
Share on other sites

 

 

btw, "Self" is redundant.

 

Do you mean that if you call a function without a reference before it, Self is assumed? So, "Self.ChangeHeadPart(HairMale13)" and "ChangeHeadPart(HairMale13)" are the same?

 

Thanks.

 

Yep.

Link to comment
Share on other sites

If I remember correctly the OnLoad event is only called on the player character. If this script is attached to another actor or NPC it may not work. An alternative event to use is OnInit.

Edited by MadGodSheogorath
Link to comment
Share on other sites

If I remember correctly the OnLoad event is only called on the player character. If this script is attached to another actor or NPC it may not work. An alternative event to use is OnInit.

 

Incorrect. OnLoad is called on all ObjectReferences i.e. basically anything that can have a 3D model in-game.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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