User Tools

Site Tools


crpl:crpltutorial:interactive:advancedemitter

This is an old revision of the document!


~~DISCUSSION:off~~ <-CW3 Home <-CRPL Home <-Interacive tutorials

Creating a custom emitter

Here I'll show you how to create your custom emitter. What will it have:

  • Custom image (optional)
  • Show popup text
  • Leave something other than a PZ
  • Progressive output with limit
  • Support digitalis

I will also cover how to turn it into a slip emitter or flip emitter.
It won't (as that's not what an emitter should do, also remember the game should be fair to the player):

  • Create runners
  • Send spore
  • Create new emitters on death

Custom image

Let's start simple with a custom image. You can easily skip this step as the game has a special emitter image built-in. Go HERE or HERE, download the emitter, open the map, go to edit -> units -> custom images, go to 64×64 and select the downloaded emitter.
To attach the image to a crpl core, simply double-click it and select the correct image in the image dropdown menu.

Basic script framework

We want the script to be very portable, so instead of coding the values into the script, we'll use input variables. These will be Amt, Delay, AmtIncrease, AmtMax, DeathMode and DeathAmt.

Click to display ⇲

Click to hide ⇱

$Amt:10
$Delay:15
$AmtIncrease:0.1
$AmtMax:20
$DeathMode:1
$DeathAmt:"50"

Note that “DeathAmt” holds a string instead of a number, the game will convert these into integers at runtime when possible


And as it is an emitter, simple code to make it emit creeper.

CurrentCoords <-Amt SetCreeperNoLower
<-Delay Delay

You probably need a good popup text to make sure people think it's a normal emitter. Simply add these 2 lines and you're done.

"Amt: " <-Amt concat "
" concat "Interval: " <-Delay 30.00 div 2 Round concat concat SetPopuptext

Leaving stuff behind

The hardest part probably, but the most important for huge maps, is to prevent power zone (PZ) spam.
This should be something the map maker should take care of himself and not be a problem you have to worry about. Though doing things on the destruction of our custom emitter isn't that hard.

Set PZ creation on death

If you would like to force a PZ to appear or perhaps not to appear, that is done easily with the following snippet:

Self CONST_CREATEPZ FALSE SetUnitAttribute

Explaining in-depth what it does:
self: Get the current unit (the emitter we're creating);
CONST_CREATEPZ: A constant each CRPL core has, defines whether or not to create a PZ on death;
FALSE: Set the above constant to false, meaning this emitter won't drop a PZ on death (obviously can also be TRUE);
SetUnitAttribute: Set the defined constant of the defined unit to the defined value.

It's best not to force this constant in your code and leave the decision of whether or not to leave a PZ to the map maker. A map maker can choose whether or not to leave a PZ in the options of a CRPL code.
Leaving something else behind

In case you're not satisfied with just a simple PZ, you can do whatever you'd like on the unit's death by defining a function called destroyed.
This function is automatically called the moment the unit is destroyed.
Example time!

# When Destroyed, emit a bunch of Creeper, 
# choose 5 random units and fire spores at them. 
:destroyed 
	CurrentCoords 1000 AddCreeper 
	5 0 do 
		CurrentCoords RandUnitCoords 1 20 CreateSpore 
	loop

Progressive output

Negative increment

Digitalis support

Phantom/slip emitter

Flip emitter

crpl/crpltutorial/interactive/advancedemitter.1426860118.txt.gz · Last modified: 2015/03/20 10:01 by TheDutcher