How would one show a circle, such as the ones when you hover over a circle, but when you hover over a prpl unit? The script below should function correctly in fining if the mouse is over the unit. I would prefer to not have a ton of cores...
I have this function that i pulled from my overMire finder:(if it doesn't work, idk why it wouldn't)
Note: Uwidth and Uheight are determined through the editor(default 5,5). They are set as default in this example.
:showRange
Self GetUnitCoords ->UCoordY ->UCoordX
GetMouseCell ->MCellY ->MCellX
0 ->showingRange
do(<-Uwidth 0)
i <-Uwidth 2 div 0 round sub ->UWidth #x value in relation to center(0,0)
do(<-Uheight 0)
i <-Uheight 2 div 0 round sub ->UHeight #y value in relation to center(0,0)
<-UCoordX <-UWidth add ->tempUCoordX
<-UCoordY <-UHeight add ->tempUCoordY
if(<-MCellX <-tempUCoordX eq <-MCellY <-tempUCoordY eq and)
#where I would put code to show the range
1 ->showingRange #trace("hovering")
endif
loop
loop
if(<-showingRange not)
#where I would put code to hide range
endif
There are two ways to create a range circle. The first is to have a "circle" image, and scale it appropriately. The other is to have any image, and make an approximate circle, following this logic: A triangle is nowhere near being a circle. A square is better. A pentagon is starting to look round. An octagon is pretty good. 100 sides is almost perfect.
As to that code, may I suggest the following modification:
:MouseHovering #[ - Hovering ]
GetMouseCell ->MouseCellY ->MouseCellX
<-MouseCellX CurrentX sub abs <-Width gt if 0 return endif
<-MouseCellY CurrentY sub abs <-Width gt if 0 return endif
1
:ShowRange
@MouseHovering if
#Show circle
else
#Hide circle
endif
For an example of this, you can examine Stickman's range-indicator (one image, blurry for large circles) or my Construction Pylon (composite image). Either should have come copy/paste -able code.
Thanks! I didn't think about using the difference between the mouse cell and the unit cell, so that saves a lot of code :D
Here's the code, with changed names cause "strut" doesnt make sense in this situation.
:MouseHovering
GetMouseCell ->MouseCellY ->MouseCellX
<-MouseCellX CurrentX sub abs <-Uwidth 2 div 0 round gt if 0 return endif #2 div 0 round cause its an odd number(and total height, not half)
<-MouseCellY CurrentY sub abs <-Uheight 2 div 0 round gt if 0 return endif
1
:ShowRange
@MouseHovering if
#Show circle
64 ->Cpieces #C meaning circle
TWOPI <-Cpieces div ->CpieceAngleChange
<-range 4 mul ->PixelRange
<-CpieceAngleChange 2 div sin <-PixelRange mul ->CpieceLength
<-CpieceAngleChange 2 div cos <-PixelRange mul ->CpieceDist
#<-Strut Trace
<-Cpieces 0 do
"Cpiece_" I concat ->CpieceName
<-CpieceAngleChange I mul ->CpieceAngle
Self <-CpieceName <-Cpiece SetImage
Self <-CpieceName <-CpieceAngle HALFPI add SetImageRotation
Self <-CpieceName <-CpieceAngle cos <-CpieceDist mul <-CpieceAngle sin <-CpieceDist mul 0 SetImagePosition
Self <-CpieceName <-CpieceLength 5.95 div SetImageScaleX
Self <-CpieceName 1 SetImageScaleY
Self <-CpieceName 0 255 255 100 SetImageColor
loop
else
#Hide circle
<-Cpieces 0 do
"Cpiece_" I concat ->CpieceName
<-CpieceAngleChange I mul ->CpieceAngle
Self <-CpieceName 0 SetImageScaleY
loop
endif
I think this should help.
:MouseHovering
GetMouseCell ->MouseCellY ->MouseCellX
<-MouseCellX CurrentX sub abs <-Uwidth 2 div 0 round gt if 0 return endif #2 div 0 round cause its an odd number(and total height, not half)
<-MouseCellY CurrentY sub abs <-Uheight 2 div 0 round gt if 0 return endif
1
:ShowRange
@MouseHovering if
#Show circle
256 ->Cpieces #C meaning circle
TWOPI <-Cpieces div ->CpieceAngleChange
<-range 4 mul ->PixelRange
<-CpieceAngleChange 2 div sin <-PixelRange mul ->CpieceLength
<-CpieceAngleChange 2 div cos <-PixelRange mul ->CpieceDist
#<-Strut Trace
<-Cpieces 0 do
"Cpiece_" I concat ->CpieceName
<-CpieceAngleChange I mul ->CpieceAngle
Self <-CpieceName <-Cpiece SetImage
Self <-CpieceName <-CpieceAngle HALFPI add SetImageRotation
Self <-CpieceName <-CpieceAngle cos <-CpieceDist mul <-CpieceAngle sin <-CpieceDist mul 0 SetImagePosition
Self <-CpieceName <-CpieceLength 6 div SetImageScaleX
Self <-CpieceName 1 SetImageScaleY
Self <-CpieceName 0 255 255 100 SetImageColor
loop
else
#Hide circle
<-Cpieces 0 do
"Cpiece_" I concat ->CpieceName
<-CpieceAngleChange I mul ->CpieceAngle
Self <-CpieceName 0 SetImageScaleY
loop
endif