In this tutorial I'll cover how to make a flying emitter that flies to a randomly chosen spot, deploys a load of creeper and then repeats the procedure until you end the map.
First you must access the custom map section from the front screen int the projects sector.
Press the edit map button to access all the map editing functions.
Now when everything is set up, it's time to start scripting. At this point I hope you have went through the start page of the CRPL page, if not, do it now! It explains the basics of the language so you understands the fundamentals, but don't worry if you doesn't get everything there, I'll cover as much as possible here.
So right now, if you did everything right, and have a text editor set up, then you should have a mostly empty page with just some gibberish at the top, you can remove that part if you want or keep it, it doesn't really make a difference.
But where to start?
I will start with showing off the first two rows of the code:
In these two rows you have defined all the properties for the emitter, or not really, but all the values that you'd need to enter in manually! Also when defining numbers like that you'll allow changes to happen out of the code, isn't that fantastic?!
But ok, how does this work?
First off you need to understand the concept of variables, and now you'd that you had listened under your algebra lessons in school, but it's fine, I'm here to attempt to teach you what this means. A variable is the concept of “naming” values and then store them so you can use them later. You can also alter the values in variables rather freely and this makes it lots more easier to keep check on all the numbers you'll be handling while programming. Also this makes user input and calculations possible in your code.
So, how do i actually define a variable and then give it a value?
The code above defines the variable named Speed, it's dead simple, just add a $ before a name that CAN'T be separated my a space, it has to be another symbol, and you'll have your variable defined, but for it to work you have to assign it something, let's say a number!
There, now the variable have a name AND a number stored, the number of 3. Now the variable is initialized and ready to use, and I'll cover later how to change this outside of the script file.
So with that knowledge you can now see that with the two lines of code i wrote earlier, i defined two variables and then assigned them different numbers, and these variables are going to be used later on in the script.
The next part of the script is the following code:
if (GetQueuedMoveCount 0 eq)
OMG SO MUCH NEW STUFF!!
Yeah that line introduced much new stuff, but don't panic, I'll explain everything, and for persons who have coded before, this should be really easy to grasp.
The first thing you see here is the small little word if, and it's quite self explanatory what it means, it checks if something is true, but how?
That's where the things inside the parentheses comes in, depending if the things inside the parenthesis works together, then it's true what says in there and the small if says “Hey this seems correct, then i better start doing something!”
But how do we know what's written in there and how the if statement sees it's true, it's rather easy actually. What we simply do is put in two values and check if they are true. So we have the two values of 0 and the word GetQueuedMoveCount. 0 is quite self explanatory what it means, but the other stuff, what does it mean?
The GetqueuedMoveCount is a command that'll correspond to the number of current moves you have queued in the movement queue. What that tells you is whenever you create a move, it's stored in a queue and that command corresponds to the number of move commands currently in the queue.
The last little thing int that row is eq, and what it simply does is that it takes the two last values given in the core and says if they are the same or not. If they are the same, it'll give you the true value and if they're no the same then they'll give you the value false.
Those two values will then in turn tell the if statement if it should do anything or just stay there and look pretty.
So what happens when the if statements gets the true value, what defines what to happen?
The definition of the things that'll happen is everything below the if statement and the statement called endif, and all the code looks like this in the current script:
if (GetQueuedMoveCount 0 eq) QueueMove(RandCoords <-Speed) SetCreeper(CurrentCoords <-Strength) endif
So we have a lot of new stuff, but from what is mentioned earlier and from the names of the commands, this should be rather easy to figure out what is means.
that simple row of line is what creates a movement command and moves it to a random location. In the parenthesis i entered two things, RandCoords and <-Speed.
RandCoords gives the move a random x coordinate and a random y coordinate and the <-Speed line gives the number of the Speed variable and sets it as the speed the emitter will move in.
The next row with something in it is:
In that code you create creeper. To create creeper you have to give it coordinates to spawn at and the amount of creeper to spawn there. To give the coordinates i put the command CurrentCoords down and that'll give me the current coordinates of our emitter and after that i put down the value of our Strength variable.
The last row is:
That row simply states that the code after this is not affected by the outcome of this earlier if statement.
That was all the code needed and here you have it with all the parts together:
$Speed:3 $Strength:50 if (GetQueuedMoveCount 0 eq) QueueMove(RandCoords <-Speed) SetCreeper(CurrentCoords <-Strength) endif
And now to make the script actually effect a unit!
In the image above i show a very crucial part, the compiling of a script! Now when you have very nicely have created and saved your script, just press the button to compile and it'll be performed automatically but the client, no worries!
This was all for me for this time, hope you enjoyed and learned something! :)
Only read this if you want some extra information.
If you declare a variable as floating point, so:
You can use floating point values in the game when choosing the variables! (#5 of the last image above)