Modifying Glider Script

Started by Jacobwde12, May 01, 2015, 10:44:27 PM

Previous topic - Next topic

Jacobwde12

I have a question. Whenever I change the glider script to not destroy the glider itself, it never destroys the unit it was targeting. Does anyone know how to make the glider not destroy itself but still be able to destroy other units?


This is the only code I deleted from the Glider Script:

self 1 Destroy

Telanir

Well, provided that you have stored the unit it was supposed to be targeting in a variable perhaps called ->unit then you can just kill it like so:
<-unit 1 Destroy
Want to make genius CRPL? The new top map? You can start here!

Find out more about Creeper World 3 on the wiki!

CW3, The Sleeper Menace!

Own an iOS device? Check out my game Blobivers

Grayzzur

If you require further help than that, please post which map the script is in, or post the script. The gliders I thought you might be referring to run two scripts.. Patrol.crpl and PatrolGun.crpl... in the Alpha Sector, virgilw, Aether map. The syntax in that script is a little different than your example, though.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Jacobwde12

The map where the script is contained is called Chanson in the normal Campaign Mode

Script for the Patrol Gun:
$range:9

<-firing if
"Firing" trace
GetTimer0 eq0 if
@Kaboom
else
@Fire
endif
else
GetTimer0 eq0 if
@GetClosestUnit
<-closestUnit neq0 if
"Closest Unit " <-closestUnit trace2
self "beam" "Custom1" SetImage
self "beam" 255 255 0 255 SetImageColor
self "beam" 1.5 SetImageScaleY
@Fire
endif
# For efficiency, wait a second before scanning for new units.
# We also will wait if firing.  This will make the beam track the unit
# before everything explodes.
20 SetTimer0
endif
endif

:Kaboom
<-closestUnit 2 Destroy
self 1 Destroy

:Fire
TRUE ->firing

<-closestUnit CONST_ISDESTROYED GetUnitAttribute if
FALSE ->firing
SetImage(self "beam" "NONE")
SetImage(self "damage" "NONE")
return
endif

<-closestUnit CONST_PIXELCOORDX GetUnitAttribute ->targetX
<-closestUnit 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 4 lt if 4 ->img endif
<-img 7 gt if 4 ->img endif

SetImage(self "damage" concat("Custom" <-img) )
SetImagePosition(self "damage" <-deltaX <-deltaY -0.1)

<-img 1 add ->img


# Func :GetClosestUnit
# Finds the nearest unit in "range".
# Returns the unit uid of the closest unit, or 0 if no unit is in range
# "closestUnit" contains the return value on return
# "unitCount" contains the number of units in range
# "closestDistance" containts the distance to the closest unit
:GetClosestUnit
99999999 ->closestDistance
0 ->closestUnit
#All 'player' units are returned, including power zones and artifacts.  If you don't want them to be targeted, they must be excluded...
GetUnitsInRange(CurrentCoords <-range)  ->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
# EndFunc


Script for Patrol:
$SPEED:2

once
# Grab the current terrain height and remember this.
# We only move onto terrain that is equal to the starting height.
GetTerrain(CurrentX CurrentY) ->targetTerrainHeight

# Initialize our last position since we don't have one.
-1 ->lastCellX
-1 ->lastCellY

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_SNIPERTARGET True)
SetUnitAttribute(Self CONST_DESTROYMODE 1)
endonce

<-dieing if
if (GetTimer0 eq0)
Destroy(self 1)
endif
return
endif

#If we aren't moving, choose a new location.  The location will be a neighboring cell.
if (GetQueuedMoveCount eq0)
if (GetUnitAttribute(<-base CONST_ISDESTROYED))
true ->dieing
SetTimer0(RandInt(30 150))
return
endif

if (@ChooseNewCell)
QueueMove(<-chosenX <-chosenY <-SPEED)
CurrentX ->lastCellX
CurrentY ->lastCellY
endif
endif


:ChooseNewCell
-1 ->chosenX
-1 ->chosenY

# Get a list of the neighbors that we can move to.
# This call returns the coordinate pairs on the stack.
@GetPossibleCells

# Choose a random location within the list
RandInt(0 <-count)  ->randCellNumber

# Go through the list and pop tall of the coordinates off the stack
# As we pass the coordinates that we chose in our random number above, remember them.
# Those are the coordinates we will be returning.
do (<-count 0)
->y
->x
if (I eq(<-randCellNumber))
<-x ->chosenX
<-y ->chosenY
endif
loop
# Return if we chose a new location
<-chosenX neq(-1)


:GetPossibleCells
#Check the four neighboring cells to see if they are the same terrain height.
0 ->count
CurrentX 1 add ->cx CurrentY ->cy @CheckCell #Right
CurrentX ->cx CurrentY 1 sub ->cy @CheckCell #Up
CurrentX 1 sub ->cx CurrentY ->cy @CheckCell #Left
CurrentX ->cx CurrentY 1 add ->cy @CheckCell #Down

# By default, we won't return the last cell coordinates.  This is so the patrolling unit
# doesn't return back to where it came from immediately.  But, if the only choice is to return
# to the previous cell, then that is what we have to do.
if (<-count eq0)
<-lastCellX
<-lastCellY
1 ->count
endif


:CheckCell
#Check to see if the cell we are looking at is the last cell, if so ignore.
if (<-cx <-lastCellX neq <-cy <-lastCellY neq or)
# Check if the target cell is at our target terrain height.  If so, push the
# coordinates to the stack and increment count.
if (GetTerrain(<-cx <-cy) eq (<-targetTerrainHeight))
<-cx
<-cy
<-count 1 add ->count
endif
endif


:Destroyed
if (<-base neq0)
<-base "Base.crpl" "patrolCount" GetScriptVar ->patrolCount
<-patrolCount 1 sub ->patrolCount
<-base "Base.crpl" "patrolCount" <-patrolCount SetScriptVar
endif
PlaySound("Weapons15")
if (GetInhibitorCount gt(0))
#Used for achievements.  This call only works in this mission, and has no effect elsewhere.
Reserved7
endif

Jacobwde12

So does anyone know how to change the script and make it so that the glider will destroy other units without destroying itself? Also how would you use SuspendMove? I keep trying to figure out how to use it however it just suspends the units move for eternity.

RandUnitCoords 4 QueueMove 90 SuspendMove