|
Welcome to the powerups tutorial. In this we shall be talking through different powerups, and creating a respawning powerup like the ones you get in the original GTA. Firstly I've setup a basic mission file;
10 (52,32,1) PLAYER 0 0
15 (52,32,1) TRIGGER 1000 0
-1
0 DONOWT 0 0 0 0 0
1000 STARTUP 15 20000 -1 0 0
-1
If you don't understand this code, then I suggest you take a look at the 7 Days tutorial that will take you through these basics. Line 1000 is run straight away, as there is a trigger on the square the player stands on that goes to line 1000. The STARTUP line will jump straight to line 20000, where we'll turn on all our POWERUPs.
There are loads of powerups, each with it's own numerical value. There's the four guns plus 6 powerups and the info sign. Here's a list of them all and their respective number;
- 1 - Pistol
- 2 - Machine Gun
- 3 - Rocket Launcher
- 4 - Flame Thrower
- 5 - Empty Box
- 6 - Speedup
- 7 - Empty Box
- 8 - Empty Box
- 9 - Police Bribe
- 10 - Armour
- 11 - Multiplier Up
- 12 - Get out of jail free card
- 13 - Extra Life
- 14 - Info sign (no crates)
- 15 - Extra Life
- 16>- Empty Box
All but the info sign are stored in crates. To create a powerup, you need to define the powerup using the POWERUP line in the declarations, then turn it 'on' using the POWERUP_ON line in the mission code. Here's an example;
2000 (50,32,1) POWERUP 1 49
The 1 represents the the powerup type - in the case, a pistol. The second variable can represent lots of things. It the powerup is a gun (powerups 1 to 4) then it represents either the ammo when you pick it up (maximum of 99) or, if greater than 99, a timer used for kill frenzies. Put it on 100 and the player will get infinite bullets. We won't go in to the timer thing yet - that's for another tutorial.
If the powerup is number 14, an info sign, then the number represents which 'help' line in the FXT file it will display when they player gets it. So if you use;
2000 (50,21,1) POWERUP 14 5
Then is will display a help sign that, when you get it, will display the message [help5] that's in the FXT file.
If you use any other powerup, then the second parameter can be left as 0.
Now what we have to do is turn 'on' the powerup. Without doing this, the powerup wouldn't 'exist' in the game. It's simply a case of using the POWERUP_ON line;
20000 POWERUP_ON 2000 0 0 0 0
29999 DONOWT 0 0 0 0 0
Line 20000 just turns on the powerup in line 2000, and line 29999 stop the flow of code. This leaves lots of space for more powerups in the future. Now we've done this, test out your mission. You'll have a working powerup!
What would be good now is to create a respawn powerup, like they've got in the real games. Note that when you respawn, there's usually a pistol waiting to be picked up. This is because the POWERUP is recreated after a short time limit, so that when you respawn in a hospital or police station then there's a gun waiting for you. We'll do the same with our powerup. Firstly, we need a trigger to go off when the player gets the powerup. Unfortunately there's not a specific trigger when the player collects a powerup - but what we can do is do a TRIGGER When the player is on the same square as the powerup. We've done this with;
2001 (50,32,1) TRIGGER 30000 0
This will run line 30000 once the player gets on co-ordinates (50,32,1). Although this doesn't mean the player has actually taken the powerup (because they're on crates you could have walked over it and not punched the crate, thus not taking the powerup) it's a good start. We then do the code at line 30000. This is the code I've used;
30000 DISABLE 2001 0 0 0 0
30001 IS_POWERUP_DONE 2000 0 30005 -1 0
30002 SURVIVE 0 0 0 500 0
30003 GENERAL_ONSCREEN 2000 30003 0 0 0
30004 POWERUP_ON 2000 0 0 0 0
30005 ENABLE 2001 -1 0 0 0
The first thing you should do with all triggers is to disable them - otherwise they'll keep retriggering. Line 30000 simply disables the trigger in line 2001. We then check to see if the powerup in question is done. If it's not, then we want to quit this procedure, but if it is we want to do the respawn code. IS_POWERUP_DONE checks at that moment whether or not the powerup in line 2000 is 'done' - i.e. has it been taken. It if has, then it goes to success - the '0' means go on to the next line. If it's not done, then we go to line 30005, that re-enables the trigger and stops the procedure. The procedure will keep triggering until the powerup is done, and we get to line 30002.
We then want to wait for a while. We don't want the powerup to respawn straight away - that'd just look silly. SURVIVE halts the execute of code for a certain number of 'ticks' - in this case 500. There are exactly 25 'ticks' in a second, so 500 is 20 seconds. In the original game they seem to vary between 500 and 1000 of these ticks - 20 to 40 seconds. Depending on how hard to you want your map, chose a number that suits you.
Once the SURVIVE is up, I use a cunning little peice of code in line 30003. This isn't exactly compulsorary (they don't use it in the original, I made this up myself :P). Basically it sets up a loop that continues to loop around line 30003 until the player can't see the powerup. That way, it won't suddenly 'appear' on the game screen. GENERAL_ONSCREEN checks to see if the player and object 2000 - our powerup - are on the screen together. If they are, then it goes to success - in this case 30003. Therefore it'll keep running line 30003 until it goes to fail - until the powerup is offscreen. Once they're offscreen then it goes to line 30004, that simply turns back on the powerup. Line 30005 reenables the trigger so that it will do it all again when the player comes back to take the powerup.
There ya go - one working respawning powerup. But what's that? You want to make it more complicated for yourself? You want it so it will only respawn a set number of times, and then it wont respawn again? Well ok... if you insist....
For this we'll need a counter. For an introduction on counters, see Day 5 of the mission code tutorial. We'll setup a counter in the declarations with a starting value of 0;
2002 (0,0,0) COUNTER 0 0
Now what we want to do is increment this counter every time it respawns. When the counter gets to 3, we want to stop enabling the trigger, so it can't respawn again. Take a look at the new code;
30000 DISABLE 2001 0 0 0 0
30001 IS_POWERUP_DONE 2000 0 30006 -1 0
30002 SURVIVE 0 0 0 500 0
30003 GENERAL_ONSCREEN 2000 30003 0 0 0
30004 POWERUP_ON 2000 0 0 0 0
30005 INCCOUNT 2002 -1 0 3 0
30006 ENABLE 2001 -1 0 0 0
The main change is inclusion of line 30005. This line does two things. It first increments the counter in line 2002. It then compares the counter with 3. If it equals 3, it goes to success - if it doesn't equal 3, it goes to fail. The -1 stops the code carry on - this means that the trigger won't re-enable. This occurs when the counter equals 3. Otherwise, it goes on to line 30006 to re-enable the counter.
Hey presto - one respawning powerup that has a set limit of respawns! Feel free to use this in your code, or play around with it to suit your needs. You'll need a powerup, a trigger, a counter, a powerup_on and new set of lines 30000-30006 for each powerup you want to respawn. If you make any interesting changes to this code, or if you've got further questions or problems, please feel free to email me!
|