inawe Posted January 27, 2017 Share Posted January 27, 2017 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 More sharing options...
kitcat81 Posted January 27, 2017 Share Posted January 27, 2017 Normally variables do not reset themselves so it should not run more than once. OnLoad will fire when player visits some locations that were unloaded. Not sure if this is what you want. You can try to use Event OnInit. Link to comment Share on other sites More sharing options...
inawe Posted January 28, 2017 Author Share Posted January 28, 2017 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 More sharing options...
inawe Posted January 28, 2017 Author Share Posted January 28, 2017 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 More sharing options...
kitcat81 Posted January 28, 2017 Share Posted January 28, 2017 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 More sharing options...
steve40 Posted January 30, 2017 Share Posted January 30, 2017 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 More sharing options...
inawe Posted January 30, 2017 Author Share Posted January 30, 2017 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. Link to comment Share on other sites More sharing options...
steve40 Posted January 31, 2017 Share Posted January 31, 2017 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 More sharing options...
MadGodMods Posted January 31, 2017 Share Posted January 31, 2017 (edited) 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 January 31, 2017 by MadGodSheogorath Link to comment Share on other sites More sharing options...
steve40 Posted February 1, 2017 Share Posted February 1, 2017 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 More sharing options...
Recommended Posts