Right.
I didn't have time for this earlier, hence the flippant reply.
First of all, let's think out our code.
Before we write anything down, it's best to get a good idea in our heads of how we're going to make our code work.
So.
What we want is 'A shooter whirlwind which fires every 60 frames'.
Let's have a think of what we're going to be able to do to make this work.
The most obvious thing we'll need is to create the whirlwind.
We'll also need a 60 frame time delay.
Those are perhaps the most obvious two.
There are, however, some other important things that we will definately need for our code to work.
Because we want it to happen every 60 frames, we need something to keep repeating iterations of our code.
We also need somewhere for our whirlwind to start from, and somewhere for it to be going to.
The final thing, which is perhaps the least obvious to someone who hasn't coded in ZScript before is something that will let the rest of the system run inbetween the functions of our script.
That's handled in the 60 frame time delay though, so we won't worry about it this time.
Now we have some pretty good ideas as to what we need in our code, so let's get those ideas down.
For the purpose of this explanation, we're going to have the whirlwind start where the ffc is, and fire off in a random direction.
[pseudocode]
start a loop
create a whirlwind
place the whirlwind in its starting position
pick a random direction for the whirlwind to go in
delay for 60 frames
go back to the start of the loop
[/pseudocode]
Now we have a clear structure for our code to take, and all that's left for us to insert is the proper ZScript functions and syntax.
Off we go then:
ffc script Whirlwind{ //Firstly, declare a script
void run(){ //Every script's functions start in void run
while(true){ //This creates our loop. 'while' will continue to loop the code in the following braces - {} - while the condition in its brackets - () - is true. 'true' is always true (as you may have guessed), so 'while(true){' will continue to loop the following code while the script runs.
eweapon Whirlwind = Screen->CreateEWeapon(EW_WIND); //Here we create our whirlwind. Whirlwinds are an 'eweapon', so we create them like so
Whirlwind->X = this->X; //Now we place the whirlwind on top of our ffc.
Whirlwind->Y = this->Y; //We access the whirlwind's 'X' and 'Y' variables with the little '->' arrow operator, and we set them to the ffc's ('this' is a pre-declared ffc, refering to the ffc to which the script is attached) X and Y values.
Whirlwind->Dir = Rand(3); //We then access the whirlwind's 'Dir' (direction) variable. 'Rand' picks a random number for us, so now our whirlwind will head off in a random direction
Waitframes(60); //Now we wait for 60 frames
} //Tell our loop where to end. The code will now re-run from our while loop's left brace each time it gets to this point
} //End void run
}//End the script