pvyarashevich Posted March 13, 2018 Share Posted March 13, 2018 My task is to get reference to all objects and their positions of player's current location. I am planing to restore location with extracted models from *.bsas files. I am trying to use papyrus for this. I created activation tomb according to the bethesda's script manual. And use next script their (Which is using some functions from SKSE). ScriptName Script'sTheMostPerfectName extends ObjectReferenceEvent OnActivate(ObjectReference akActionRef) ; We get player, his location, cell he standing Actor player = Game.getPlayer() Location playerLocation = player.getCurrentLocation() Cell pCell = player.getParentCell() ; We find number of all elements (zero argument is for all types of elements) in current player's cell. int number = pCell.getNumRefs(0) ObjectReference[] objectReferencesList = new ObjectReference[100] int index = 0 ; Then we store all elements into array while (index < number) objectReferencesList[index] = pCell.GetNthRef(index, 0) index = index + 1 endwhile index = 0 ; And output information about each element in location while (index < number) ObjectReference obj = objectReferencesList[index] float x = obj.getPositionX() float y = obj.getPositionY() float z = obj.getPositionZ() float ax = obj.getAngleX() float ay = obj.getAngleY() float az = obj.getAngleZ() Debug.Trace("Object, with number " + index + ", \"" + obj.getBaseObject()+ "\", with name \"" + obj.getName() + "\" has position[" + x + ", " + y + ", " + z + "] and angle (" + ax + ", " + ay + ", " + az + ")", 2) index = index + 1 endwhileendEventScript's output: [03/12/2018 - 03:57:03AM] Object, with number 0, "[Form < (0001305B)>]", with name "" has position[-556.590515, -316.995544, 63.999969] and angle (0.000000, -0.000000, 180.000000) ..... (and the same thing printed 10 times more)According to the output, I get that obj.getBaseObject() - return object type and referece to this type's ID (So we get the FormID but I don't find the way to get EditorID (names object's knows in 'Object Window'), and the path to the element 3D model); obj.getName() - return only name of objects which are hightlights in the game; (x, y, z) - are the same for all elements (Does it means that I get position of this object's cell? Does I need more number after floating point to get correct location?); (ax, ay, az) - is the correct angles. So we get 11 elements total: 8 for room (only 2 FormID with different angles), 1 for Molag Bal, 1 for tomb, and 1 for player.PS: This question is about papurus's script, creation kit, Skyrim. Sorry for spoiler. Am I using \" 's \" properly?Am I using the right tool for my task? I had find the way to get all elements in location. Did I do it right? Will I face problems in future because I get elements of players current cell? How to get the file path to the element's model? How to get the exact position in current location of each element?Yeah I have a lot of questions, but any useful answer for any of this can help me to move forward. Link to comment Share on other sites More sharing options...
greyday01 Posted March 13, 2018 Share Posted March 13, 2018 does anyone know what variable positions the "you are here" marker on the map? Link to comment Share on other sites More sharing options...
Evangela Posted March 14, 2018 Share Posted March 14, 2018 (edited) This is very very slow, and it will be even slower the more references are in the cell. In any case, I made a variation of what you want. I didn't test these in a cell with name references though(statics for world building, except for say.. Doors, which is also pulled by this function, do not have names) Function PrintPositionsForAllReferences() Cell playerCell = Game.GetPlayer().GetParentCell() Int cellRefs = playerCell.GetNumRefs(0) ; Array stuff ObjectReference[] cellObjs = new ObjectReference[100] Int i = 0 ; A cell will undoutably have more than 100 references, so we need ; to restrict the search to 100 to fit the array. if cellRefs > 100 cellRefs = cellRefs - (cellRefs - 100) endif ; Fill the array with references that don\'t have a name. while i < cellRefs ObjectReference objsFound = playerCell.GetNthRef(i, 0) Int objFormID = objsFound.GetBaseObject().GetFormID() Float PosX = objsFound.GetPositionX() Float PosY = objsFound.GetPositionY() Float PosZ = objsFound.GetPositionZ() Float angleX = objsFound.GetAngleX() Float angleY = objsFound.GetAngleY() Float angleZ = objsFound.GetAngleZ() if objsFound.GetName() == "" cellObjs[i] = objsFound debug.trace("Object ID " +objFormID+ " X pos: " +PosX+ " Y pos: " +PosY+ " Z pos: " +PosZ+ \ " || Angle X: " +angleX+ " Angle Y: " +angleY+ " Angle Z: " +angleZ+ \ " || Coordinates: ("+(PosX / 4096) as int+", "+(PosY / 4096) as int+")") endif i += 1 endwhile debug.notification("Done") EndFunction I wish it were possible to declare all those variables and assign them outside of the loop. Would have made it much faster and efficient. But you can't. I tossed in an extra for you that displays coordinates. Some results: [03/14/2018 - 11:38:03AM] Object ID 1101921 X pos: 314.718262 Y pos: -60426.410156 Z pos: 670.233948 || Angle X: 5.810819 Angle Y: 17.174225 Angle Z: 175.051361 || Coordinates: (0, -14) [03/14/2018 - 11:38:04AM] Object ID 704822 X pos: 3823.456055 Y pos: -59099.441406 Z pos: 1710.815796 || Angle X: 0.000000 Angle Y: 0.000000 Angle Z: 0.000000 || Coordinates: (0, -14) [03/14/2018 - 11:38:04AM] Object ID 119979 X pos: 2292.856934 Y pos: -58948.496094 Z pos: 1369.463867 || Angle X: 0.000000 Angle Y: 0.000000 Angle Z: 93.346481 || Coordinates: (0, -14)Also, it is not possible to obtain the EditorID. The name of a form is about as good as we're going to get. Edited March 14, 2018 by Rasikko Link to comment Share on other sites More sharing options...
FrankFamily Posted March 14, 2018 Share Posted March 14, 2018 (edited) Tiny thing but Isn't "cellRefs = cellRefs - (cellRefs - 100)" unnecessary math? The result is 100, why not just "cellRefs = 100" Edited March 14, 2018 by FrankFamily Link to comment Share on other sites More sharing options...
DavidJCobb Posted March 17, 2018 Share Posted March 17, 2018 The script as written wouldn't even need to limit itself to 100 objects. It stores found objects in an array (limited to 100 items), but the array is never actually used. If all you want is to print object data to the Papyrus log, then ditch the array entirely and don't cap cellRefs. Link to comment Share on other sites More sharing options...
pvyarashevich Posted March 17, 2018 Author Share Posted March 17, 2018 (edited) In my case the problem was in : float x = obj.getPositionX() I have defined x and then it became constant. When i try to multiply or divide on any value, papyrus compiler said that: "property x on script objectreference is read-only, you cannot give it a value". And on the next iteration values of x, y and z did not change. (magic) Should I use FormList for holding the objects? How can I get path to the 3D model of object based on its FormID value, without openning "creation's kit" "object window"? I mean that there is a lot of object I should get models for, and I want some auto way for it. PS: thx for respones, they were helpfull. Edited March 17, 2018 by pvyarashevich Link to comment Share on other sites More sharing options...
Recommended Posts