Kapteyn Posted October 1, 2017 Share Posted October 1, 2017 (edited) I'm running a script on a misc item, which works fine... until the thing is inside a wardrobe for example. So how do I check if it's contained? Bearing in mind it's not a typical object reference, it's a misc item. Ugh... Once an object has been added to a container it is no longer valid to call functions on it. Functions on self will fail to run with an error. That's wonderful. If anybody knows a workaround, please let me know. Edited October 1, 2017 by Kapteyn Link to comment Share on other sites More sharing options...
cdcooley Posted October 1, 2017 Share Posted October 1, 2017 It all depends on what you're really trying to do. The easiest way for us to help is if you post your script and describe what you want to happen that isn't happening. Link to comment Share on other sites More sharing options...
Kapteyn Posted October 1, 2017 Author Share Posted October 1, 2017 I'm attaching a script to junk which can create a spawn. So I walk into a fort, and plates and bowls and pots and pans... spawn bandits. The problem with this is the junk in wardrobes and chests will be targetted, but because they're in a container they cannot be manipulated so Papyrus will throw an error... lots and lots of errors for that matter. Basically, I don't think it's possible to check if something is in a container in the strictest sense. However, it has just occurred to me that if I use onLoad or onCellAttach, that event will never occur if the item is in a container... so I can check for a bool, if it's false because the event didn't occur then I know it's in a container (we know it exists because it called the script). I actually don't need to do this because if it's in a container then I don't care about it, I just don't want the errors... so onLoad works perfectly for what I'm trying to do. Link to comment Share on other sites More sharing options...
foamyesque Posted October 1, 2017 Share Posted October 1, 2017 I'm attaching a script to junk which can create a spawn. So I walk into a fort, and plates and bowls and pots and pans... spawn bandits. That seems like an odd way to go about it. Why not use triggers? Link to comment Share on other sites More sharing options...
Kapteyn Posted October 1, 2017 Author Share Posted October 1, 2017 If you could briefly explain to me how triggers are used, I could see if it's more appropriate. :) Wait, do you mean cell triggers? So I walk into a cell and an event is triggered? I was thinking of traps at first, that's probably not what you mean... Link to comment Share on other sites More sharing options...
foamyesque Posted October 1, 2017 Share Posted October 1, 2017 (edited) If you could briefly explain to me how triggers are used, I could see if it's more appropriate. :smile: Wait, do you mean cell triggers? So I walk into a cell and an event is triggered? I was thinking of traps at first, that's probably not what you mean... Triggers are a subclass of activators. They're effectively invisible bounding boxes that can react to things entering or leaving them (among other things), and are used extensively to power things like dialogue scenes, flavour comments from followers, quest stage changes, and so on. Placing them in cells is a bit more complicated than ordinary objects, but there are tutorials out there, and they're more or less the perfect tool for 'I want to spawn a bunch of dudes when the player enters this area'. Another option would be to add simple Xmarkers with some OnCellAttach scripting or similar, but triggers give you much more precise controls. Edited October 1, 2017 by foamyesque Link to comment Share on other sites More sharing options...
Kapteyn Posted October 1, 2017 Author Share Posted October 1, 2017 Okay, I think I get it. I probably don't need to use a trigger, I just want a script to occur when a relevant object is rendered. So if I walk into a fort, a kettle half way across it could spawn stuff. One thing I don't want is for bandits to spawn literally on top of the player, I hate that - I normally don't like to see the spawn happen, the feeling of an ambush is much more immersive. The concept of triggers is interesting though; I could potentially create an explosion and then there are bandits surrounding me, which would pretty much give the feeling of an actual ambush. That is, if I'm understanding triggers properly. Also, another thing I need to be careful of is that the junk doesn't keep on spawning stuff. Normally I use onInit so it only happens once, but that's where I have the problem with things being in containers. Link to comment Share on other sites More sharing options...
foamyesque Posted October 1, 2017 Share Posted October 1, 2017 (edited) Triggers don't need to do things within them, necessarily. Suppose you have a trigger you want to spawn bandits, but somewhere other than directly at the player. What you'd do is: 1. Place your trigger somewhere the player is likely to enter. This can be the entire cell, if necessary.2. Add an XMarker where you would like your bandits to spawn.3. Attach a script to the trigger like so: Actor Property PlayerRef Auto ActorBase Property BanditActor01 Auto ObjectReference Property SpawnMarker Auto State Waiting Event OnTriggerEnter(ObjectReference akActionRef) if akActionRef == PlayerRef SpawnMarker.PlaceActorAtMe(BanditActor01) GotoState("Done") endif EndEvent EndState State Done EndState This setup gives you the most possible control over when and where your bandits will spawn in. Edited October 1, 2017 by foamyesque Link to comment Share on other sites More sharing options...
Kapteyn Posted October 1, 2017 Author Share Posted October 1, 2017 (edited) Yes but this marker needs to be actually placed in the world, right? Edited October 1, 2017 by Kapteyn Link to comment Share on other sites More sharing options...
foamyesque Posted October 1, 2017 Share Posted October 1, 2017 Yes but this marker needs to be actually placed in the world, right? Yes, as does the triggerref, but it's a much less invasive thing than trying to attach a script to a common base object. Adding markers is pretty much the least likely thing to cause conflicts you can possibly do. Link to comment Share on other sites More sharing options...
Recommended Posts