Moving CRPL Core

Started by wolkiewicz, July 07, 2014, 04:31:42 AM

Previous topic - Next topic

wolkiewicz

Can I use movement functions from Flyer Movement Framework on my own script, or i must use FlyerMovement.crpl ? I tried to do somethink but without effect. Flier demo looks very nice!
All scripts i'm using:
Bomb:
# Bomb.crpl
# Created on: 7/9/2014 10:25:53 AM
# ------------------------------------------

$targetX:0
$targetY:0
$speed:1
$payload:20
#----------------

once
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)
QueueMove(<-targetX <-targetY <-speed)
endonce
If (GetQueuedMoveCount eq0)
CurrentCoords <-payload SetCreeper
Destroy(Self 0)
endif

Bomber:
# Bomber.crpl
# Created on: 7/9/2014 10:38:06 AM
# ------------------------------------------

$range:8
$payload:20
$speed:1.5
$delay:30
$acceleration:0
#-------------------------------------------

once
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)
SetUnitAttribute(Self CONST_BEAMTARGET TRUE)
SetUnitAttribute(Self CONST_MAXHEALTH 3)
SetUnitAttribute(Self CONST_HEALTH 3)
Self "main" -0.02 SetImagePositionZ
    0 ->targetX
    0 ->targetY
endonce

@GetClosestUnit ->closestUnit


<-closestUnit neq0 if
<-closestUnit CONST_COORDX GetUnitAttribute ->targetX
<-closestUnit CONST_COORDY GetUnitAttribute ->targetY
else
-1 ->targetX -1 ->targetY
endif

once
@TakeoffNow
@QueueMove(<-targetX <-targetY -1 <-speed <-acceleration -1)
endonce

CurrentCoords <-range GetUnitCountInRange neq0 if
GetTimer0 eq0 if
PlaySound("Weapons4")
@CreateBomb
<-delay SetTimer0
endif
endif




:CreateBomb
"CRPLCore" CurrentX CurrentY CreateUnit ->unit
<-unit "Bomb.crpl" AddScriptToUnit
<-unit "Bomb.crpl" "targetX" <-targetX SetScriptVar
<-unit "Bomb.crpl" "targetY" <-targetY SetScriptVar
<-unit "Bomb.crpl" "payload" <-payload SetScriptVar
<-unit "main" "Custom2" SetImage
<-unit "main" 0 120 255 255 SetImageColor
<-unit "main" -0.01 SetImagePositionZ
#End


:GetClosestUnit
99999999 ->closestDistance
0 ->closestUnit
GetUnitsInRange(CurrentCoords 99999999)  ->unitCount
do (<-unitCount 0)
->unit
CurrentCoords <-unit CONST_COORDX GetUnitAttribute <-unit CONST_COORDY GetUnitAttribute Distance ->d
if (<-d lt(<-closestDistance))
GetUnitType(<-unit) ->ut
if ( not(<-ut eq ("POWERZONE") or (<-ut eq ("TECHARTIFACT")) or (<-ut eq("MESSAGEARTIFACT")) or (<-ut eq("SHIELDKEY"))) )
<-d ->closestDistance
<-unit ->closestUnit
endif
endif
loop
<-closestUnit
#End


:QueueMove
# arguments: X and Y (cell coordinates), direction on arrival, speed (pixel per tick), acceleration (change in speed per tick), turn radius (pixels)
# direction has to be a positive angle (0 to 2*PI), set to -1 to allow any direction
# speed, acceleration and turn radius can be set to -1 to keep them unchange
# x1 y1 f1 f2 f3 f4 -
CreateList ->Waypoint
do(4 0)
->item
PrependToList(<-Waypoint <-item)
loop
CellToPixel
do(2 0)
->item
PrependToList(<-Waypoint <-item)
loop
AppendToList(GetScriptVar(Self <-movementScriptName "QueuedWaypoints") <-Waypoint)
#End


:TakeoffNow
# starts the takeoff animation without queueing a waypoint
SetScriptVar(Self <-movementScriptName "changeFlightState" 1)
#end

Script Settings from Flyer.crpl
once
# FlyerMovement.crpl settings
"Bomber.crpl"  ->movementScriptName
SetScriptVar(Self <-movementScriptName "initialFlightState" 0) # initial flight state, 0 means landed, 2 means in the air

# initial setup
CreateList ->QueuedWaypoints
SetScriptVar(Self <-movementScriptName "QueuedWaypoints" <-QueuedWaypoints)
SetScriptVar(Self <-movementScriptName "waitForInitialization" 0)
endonce


Wow, scripting is very hard....

Grayzzur

I believe it was designed to be added as a second script to your unit. You don't really call functions in the other script, but you can set variables in the other script (like targetX/targetY) to adjust it's behavior. The sample flyer is doing that by setting the QueuedWaypoints (and some other variables) of the other script.

If you want to rip parts of it out and put it in your own script, there's nothing stopping you. The polite thing to do at that point is add a comment to the top of your script stating something like "Portions of this script taken from FlyerMovement.crpl by Eduran." Give credit where credit is due!
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

wolkiewicz

The problem is, it don't work when i add 2 scripts to unit. Look at my "Bomber" script. I added :QueueMove function to script, and "Settings" script to bomber, but it still don't moving. But when i'm using <-targetX <-targetY QueueMove , it moves to target, but texture is in wrong rotation. I going to do somethink like Demoflyer, but with diffrent track.