Difference between revisions of "Coordinate Functions"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Rasikko
(Created page with "Putting my coordinate functions here since my personal pages are getting too big. <source lang="papyrus"> Int[] Function GetCellCoordinates(ObjectReference akRef) ; Retur...")
 
imported>Rasikko
Line 25: Line 25:
    
    
     return CellCoordinates
     return CellCoordinates
EndFunction
</source>
<br>
The following requires GetCellCoordinates(). To explain what the function below does, the origin in the game, for example has the x axis positions of 0, 4096, respectively.
<source lang="papryus">
Int[] Function GetCellStartingWorldPositions(Int[] aiCoordinates)
    ; Returns an array of starting world positions for this cell.
Int coordinateX = aiCoordinates[0]
Int coordinateY = aiCoordinates[1]
Int[] startPos = new int[2]
if coordinateX < 0
    coordinateX = coordinateX * 4096 + 4096
else
coordinateX + 4096
    endif
if coordinateY < 0
coordinateY = coordinateY * 4096 + 4096
else
coordinateY + 4096
endif
startPos[0] = coordinateX
startPos[1] = coordinateY
return startPos
EndFunction
EndFunction
</source>
</source>

Revision as of 10:17, 21 November 2020

Putting my coordinate functions here since my personal pages are getting too big.

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


The following requires GetCellCoordinates(). To explain what the function below does, the origin in the game, for example has the x axis positions of 0, 4096, respectively.

Int[] Function GetCellStartingWorldPositions(Int[] aiCoordinates)
    ; Returns an array of starting world positions for this cell.
	Int coordinateX = aiCoordinates[0]
	Int coordinateY = aiCoordinates[1]
	Int[] startPos = new int[2]
	
	if coordinateX < 0
	    coordinateX = coordinateX * 4096 + 4096
	else
		coordinateX + 4096
    endif
	
	if coordinateY < 0
		coordinateY = coordinateY * 4096 + 4096
	else
		coordinateY + 4096
	endif
	
	startPos[0] = coordinateX
	startPos[1] = coordinateY
	
	return startPos
EndFunction