Bugs With SetScriptVar and Graphical Bug

Started by Jacobwde12, May 08, 2015, 08:51:19 AM

Previous topic - Next topic

Jacobwde12

Hey guys! Umm I have 2 problems in the following scripts. The SetScriptVar in the first script doesn't work and when it makes the beam/laser image in the @Move function it doesn't disappear  after the delay, instead it moves to the next point in the move queue and then turns off. Does anyone know how to fix this?

1st Satellite Script
# Satellite Actions.crpl
# Created on: 2/26/2015 9:04:33 PM
# ------------------------------------------

$stage:0
$ckey:1
$laserd:1
$lassdw:1800
$lasdint:750

#Makes the satellite move between multiple points.
#The points are defined once and assigned to local variables.
@move

once
   #Make the second image disappear when the user unpauses.

   Self RemoveImages
   Self "laser" "Custom2_128" SetImage
   Self "laser" 0.01 SetImagePositionZ
   Self "laser" 3 SetImageScaleX
   Self "laser" 3 SetImageScaleY
   Self "laser" 255 255 255 255 SetImageColor
   

   CreateList ->patrolPath
   ClearStack #just in case
   12 46
   12 243
   125 243
   125 206
   125 243
   188 243
   240 243
   240 12
   12  12
   <-patrolPath PrependStackToList
   
   3 ->patrolSpeed
endonce

#Control Stages
<-stage 2 gte if
<-laserd 1 eq if
Delay(<-lassdw)
@FireDLaser
<-laserd -1 add ->laserd
else
    <-laserd eq0 if
10 0 do
Delay(<-lasdint)
@FireDLaser loop endif endif
<-stage 3 gte if
"ractive" 0 GetCoresWithVar pop ->rl
SetScriptVar(<-rl "RocketLauncher.cprl" "ractive" 1)
endif  endif

:Move
GetQueuedMoveCount eq0 if
0 ->i
while <-i <-patrolPath GetListCount lt repeat
<-patrolPath <-i GetListElement
<-patrolPath add(<-i 1) GetListElement
<-patrolSpeed QueueMove

<-i 2 add ->i



endwhile
endif

#Stop
CurrentX 125 eq CurrentY 206 eq and if
SuspendMove(90)


#Search for Owner
"ccode" <-ckey GetCoresWithVar pop ->owner

#Fire Charging Laser
self "beam" "Custom1" SetImage
self "beam" 255 255 0 255 SetImageColor
self "beam" 1.5 SetImageScaleY

<-owner CONST_PIXELCOORDX GetUnitAttribute ->targetX
<-owner CONST_PIXELCOORDY GetUnitAttribute ->targetY

self CONST_PIXELCOORDX GetUnitAttribute ->selfX
self CONST_PIXELCOORDY GetUnitAttribute ->selfY

<-targetX <-selfX sub ->deltaX
<-targetY <-selfY sub ->deltaY
<-deltaY <-deltaX atan2 ->angle
<-selfX <-selfY <-targetX <-targetY Distance ->distance
<-distance 24 div ->beamScaleX

<-deltaX 2 div ->beamX
<-deltaY 2 div ->beamY

SetImagePosition(self "beam" <-beamX <-beamY -0.02)
SetImageScaleX(self "beam" <-beamScaleX)
SetImageRotation(self "beam" <-angle)



<-img 1 add ->img
Delay(170)
self "beam" 255 0 0 0 SetImageColor
    SetImage(self "beam" "NONE")
SetImage(self "damage" "NONE")
<-stage 1 add ->stage
Delay(60)
@move

endif




:FireDLaser

#Choose Target

0 ->ldrtarget
GetUnitsInRange(CurrentCoords 100000)
RandUnitCoords ->ldtargetY ->ldtargetX
<-ldtargetX <-ldtargetY 1 GetUnitsInRange pop ->ldrtarget
#Stop
SuspendMove(90)

#Fire Charging Laser
self "dbeam" "Custom1" SetImage
self "dbeam" 255 255 0 255 SetImageColor
self "dbeam" 1.5 SetImageScaleY

<-ldrtarget CONST_PIXELCOORDX GetUnitAttribute ->targetX
<-ldrtarget CONST_PIXELCOORDY GetUnitAttribute ->targetY

self CONST_PIXELCOORDX GetUnitAttribute ->selfX
self CONST_PIXELCOORDY GetUnitAttribute ->selfY

<-targetX <-selfX sub ->deltaX
<-targetY <-selfY sub ->deltaY
<-deltaY <-deltaX atan2 ->angle
<-selfX <-selfY <-targetX <-targetY Distance ->distance
<-distance 24 div ->beamScaleX

<-deltaX 2 div ->beamX
<-deltaY 2 div ->beamY

SetImagePosition(self "dbeam" <-beamX <-beamY -0.02)
SetImageScaleX(self "dbeam" <-beamScaleX)
SetImageRotation(self "dbeam" <-angle)

<-img 1 add ->img
Delay(90)
<-ldrtarget 2 Destroy

self "beam" 255 0 0 0 SetImageColor
    SetImage(self "dbeam" "NONE")
SetImage(self "damage" "NONE")
@Move



2nd Rocket Launcher Script
# RocketLauncher.crpl
# Created on: 5/2/2015 10:17:25 AM
# ------------------------------------------
$payload:20
$interval:180
$amount:4
$initialdelay:1800
$ractive:0
$trace:0

<-trace 1 eq if
Self trace
ShowTraceLog
else
HideTraceLog
endif



<-ractive 1 eq if
once
Delay(<-initialdelay)
@Spit
endonce

Delay(<-interval)
@Spit

:Spit
<-amount ->current
while <-current 0 gt
repeat
Delay(10)
RandUnitCoords ->targetY ->targetX
CreateUnit("CRPLCORE" CurrentX CurrentY) ->rocket
AddScriptToUnit(<-rocket "Rocket.crpl")
SetScriptVar(<-rocket "Rocket.crpl" "targetX" <-targetX)
SetScriptVar(<-rocket "Rocket.crpl" "targetY" <-targetY)
SetScriptVar(<-rocket "Rocket.crpl" "payload" <-payload)
PlaySound("Explosion5")
<-current 1 sub ->current

endwhile
endif


3rd Rocket Script
# Rocket.crpl
# Created on: 5/3/2015 9:55:40 AM
# ------------------------------------------
$targetX:-1
$targetY:-1
$payload:0
$speed:10
$damage:0.4

<-targetX <-targetY 1 GetUnitsInRange pop ->target


if (GetQueuedMoveCount eq0)
Damage(<-target <-damage)
SetCreeper(CurrentX CurrentY <-payload)
Destroy(Self 1)
endif



:Awake

Trace3("Awake: " <-targetX <-targetY)
SetUnitAttribute(Self CONST_CREATEPZ FALSE)
SetUnitAttribute(Self CONST_TAKEMAPSPACE FALSE)
SetUnitAttribute(Self CONST_SUPPORTSDIGITALIS FALSE)
SetUnitAttribute(Self CONST_NULLIFIERDAMAGES FALSE)
SetUnitAttribute(Self CONST_COUNTSFORVICTORY FALSE)

SetImage(Self "Main" "Custom2")
SetImagePositionZ(Self "Main" -0.1)
SetImageScale(Self "Main" 0.5 0.5)
QueueMove(<-targetX <-targetY <-speed)