Jump to content

Make NPC equip item on cell load. Help please.


antstubell

Recommended Posts

So as title says I want a NPC to equip an item when player enters cell, in this case it is a torch. I'm in two minds whether to use OnCellAttach or OnCellLoad - not sure what it better or proper.

I placed this script on the actor then realised I couldn't select the sctor as a property if the script is running on that actor.

 

Actor Property MyActor01 Auto
Light Property MyLight Auto

Event OnCellAttach()

MyActor01.EquipItem(MyLight)

EndEvent

 

As a shot in the dark I tried...

 

Light Property MyLight Auto

Event OnCellAttach()

Self.EquipItem(MyLight)

EndEvent

 

Didn't work as expected.

So help with this please.

Link to comment
Share on other sites

One option:

Place a small trigger volume box around the spot that the player enters the cell (either in the same cell or the cell before it). Then add a script on the trigger. Depending upon which side of the cell line / door you place the trigger you would use OnTriggerEnter or OnTriggerLeave to have the NPC equip the item. Note that if the NPC is in view of this location the player may see the item being equipped. If not needed to run on every entrance, use states, bools or other conditions to limit when it takes place.

 

 

*******************************

If you still want to try running a script on the actor, instead of using a property for the actor, you can use the Self variable instead.

 

 

Light Property MyLight Auto

Event OnCellAttach()
  (Self as Actor).EquipItem(MyLight)
EndEvent

You may wish to use a location check just in case you use the actor in different locations. Also if this is on a reference alias, it would need to be: (Self.GetReference() as Actor)

 

 

 

 

Regarding OnLoad vs OnCellAttach...

OnLoad will only run when a cell is first loaded into memory. The player must stay away from the area long enough for the game to fully reset the cell before it can be triggered again.

OnCellAttach will run whenever that cell is attached to the cell that the player is in. For small single cell interiors it is usually the same cell. For multi-cell locations, typically the exterior world spaces, it is when the cell is attached as defined by the uGrid settings.

Link to comment
Share on other sites

Very helpful, thank you.

 

Oops. Won't compile on actor. I think it is because the script is an object reference, I could be wrong.

 

Scriptname SMTonCellAttachActorEquipItem extends ObjectReference

Light Property MyLight Auto

Event OnCellAttach()
(Self as Actor).EquipItem(MyLight)
EndEvent

 

 

cannot cast a smtoncellattachactorequipitem to a actor, types are incompatible

Edited by antstubell
Link to comment
Share on other sites

Longshot... since technically Self is the script rather than the object. Try:

 

((Self as ObjectReference) as Actor).EquipItem(MyLight)

 

This should cast the script into the object reference of the object holding the script and then cast that into actor.

Link to comment
Share on other sites

It compiles and kind of works. The NPC - Falmer - has nothing to do, is friendly, cell has no navmesh, he is just for testing purposes. Only thing he has in inventory is torch01 so he just stands/crouches where I placed him. On coc into cell he equips torch for a second then unequips it. Moderate success I'd say.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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