PAWN Tutorial 2
OK, if you have read Part 1 you should have a very basic deathmatch or team-deathmatch with spawns placed wherever you want, so lets add some vehicles. Most of the commands in PAWN do pretty much exactly as they're named, we want to add a vehicle so lets look for vehicle commands:
If you click on either of these and look in the status bar (the bar at the bottom of the editor) you will see their syntax (what information/parameters you need to give them to work):
[a_samp.inc] native CreateVehicle(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2); [a_samp.inc] native AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2);
Now they both look equally as good, but this is where prior knowledge comes in, CreateVehicle only places one car ingame, AddStaticVehicle creates a vehicle spawn, so when the car is destroyed or desynched it will reappear back where you placed the spawn. These need to be created at the start of the game so you would place this in your "OnGameModeInit()" callback.
The modelid/vehicletype numbers can be found in your vehicles.ide file, the Floats are just non whole numbers, basically co-ordinates and angles, and the color numbers can be found in your carcols.dat file, look for the reference number for the color you want, so "black" is "0", "taxi yellow" is "6", "currant blue poly" is "32" etc, "-1" means random (from that car's default colors, found lower in the carcols.dat file). If you want to get the position for a vehicle, go into debug mode, select your vehicle, get in and type "/save" then open up "savedpositions.txt" and copy the line. If you want to spawn a vehicle in debug mode, type "/v <vehicleid>" ingame and that vehicle will spawn (vehicleid is taken again from vehicles.ide), or type "/vsel" to bring up the vehicle command screen.
I got these co-ordinates:
2040.2279, 1344.4127, 11.0, 3.5436
Note: These are called floats, 11.0 is a float despite being whole, any whole number being used as a float must have a trailing ".0" to denote it as a float. These numbers are in the english format of using a decimal point ("."), commas are used to separate parameters. Also remember the 4th number is angle, so if we now add the following line to the game mode in OnGameModeInit, recompile and test, we will get a bright pink infernus outside the casio which is the default spawn position for cj. Note: on a car which uses the secondary color (such as a cop car (id 596)) this would be a pink and blue car as that is the secondary color.
AddStaticVehicle(411, 2040.2279, 1344.4127, 10.6719, 3.5436, 126, 54);
Now you can easilly go about saving positions and creating as many cars as you want (up to an engine defined limit of 254 individual cars, 50 different types of car). The spawns saved to the file will have "-1, -1" as the colors by default.