09.04.2010, 00:13
**Note: I know this Tut exists already, however i would like to write my own version because i didn't like i saw from other people.**
Introduction
This tutorial will show you how to spawn already modded cars into your script. This will mean that you can have a car that is already modded from the transfenders without you having to go do it yourself all the time. This is the result you will get from this tutorial:
This vehicle is fully modded with a paint job, spoiler, rims, roof, front bumper, back bumper. These modifications are from the mod shop in SF although they automatically go onto the car when the gamemode starts.
Part 1 - Adding the vehicle to begin with..
Okay, we will be making the car that i showed above so i will start of by going in game, using the /save command while in that position with my elegy (the vehicle i used). The co-ords i have gotten for my vehicle are this (after i changed it a bit to AddStaticvehicleEx):
This car in game will just be a basic elegy that is white with no mods on it at all. In order for us to add the mods to this vehicle we want to define what the vehicle is called (in the script). So at the top of your script you need to add this:
This is a new variable which will store the ID of the vehicle you just added! (in basic terms..it is what your vehicle is called). Now you must add this to yuor AddStaticVehicleEx code:
This tells the script that the vehicle that we have added is called 'moddedCar'. Now we can use this name later on in the script.
Part 2 - Adding the components..
Okay, so now we have given the car a name in the script. The next thing we need to do is give this vehicle some "components". A component is just a car part, such as a spoiler, front bumper, NOS e.t.c. To add these it is really simple, you just need to use one function called:
The carID is the ID of the vehicle we want to give the component to (the name of the vehicle, in this case "moddedCar". The componentID is the ID of the car part which you wish to give to your vehicle. A list of component ID's is found here: https://sampwiki.blast.hk/wiki/Car_Component_ID. For this example i am going to be using these:
This will give us all of our components we need. However we also need a paint job. So we use a different function for this called "ChangeVehiclePaintjob(carid,paintjobid);".. the Id we are using is either 0,1 or 2. In this example i am using 0. So i will add this to the TOP of the list of components. We now have this:
We are going to add these lines of code to the Bottom of "OnGameModeInit"
Part 3 - Adding them to OnVehicleSpawn..
Okay, so now if you test your GM the vehicle should work perfectly and you have your vehicle. However if you crash your car and it respawns. The mod's will be gone. This is because the vehicle components was added when the Gamemode initiated. so therefore they wont add again if your car explodes and has to respawn. In order to fix this we use a calledback (a public) called OnVehicleSpawn. It passes one parameter through which is the car id.. I will show you my OnVehicleSpawn callback and you can just copy and paste it somewhere in your code..Although you MUST remember that if yuo add a componenent on the ongamemodeinit section, you must add it here.
Part 4 - Finished..
Well that is it. We are finished. Your vehicle should now be modded when you go in game. The only thing i would like to remind everyone that when you choose your component ID, make sure that it is for the correct vehicle otherwise you may run into some problems.
If there is any mistakes in this tut or i have not made sense on a section, feel free to reply to this thread or PM me....Now i am off to watch Russel Howards good news
-Darren
Introduction
This tutorial will show you how to spawn already modded cars into your script. This will mean that you can have a car that is already modded from the transfenders without you having to go do it yourself all the time. This is the result you will get from this tutorial:
This vehicle is fully modded with a paint job, spoiler, rims, roof, front bumper, back bumper. These modifications are from the mod shop in SF although they automatically go onto the car when the gamemode starts.
Part 1 - Adding the vehicle to begin with..
Okay, we will be making the car that i showed above so i will start of by going in game, using the /save command while in that position with my elegy (the vehicle i used). The co-ords i have gotten for my vehicle are this (after i changed it a bit to AddStaticvehicleEx):
Code:
AddStaticVehicleEx(562,1361.9299,-1660.2322,13.0449,317.4974,1,1,600000);
Code:
new moddedCar;
Code:
moddedCar = AddStaticVehicleEx(562,1361.9299,-1660.2322,13.0449,317.4974,1,1,600000);
Part 2 - Adding the components..
Okay, so now we have given the car a name in the script. The next thing we need to do is give this vehicle some "components". A component is just a car part, such as a spoiler, front bumper, NOS e.t.c. To add these it is really simple, you just need to use one function called:
Code:
AddVehicleComponent(carID, ComponentID);
Code:
AddVehicleComponent(moddedCar, 1035); // roof AddVehicleComponent(moddedCar, 1079); // rim AddVehicleComponent(moddedCar, 1037); // exhaust AddVehicleComponent(moddedCar, 1039); // side AddVehicleComponent(moddedCar, 1172); // front AddVehicleComponent(moddedCar, 1148); // back AddVehicleComponent(moddedCar, 1146); // Spoiler
Code:
ChangeVehiclePaintjob(moddedCar,0); // paint job AddVehicleComponent(moddedCar, 1035); // roof AddVehicleComponent(moddedCar, 1079); // rim AddVehicleComponent(moddedCar, 1037); // exhaust AddVehicleComponent(moddedCar, 1039); // side AddVehicleComponent(moddedCar, 1172); // front AddVehicleComponent(moddedCar, 1148); // back AddVehicleComponent(moddedCar, 1146); // Spoiler
Part 3 - Adding them to OnVehicleSpawn..
Okay, so now if you test your GM the vehicle should work perfectly and you have your vehicle. However if you crash your car and it respawns. The mod's will be gone. This is because the vehicle components was added when the Gamemode initiated. so therefore they wont add again if your car explodes and has to respawn. In order to fix this we use a calledback (a public) called OnVehicleSpawn. It passes one parameter through which is the car id.. I will show you my OnVehicleSpawn callback and you can just copy and paste it somewhere in your code..Although you MUST remember that if yuo add a componenent on the ongamemodeinit section, you must add it here.
Code:
public OnVehicleSpawn(vehicleid) { if(vehicleid == moddedCar){ ChangeVehiclePaintjob(moddedCar,0); // paint job AddVehicleComponent(moddedCar, 1035); // roof AddVehicleComponent(moddedCar, 1079); // rim AddVehicleComponent(moddedCar, 1037); // exhaust AddVehicleComponent(moddedCar, 1039); // side AddVehicleComponent(moddedCar, 1172); // front AddVehicleComponent(moddedCar, 1148); // back AddVehicleComponent(moddedCar, 1146); // Spoiler } return 1; }
Well that is it. We are finished. Your vehicle should now be modded when you go in game. The only thing i would like to remind everyone that when you choose your component ID, make sure that it is for the correct vehicle otherwise you may run into some problems.
If there is any mistakes in this tut or i have not made sense on a section, feel free to reply to this thread or PM me....Now i am off to watch Russel Howards good news
-Darren