Jason210 Posted August 11, 2015 Share Posted August 11, 2015 (edited) Hi I need to check whether a reference is present in any potential interior. Since every interior is a cell with a limited number of references, I would imagine that checking to see if a specific reference is present in that interior cell would be quite simple; yet I have not found a way to do it. I can't even find a function that will return the name of the cell I'm in. Is there a way to do these things without resorting to MWSE? RegardsJason Edited August 11, 2015 by Jason210 Link to comment Share on other sites More sharing options...
hollaajith Posted August 11, 2015 Share Posted August 11, 2015 Since morrowind cannot return 'strings', returning cell name is out of the question. You need to figure out another way or use MWSE. Link to comment Share on other sites More sharing options...
Jason210 Posted August 11, 2015 Author Share Posted August 11, 2015 (edited) Thanks. All I need is to check whether a reference is present in the current interior cell. I am frustratingly close to a solution. At first GetDistance looked promising, but it only looks for the first reference used, rather than the one in the current cell. Interestingly, if that first reference is not in the current cell, then it returns a value of 340282346638528860000000000000000000000, which you can then check against. If the reference is unique this is a way to test if its in the same interior. But alas, in my mod the references I need to check aren't unique. Edited August 11, 2015 by Jason210 Link to comment Share on other sites More sharing options...
Daemonjax Posted August 12, 2015 Share Posted August 12, 2015 (edited) I need to check whether a reference is present in any potential interior. There's no good way to do it without using mwse. Well... on second thought... If the reference in question is non-unique, that's fine... you can have a targetted global script use the getdistance function with the player as the target (because the player IS unique)... if it returns a very large number (like greater than 10000) , then you know it's not in the current cell. int curDist set curDist to ( GetDistance, Player ) if ( curDist < 10000 ) ;PC is effectively in same cell endif Unless you have some other reason for using a targeted global script, I would try to do it all with just a local script, though... they only run when the player is in the same cell, so that may be good enough in and of itself. Alternatively, if you need to know when the player leaves the cell the object is in, then you'll need to use a targeted global script (which can stop itself shortly afterwards). If you end up needing to directly compare an arbitrary number of cell names or do anything much fancier than the above, then you're going to end up using mwse functions (xPCCellID, and possibly xStringcompare). Some MWSE function are buggy, some aren't... these aren't. Edited August 12, 2015 by Daemonjax Link to comment Share on other sites More sharing options...
Jason210 Posted August 12, 2015 Author Share Posted August 12, 2015 Hi Thanks for the reply. So are you saying that it is possible to attach a script to the reference, which targets the player? RegardsJason Link to comment Share on other sites More sharing options...
Daemonjax Posted August 12, 2015 Share Posted August 12, 2015 (edited) Hi Thanks for the reply. So are you saying that it is possible to attach a script to the reference, which targets the player? RegardsJason You can do that, but I'm not sure you'd want to. What I'm really saying is that you can have getdistance target the player. Since player is a unique reference, you won't run into the problem where it grabs the first reference of your non-unique object. "At first GetDistance looked promising, but it only looks for the first reference used, rather than the one in the current cell." You were on the right track, it just sounds like you were trying to do something like this: Player->GetDistance "<object_ID>" ... is bad if your object is non-unique, as you found out. GetDistance, Player ... is good if your object is non-unique, but requires being run from a local script on the object or from a global script targeting the object (started from either a local script or dialogue result). If you're a using targeted global script, then you'll need to be aware of their limitations (especially to prevent CTDs). Without knowing the full details of what you're trying to do, it's hard to say much more. Also... GetDistance Limitations from Morrowind Scripting for Dummies 9.0: • GetDistance requires that the object given as parameter is placed in the gameworld (inthe editor) and has references persist checked (or is naturally persistent such as anNPC).• Note that you should use this function only with unique ID's or in environments whereyou exactly know that there is only one instance of the ID – otherwise the Gameengine will just grab the first instance of the ID it finds and report that distance – mostlikely not the distance to the object you want. Thus, a script that warns the player ofthe presence of a slaughterfish that is closer than 800 units would have to be attachedto the ID of the slaughterfish, and check the distance to "player" (which is unique), notvice versa.• If you determine distance to an object you are moving with Move or MoveWorld,GetDistance will still report the distance to the original location of the object (theone you set in the editor). Use GetPos and good ol' Pythagoras (c2 = a2 + b2) todetermine distances in these instances.• GetDistance won't work on disabled objects. Edited August 12, 2015 by Daemonjax Link to comment Share on other sites More sharing options...
Jason210 Posted August 14, 2015 Author Share Posted August 14, 2015 (edited) Cheers. What I was planning to do was to have an item 'A' which, when the player has in the inventory, makes another item 'B' appear in player inventory. This second object B can only be placed in interiors which do not already contain it or the ASE interior sound activator. What it does is add the interior sound to an interior that does not already have it. If you try to add 'B' twice (ie it's already there), the item is removed from the cell. Finally, removing item 'A' from the inventory removes 'B' also. So basically it is a tool to add interior ASE sound to interiors which don't have it. Everything is working apart from the logic to check if the player has already placed the item in the interior. However, it turned out to be a complicated project! Edited August 14, 2015 by Jason210 Link to comment Share on other sites More sharing options...
hollaajith Posted August 14, 2015 Share Posted August 14, 2015 You can have a global which is set to 1 using B and then you can have a global script which resets it to 0 every so often. Valid script part on 'B' Set <global> to 1 This part sets the global to 1 every frame B is present. But the global remains at 1 even after you leave the cell and enter new cell. So you can have a globalscript set as a startscript, so it runs always, like so... float timer ;resets the global to 0 as soon as you enter new cell If ( CellChanged ) Set <global> to 0 Endif ;resets the global to 0 every 2 seconds, just a pre-caution if CellChanged doesn't work ; as sometimes it doesn't Set timer to ( timer + Getsecondspassed ) If ( timer > 2 ) Set <global> to 0 Set timer to 0 Endif Now you can use that global as an indicator of whether the activator is present or not. Note that if 'B' is present in exterior, then this script on 'B' runs even you are on adjacent cell. Link to comment Share on other sites More sharing options...
Jason210 Posted August 15, 2015 Author Share Posted August 15, 2015 Thanks guys. So there a few approaches to this which seemed impossible to me. @hollaajith: B wouldn't be dropped when PC is in an exterior cell - a simple check prevents that - that was the easy part :) Link to comment Share on other sites More sharing options...
Recommended Posts