IsSelected code

Started by bluebolt, January 05, 2017, 06:23:35 PM

Previous topic - Next topic

bluebolt

Well, because I really wanted an IsSelected command, i made a script for it :D this is only a section of a script i've been working on, but this is like half of it... could some of you verify the code, and/or fix it up? i think this could be greatly helpful :D. the full (WIP) code is attached as well, for those curious(and if there is some stuff in it that should be in the spoiler as well)
Spoiler

once
0 ->Selected
Self "main" "Custom3" SetImage
Self "main" "LowerUnits" SetImageLayer
Self "main" 1 SetImageOrder
Self "main" 1.5 1.5 SetImageScale
Self "main" <-direction SetImageRotation
endonce
@click


if(<-Selected)
@pointTowardsMouse
endif

:click
if(0 GetMouseButtonDown)
Self GetUnitCoords ->UCoordy ->UCoordx
0 ->selection #if it was selected
5 ->Uwidth #cells
5 ->Uheight #cells
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)
if(<-Selected 0 eq)
<-UCoordx <-UWidth add ->tempUCoordx
<-UCoordy <-UHeight add ->tempUCoordy
<-tempUCoordx <-tempUCoordy
@IsSelected ->Selected
1 ->selection
endif
loop
loop
if( <-selection 0 eq)
if(<-Selected)
CurrentPixelCoords ->y ->x
GetMousePosition ->my ->mx
<-my <-y sub <-mx <-x sub atan2 ->direction
Self "main" <-mouseDirection SetImageRotation
<-pointer 0 DestroyUnit
0 ->Selected
endif
endif
endif
:IsSelected
->tempUCoordy ->tempUCoordx
GetMouseCell ->MCelly ->MCellx
if(<-MCellx <-tempUCoordx eq)
if(<-MCelly <-tempUCoordy eq)

1 ->Selected
@createPointer

endif
endif
<-Selected
:createPointer
"PRPLCORE" 0 0 CreateUnit ->pointer
<-pointer "main" "Custom1" SetImage

:pointTowardsMouse
CurrentPixelCoords ->y ->x
GetMousePosition ->my ->mx

<-my <-y sub <-mx <-x sub atan2 ->mouseDirection
<-mx ->pointer.UnitPixelCoordX
<-my ->pointer.UnitPixelCoordY
<-pointer "main" <-x <-y <-mx <-my Distance 12 div 1 SetImageScale
<-pointer "main" <-mouseDirection SetImageRotation
<-pointer "main" "Ships" SetImageLayer
<-pointer "main" 1 SetImageOrder
<-pointer "main" <-x <-mx sub 2 div <-y <-my sub 2 div -0.025 SetImagePosition
[close]
Even YOU may survive an apocalypse! Fight back against the creeper today!

Sorrontis

V is adding the isSelected and related functions soon :)
"If you want others to be happy, practice compassion. If you want to be happy, practice compassion."