Difference between revisions of "Talk:GetPositionX - ObjectReference"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Lisselli
imported>Rasikko
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Getting Cell Coordinates ==
== Getting Cell Coordinates ==
== Getting Cell Coordinates ==
Ever wondered how you can use the [[Cell View]] window's coordinates in game? Simple. You take the two values and you multiply them by 4096.
Ever wondered how you can use the [[Cell View]] window's coordinates in game? Simple. You take the two values and you multiply them by 4096.
If you want to convert an object's in game coordinates to use in the Cell View window, you divide the X and Y values by 4096 and cast as int to remove the decimals.
If you want to convert an object's in game coordinates to use in the Cell View window, you divide the X and Y values by 4096 and cast as int to remove the decimals.
[[User:Lisselli|Lisselli]] ([[User talk:Lisselli|talk]])[[User:Lisselli|Lisselli]] ([[User talk:Lisselli|talk]]) 2017-10-06T11:57:52 (EDT)
[[User:Lisselli|Lisselli]] ([[User talk:Lisselli|talk]])[[User:Lisselli|Lisselli]] ([[User talk:Lisselli|talk]]) 2017-10-06T11:57:52 (EDT)
: As with [[Floor - Math]], casting a negative value as int has its issues. This will result in inaccurate coordinates if they are negative values, especially the y position. Testing for a way around this. [[User:Lisselli|Lisselli]] ([[User talk:Lisselli|talk]]) 2017-10-06T11:57:52 (EDT)
 
== GetCellCoordinates ==
<source lang="papyrus">
Int[] Function GetCellCoordinates(ObjectReference akRef)
    ; Returns an array of this references' cell coordinates.
    int posX = akRef.GetPositionX() as int
    int posY = akRef.GetPositionY() as int
    if (posX < 0)
        posX = (posX / 4096) - 1
    else
posX = posX / 4096
    endif
    if (posY < 0)
        posY = (posY / 4096) - 1
    else
        posY = posY / 4096
    endif
    Int[] CellCoordinates = new Int[2]
    CellCoordinates[0] = posX
    CellCoordinates[1] = posY
    return CellCoordinates
 
EndFunction
</source>
To cut down on function calls, it does not check for interiors, so do not use this for references that are in an interior. Also the Z position was intentionally
omit, as the purpose of this function is to obtain only the X,Y coordinates as seen in the Cell View Window. --[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2019-01-15T04:04:35 (EST)
:I havent tested this in game but this looks like a worthy example to add on the primary page. Nice function. [[User:Scrivener07|Scrivener07]] ([[User talk:Scrivener07|talk]]) 2019-01-17T19:31:31 (EST)
::I prefer adding things to the talk page, to keep the primary page clean as possible, and only changing if, it I find a bug, or a "special" way the vanilla function has to be used. --[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2019-01-18T02:55:46 (EST)

Latest revision as of 02:55, 18 January 2019

Getting Cell Coordinates[edit source]

Ever wondered how you can use the Cell View window's coordinates in game? Simple. You take the two values and you multiply them by 4096. If you want to convert an object's in game coordinates to use in the Cell View window, you divide the X and Y values by 4096 and cast as int to remove the decimals. Lisselli (talk)Lisselli (talk) 2017-10-06T11:57:52 (EDT)

GetCellCoordinates[edit source]

Int[] Function GetCellCoordinates(ObjectReference akRef)
    ; Returns an array of this references' cell coordinates.
	
    int posX = akRef.GetPositionX() as int
    int posY = akRef.GetPositionY() as int
	
    if (posX < 0)
        posX = (posX / 4096) - 1
    else
	posX = posX / 4096
    endif
	
    if (posY < 0)
        posY = (posY / 4096) - 1
    else
        posY = posY / 4096
    endif
	
    Int[] CellCoordinates = new Int[2]
    CellCoordinates[0] = posX
    CellCoordinates[1] = posY
	
    return CellCoordinates

EndFunction

To cut down on function calls, it does not check for interiors, so do not use this for references that are in an interior. Also the Z position was intentionally omit, as the purpose of this function is to obtain only the X,Y coordinates as seen in the Cell View Window. --Rasikko (talk) 2019-01-15T04:04:35 (EST)

I havent tested this in game but this looks like a worthy example to add on the primary page. Nice function. Scrivener07 (talk) 2019-01-17T19:31:31 (EST)
I prefer adding things to the talk page, to keep the primary page clean as possible, and only changing if, it I find a bug, or a "special" way the vanilla function has to be used. --Rasikko (talk) 2019-01-18T02:55:46 (EST)