antstubell Posted July 16, 2021 Share Posted July 16, 2021 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 AutoLight Property MyLight AutoEvent OnCellAttach()MyActor01.EquipItem(MyLight)EndEvent As a shot in the dark I tried... Light Property MyLight AutoEvent OnCellAttach()Self.EquipItem(MyLight)EndEvent Didn't work as expected.So help with this please. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 16, 2021 Share Posted July 16, 2021 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 More sharing options...
antstubell Posted July 17, 2021 Author Share Posted July 17, 2021 (edited) 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 ObjectReferenceLight Property MyLight AutoEvent OnCellAttach()(Self as Actor).EquipItem(MyLight)EndEvent cannot cast a smtoncellattachactorequipitem to a actor, types are incompatible Edited July 17, 2021 by antstubell Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 17, 2021 Share Posted July 17, 2021 You just have to play around with the casting because all instanced actors are also object references. You could also try without any casting and see if EquipItem will work with Self only. Link to comment Share on other sites More sharing options...
antstubell Posted July 17, 2021 Author Share Posted July 17, 2021 Tried that, my OP shows the script. Never mind, I'll go with the triggerbox. Thanks. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 17, 2021 Share Posted July 17, 2021 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 More sharing options...
antstubell Posted July 17, 2021 Author Share Posted July 17, 2021 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 More sharing options...
IsharaMeradin Posted July 17, 2021 Share Posted July 17, 2021 You might have to set the item to not be unequipped. Which means that you have to explicitly script it to unequip when you want. Link to comment Share on other sites More sharing options...
antstubell Posted July 18, 2021 Author Share Posted July 18, 2021 Yep. ((Self as ObjectReference) as Actor).EquipItem(MyLight, true) This does it. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts