Jump to content

Connected objects and Scripting


Maduin81

Recommended Posts

I'm not quite that familiar with actual in-game objects yet, and I'm not quite sure where to look for what I'm asking, so I was wondering if someone might have an answer here?

 

Using Papyrus, is it possible to get the objectreference of objects snapped together, say walls or floors? I think what I'm looking for is something along the lines of HasNode()?

 

Basically, let's say I put down a piece of floor, I snap another piece of floor to the 'north' side of it, can I check specifically that 'north' side to A) see if something is attached, and B) get the object reference of that something, and bonus C) Get the node on the 2nd piece(For ease, we'll call it the 'south' side) that is connected to the first?

 

Right now, I'm thinking closest I can come is using GetClosestReferenceByType() + HasDirectLOS() but I'm not sure how well that'd work or if there might be something better?

 

Any help here would be greatly appreciated!

Link to comment
Share on other sites

I don't think there is a function for this. However as you said you can use the function getclosestreferenceoftype, or better the function with a formlist as parameter (im this flst you put all vanilla floors you want to search for). But you have to calculate the position of the attached floor using the Math.sin() and Math.cos() functions and then pass this cords to the getclosestreferenceoftype function. Otherwise you will always get the floor you started with.
Link to comment
Share on other sites

Very interesting. I'm probably no help but it occurs to me.

 

Does the function you use to ''put down a piece of floor" return a Ref to the newly place item?

 

Could you then: Fill a list of connection points from the first piece, fill a list of connection points from the newly placed piece, compare the two lists to see if any two connection points are in 'virtually' the same location?

Link to comment
Share on other sites

I can't seem to find any functions that so much as touch those connection points. I can sort of do what I need by doing FindAllReferencesOfType in an extremely small radius, removing self to get rid of the original, then comparing the heading angle from self to the others to get roughly what side they're attached to. This doesn't definitely even tell me if they are attached, only extremely close and roughly what direction. I thought HasNode would give me /some/ connection point data but either it doesn't or I'm using it incorrectly. Any help on specifically the connection points?
Link to comment
Share on other sites

FinAllReferencesOfType is probably not a nice way to do this, especially comparing the angles is more complicated than calculating the position before. The script you need for that is something like this:

Formlist property myFormlist auto const
;try which value works good. Don't make it too small, as calculations with floats aren't 100% exact
float property searchRadius auto const

float angle = self.getAngleZ() + 90.0 ;do with +0.0, +90.0, +180.0 and +270.0
float xcalc = Math.sin(angle) * 256 + getPositionX()
float ycalc = Math.cos(angle) * 256 + getPositionY()
flaot zcalc = getPositionZ() ;-224 ;(you have to go done 1 level to find staircase)
ObjectReference foundref = Game.FindClosestReferenceOfAnyTypeInList(myFormList, xcalc, ycalc, zcalc, searchRadius)
if (foundref)
    ;do something
endif
Link to comment
Share on other sites

Heya MasterMagnus, I believe OnWorkshopObjectPlaced returns this, it's just a matter of capturing that event, I think the list in that case would work just fine, however I can't come up with a way to access those connection points, unless it's a pretend list and not actual object properties.

 

DarthWayne, I really appreciate you taking the time here, though I'm having a few issues getting the example you provided to work.

 

It's been about... 17 years since I've touched sines/cosines, so if you don't mind catching me up here, I'm thinking this is what the purpose of this is...

 

I believe what's happening is that you're getting the angle of the object and using that to offset the current position to just off the side where something I'd want to search for should be. I've got the method compiling and its returning valid coordinates, that are fairly close, but don't seem to center on where I'd want. Below are the raw values for the base object, all the calculations (0/90/180/270), and the actual position of the object I'm looking for. I'm also using a search radius of 100 as its a fairly small object.

Base - Angle:315.019714| X: -79113.343750| Y: 89210.585938| Z: 7846.123535
Calc+000 Angle:315.019714| X: -79294.296875| Y: 89391.664063| Z: 7846.123535
Calc+090 Angle:405.019714| X: -78932.265625| Y: 89391.546875| Z: 7846.123535
Calc+180 Angle:495.019714| X: -78932.382813| Y: 89029.507813| Z: 7846.123535
Calc+270 Angle:585.019714| X: -79294.421875| Y: 89029.625000| Z: 7846.123535
Targ - Angle:585.019714| X: -79090.710938| Y: 89233.203125| Z: 7846.123535
Currently what I have, using the heading angle, I can get the position roughly on an x/y axis but no z, though z isn't super-important to me. I'd really like to get a working sample based on what you provided and extend on it as I think it'd be way more accurate and useful for me. Also, random question, will finding a reference work if any part of the object is in/near those coordinates or does it have to be its relative origin point?
Edit: Oh, derp, the "256" being multiplied should coincide with the actual radius of the object not a static 256. I can detect stuff now, I believe I can refine it a bit more to fit my needs, though it appears getting the actual radius of an object in script might be tricky since getwidth and all that seem to return 0 for the objects I'm testing.~
Edited by Maduin81
Link to comment
Share on other sites

So you got it working now? Anyway a search radius of 100 is already pretty huge. I would start with 4 or 8 and then slowly go bigger if it is to small. Basically the sin and cos calculation works like this: First you calculate the coords in 1 unit distance with the given angle. Then you multiply the result with the distance you want. Usually 256, as this is the size most (if not all) snapping workshop objects have. Now you have the position relative to your base object and have to add the coords, so you get the global position.

Link to comment
Share on other sites

Yep, it's working relatively well now, though I'm having troubles getting searches along the z axis to return anything. Not a major deal since all the objects should share the same z axis. I'm trying to compare this to my original method to see which is more efficient as far as getting the connected objects. Basically, I'm hopping through every item to get, say, the furthest item on the left, then return an array of all objects from left to right with left being index 0.

 

The original method would just center the search on that particular object and look in each direction for another object then do another search based on that, which is relatively accurate, but I can see scenarios where it would cause issues.

 

This one offsets the position and centers the search where the new object should be. It /should/ be more accurate, however there's a few more calculation steps going into it, so I'm kind of concerned with overhead.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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