# --OverCharger-- 12/13/2016 5:37:20 PM once # Set up image(s). You NEED to set image layer to Ships, otherwise your module will render behind ships. Self "main" "Custom0_128" SetImage Self "Base" "Custom1_128" SetImage Self "main" "Ships" SetImageLayer Self "Base" "Ships" SetImageLayer Self "main" 2 SetImageOrder Self "Base" 1 SetImageOrder Self "main" 1 1 SetImageScale Self "Base" 1 1 SetImageScale Self "ShipModule.prpl" "Ship" GetScriptVar ->Ship <-Ship.ShipIsEnemy ->IsEnemy -1 ->target 0 ->BarrelAngle endonce #The heading of the ship the module is attached to. Self "ShipModule.prpl" "ShipAngle" GetScriptVar ->ShipAngle #The amount the heading has changed in the last frame (in radians) Self "ShipModule.prpl" "delta" GetScriptVar ->Delta #Whether the module exists. #0 = hull destroyed #1 = under construction #2 = built Self "ShipModule.prpl" "exist" GetScriptVar ->Exist #If the module is destroyed, make it invisible and prevent the rest of the script from running. <-Exist eq0 if self "main" 0 0 0 0 SetImageColor return endif #make module align with ship #self "main" <-ShipAngle SetImageRotation #Disabled this so i could see if the barrel was aiming correctly. self "base" <-ShipAngle SetImageRotation IsPaused if return endif #This is better found in-context, as CurrentX and CurrentY are likely faster then refread and refwrite. # CurrentX ->x # CurrentY ->y CurrentPixelCoords ->y ->x <-Exist 1 eq if # if under construction, make the module semi transparent. # also use this for things like resetting turret rotation or cooldown if the module is destroyed and rebuilt self "main" 255 255 255 128 SetImageColor else self "main" 255 255 255 255 SetImageColor # I don't know of a way to read the Fire Multiple property on some enemy ships, which increases their fire rate. # Instead, this script pretends that all enemy ships have amp gems. <-Ship.ShipHasAmp <-IsEnemy or ->GemPresent #Whay do all opponents get automatic amp? #code your module's abilities here CurrentX CurrentY 35 1 GetAllUnitsInRange ->Targets #Use 1 for a box search, it makes it somewhat faster. <-Targets GetListCount 0 do <-Targets[I] ->Target <-Target GetUnitType ->TargetType <-TargetType "Stunner" eq <-TargetType "Stunner(Clone)" eq or if #Insert If It is Stunner here code <-Target GetUnitIsEnemy 1 eq if #<-Target Trace <-Target.UnitCoordX ->xx <-Target.UnitCoordY ->yy <-Target.UnitPixelCoordX ->px <-Target.UnitPixelCoordY ->py Self "main" GetImageRotation ->BarrelAngle #<-BarrelAngle Trace GetTimer0 eq0 if <-py <-y sub <-px <-x sub Trace2 <-py <-y sub <-px <-x sub atan2 ->targetAngle #get the angle from the turret to the target. #<-targetAngle Trace <-targetAngle <-BarrelAngle ShortestAngle ->dist #find the angle between the current barrel and the target angle. #for this gun, turn speed is 0.08 radians per tick <-dist abs 0.08 lt if #The results of TargetAngle can be positive or negative. If it's between -0.08 and 0.08, it can turn to the target in one tick. <-targetAngle ->BarrelAngle CurrentCoords GetLand eq0 if #fire "PRPLCORE" 0 0 CreateUnit ->beam <-px ->beam.UnitPixelCoordX <-py ->beam.UnitPixelCoordY <-beam "BeamEffect.prpl" AddScriptToUnit <-beam "BeamEffect.prpl" "Duration" 15 SetScriptVar <-beam "BeamEffect.prpl" "R" 255 SetScriptVar <-beam "BeamEffect.prpl" "G" 250 SetScriptVar <-beam "BeamEffect.prpl" "B" 0 SetScriptVar <-beam "main" "Custom2" SetImage <-beam "main" <-x <-y <-px <-py Distance 12 div 0.2 SetImageScale <-beam "main" <-targetAngle SetImageRotation <-beam "main" "Ships" SetImageLayer <-beam "main" 1 SetImageOrder <-beam "main" <-x <-px sub 2 div <-y <-py sub 2 div -0.025 SetImagePosition "Weapons22" PlaySound "Stunner" <-xx <-yy CreateUnit <-Target 0 DestroyUnit 150 SetTimer0 endif else #If the angle difference is too great, the sign of the result of ShortestAngle will tell us which way to turn. <-dist 0 gt if <-BarrelAngle 0.08 sub ->BarrelAngle else <-BarrelAngle 0.08 add ->BarrelAngle endif endif endif endif endif loop Self "main" <-BarrelAngle SetImageRotation endif :awake # I dunno, I like to have all my scrpts OWP and exit partway through, I doubt it's caused by the brain chip. 1 OperateWhilePaused