A simple mission
Like I promised, we are going to make a simple mission. First you have to make a good plan for the mission. In our example, we will spawn a car with an arrow above it. When the player gets in the car, the arrow will disappear, and the sphere where you have to drive to will appear. The player will have a baseball bat. The car is almost wrecked, and with the slightest touch it will explode. When the player is in the sphere, there have to spawn an actor, also with a baseball bat. When he sees the player, he will attack. When the actor is killed, the mission is passed, and you will get a text and $10,000. The marker will also disappear.
Of course this isn't a very difficult mission, but you can make it more amusing. For example, when you add a timelimit: you have to drive fast, but may not hit anything! Or that when you get out of the car, there will be another marker on the car. Or that mission failed is when you are dead. But we will start small, with this mission!
We have an idea, so we will begin coding. Like usual, we will start with a stripped file:
First we will load everything and check if it is loaded. The actor (enemy) doesn't have to spawn, the car does. The bat has toi be given to the player, lateron also to the actor. Loading the models and spawning the car:
0247: load_model #GREENWOO
0247: load_model #bat
0247: load_model #BFYST
8248: not model #GREENWOO available
8248: not model #bat available
8248: not model #BFYST available
wait 0 ms
0674: set_car_model #GREENWOO numberplate "ABCDEFGH"
00A5: $greenwood = create_car #GREENWOO at 2458.2483 -1659.0264 13.3047
0224: set_car $greenwood health_to 250
What are we missing before player has to drive? The player has to get a baseball bat and there has to be a marker above the car:
> 0186: $m1 = create_marker_above_car $greenwood
01B2: give_actor $PLAYER_ACTOR weapon 5 ammo 10 // Load the weapon model before using this
01B9: set_actor $PLAYER_ACTOR armed_weapon_to 5
NOw we have to wait for the player to enter the car. What happens next? You have to go to the marked place, where there should be a sphere. The marker of the car has to disappear.
until Actor.InCar($PLAYER_ACTOR, $greenwood)
0004: $coordinate_x = 2100.9604
0004: $coordinate_y = -1366.8369
0004: $coordinate_z = 23.9844
$coordinate = Marker.CreateIconAndSphere(0, $coordinate_x, $coordinate_y, $coordinate_z)
What can happen while the player is driving to the sphere? The car can be wrecked! When the car is wrecked, there has to spawn a new car in the beginning and the player has to go back to get it. The check has to continu until the player has reached the sphere. This is perhaps a bit more complex code, but when you give it a good look, I'm sure you can make it next time by yourself!
wait 0 ms
0119: car $greenwood wrecked
wait 0 ms
01AE: car $greenwood sphere 0 near_point $coordinate_x $coordinate_y radius 5.0 5.0 stopped
When the car is wrecked, jump @MODEL_SPAWN. Then you will start all over, by spawning a new car with a new arrow. When the car isn't wrecked, it will jump to MODEL_END, the second label. There it will check if the car is in the sphere. You have to make this a loop, because when you are doing it only once, the car won't be at the sphere yet.
So when the car is in the neighbourhood of the sphere (radius 5.0), and the car stopped, then the code may continue. When it isn't, the code goes back to MODEL_WRECKED and check again if the car is wrecked. This continues until the car is in the sphere.
When the player is in the car in the sphere, the sphere and the marker have to disappear. Also you have to spawn an actor with baseball bat, which had to attack the player.
10@ = Actor.Create(CIVFEMALE, #BFYST, 2094.3499, -1342.9515, 23.9844)
Actor.Angle(10@) = 88.44
0187: $marker = create_marker_above_actor 10@
actor.Health(10@) = 250
01B2: give_actor 10@ weapon 5 ammo 1000 // Load the weapon model before using this
01B9: set_actor 10@ armed_weapon_to 5
05E2: AS_actor 10@ kill_actor $PLAYER_ACTOR
Every part of this code has been explained already in previous tutorials, if it's unclear you can look it up there.
Finally, when the actor is dead, the mission is passed. You have to play a sound, put a text on the screen and add some money. The marker on the actor has to be destroyed and the models have to be unloaded:
wait 0 ms
0394: play_music 1
01E3: show_text_1number_styled GXT 'M_PASS' number 10000 time 5000 style 1 // MISSION PASSED!~n~~w~$~1~
Player.Money($PLAYER_CHAR) += 10000
0249: release_model #GREENWOO
0249: release_model #BAT
0249: release_model #BFYST
Every part of this code has also been explained in previous tutorials.
Don't forget to add the "end_thread" to stop the thread. Then you are finished.
When you put this all together: Click. Now you can try your mission! Perhaps it isn't the most difficult mission, but who cares? You have to start small!
So it shows, that with some simple codes, you can already make a nice mission.
The limitions of the posibilities are not your coding-skills, but your creativity.