Main Menu

CRPL Help

Started by CobraKill, October 06, 2013, 01:08:25 AM

Previous topic - Next topic

CobraKill

First thread in the custom section

I took the terrain walker beam and edited to target creeper and digitals. I don't know how I broke it either and no one in chat could figure it out either.

# Weapon.crpl
# Created on: 2/4/2013 3:31:03 PM
# ------------------------------------------

<-firing if
"Firing" trace
GetTimer0 eq0 if
@Kaboom
else
@Fire
endif
else
GetTimer0 eq0 if
GetNearestGroundEnemy(199 88 18 1 1 0 1) ->closestUnit
<-closestUnit neq0 if
"Closest Unit " <-closestUnit trace2
self "beam" "Custom1" SetImage
self "beam" 0 255 255 255 SetImageColor
self "beam" 1.5 SetImageScaleY
@Fire
endif
1 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


It's designed to target Creeper and digitals and destroy them with a beam.
Never trust a computer that doesn't fit through your nearest window.

Karsten75

Not help. But Virgil really should restore Coders' Corner... An then delete this post.

Lost in Nowhere

I don't have any help, but I need some...
For some reason this code doesn't work correctly:
This is attached to a tower:
# LaserNest.crpl
# Created on: 10/8/2013 8:15:32 AM
# ------------------------------------------
$Wait:60
$MaxUnits:20

once
CreateList ->List
endonce

CurrentCoords IsDigitalisConnected <-List GetListCount <-MaxUnits lt and if
"crplcore" CurrentCoords CreateUnit ->NewUnit
<-List <-NewUnit AppendToList
<-NewUnit "DigitalisMove" AddScriptToUnit
<-NewUnit "DigitalisMove" "STARTX" CurrentX SetScriptVar
<-NewUnit "DigitalisMove" "STARTY" CurrentY SetScriptVar
<-NewUnit "CONST_COUNTSFORVICTORY" 0 SetUnitAttribute
<-NewUnit "CONST_NULLIFIERDAMAGES" 0 SetUnitAttribute
<-NewUnit "CONST_CREATEPZ" 0 SetUnitAttribute
<-NewUnit "CONST_DESTROYMODE" 1 SetUnitAttribute
<-NewUnit "CONST_DESTROYONDAMAGE" 1 SetUnitAttribute
<-NewUnit "CONST_SNIPERTARGET" 1 SetUnitAttribute
<-NewUnit "CONST_SUPPORTSDIGITALIS" 0 SetUnitAttribute
<-NewUnit "CONST_TAKEMAPSPACE" 0 SetUnitAttribute
<-NewUnit "main" "Custom1" SetImage
endif

<-List GetListCount 0 do
<-List I GetListElement ->CurrentUnit
<-CurrentUnit "CONST_ISDESTROYED" GetUnitAttribute if
<-List I RemoveListElement
endif
loop

<-Wait Delay

This on is used by the other:
# DigitalisMove.crpl
# Created on: 10/8/2013 3:23:45 PM
# ------------------------------------------
#Modified version of the "rail mover" script on the wiki

$SPEED:2
$STARTX:0
$STARTY:0

once
# Initialize our last position since we don't have one.
<-STARTX SetCurrentX
<-STARTY SetCurrentY
CurrentX ->lastCellX
CurrentY ->lastCellY
endonce

#If we aren't moving, choose a new location.  The location will be a neighboring cell.
GetQueuedMoveCount eq0 if
@ChooseNewCell if
<-chosenX <-chosenY <-SPEED QueueMove
CurrentX ->lastCellX
CurrentY ->lastCellY
endif
endif
CurrentCoords IsDigitalisConnected not CurrentCoords GetDigitalisGrowth not or if
Self 1 Destroy
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
0 <-count RandInt ->randCellNumber

# Go through the list and pop all 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.
<-count 0 do
->y
->x
I <-randCellNumber eq if
<-x ->chosenX
<-y ->chosenY
endif
loop
# Return if we chose a new location
<-chosenX -1 neq


:GetPossibleCells
#Check the four neighboring cells to see if they are acceptable terrain heights.
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.
<-count eq0 if
<-lastCellX
<-lastCellY
1 ->count
endif


:CheckCell
#Check to see if the cell we are looking at is the last cell, if so ignore.
<-cx <-lastCellX neq <-cy <-lastCellY neq or if
# Check if the target cell has digitalis.  If so, push the
# coordinates to the stack and increment count.
<-cx <-cy IsDigitalisConnected if
<-cx
<-cy
<-count 1 add ->count
endif
endif

The first script kindof creates the units successfully, except that they start at the left of the screen... and don't move.
Don't die! :)

J

Quote from: CobraKill on October 06, 2013, 01:08:25 AM
First thread in the custom section

I took the terrain walker beam and edited to target creeper and digitals. I don't know how I broke it either and no one in chat could figure it out either.


: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


It's designed to target Creeper and digitals and destroy them with a beam.
In the :Kaboom function you use the Destroy command what doesn't work on creeper or digi (only structures). Same for the unit attributes in the :Fire command. You changed the code so the closestUnit variable contains the UID of a piece of creeper or digi, but that doesn't have an UID.

Pscioed

Quote from: CobraKill on October 06, 2013, 01:08:25 AM



<-deltaY <-deltaX atan2 ->angle




I haven't really examined everything very carefully, so this is just a tiny thing.



<-deltaY <-deltaX div atan2 ->angle



I think this would do what you want. This error would just be graphical though, and it sounds like your problems go deeper than that. Still, every little thing helps I hope :)

Where did you find this command: GetNearestGroundEnemy? I don't see it on the wiki, which is my only resource for these things.


<-img 4 lt if 4 ->img endif


Where do you originally define the variable "img"? It seems to just show up here needing a value.

CobraKill

GetNearestGroundEnemy was a command that got added late in beta. It hasn't made it's way on to the wiki yet. It's the unitID's I have it doing. I didn't realize I had to the change the Kaboom and Fire Functions when I adapted the code. I'll comb through it with those suggestions in mind.
Never trust a computer that doesn't fit through your nearest window.