[Tutorial] How to make a personal car
#1

Ok, today I am going to learn you how to create a personal car right in your gamemode. This is really simple: first we create the vehicle's variable:
pawn Код:
new car;//you can name the variable however you want
Then, we will create the vehicle. First of all, take a car ingame, use /save (you can add a comentarry to find the vehicle easier) to save the car's position. After that, go to "My Documents\GTA San Andreas user files\SAMP\savedpositions.txt". The last position saved is always the last line in the .txt file. So, you will find something like "AddStaticVehicle(431, 244, 213, 12, 0, 3, 1) Let me explain you this function:
pawn Код:
AddStaticVehicle(modelid, x, y ,z, zangle, color1, color2);
modelid - the vehicle's model. You can find all the vehicle models used in SAMP here: https://sampwiki.blast.hk/wiki/Category:Vehicle
x - The x coordonate on the map.
y - The y coordonate on the map.
z - The z coordonate on the map.
zangle - The z rotation angle.
color1 - The 1st color of the vehicle.
color2 - The 2nd color of the vehicle.
You copy the whole code with AddStaticVehicle. Now that you have the code for the vehicle, use CTRL+F in your gm to search "OnGameModeInit". Then, paste the code under OnGameModeInit like this:
pawn Код:
public OnGameModeInit()
{
    car = paste the code here
    you'll see other codes here
    return 1;
}
Now, we have created the vehicle. But everyone can enter the car, this doesn't make it personal. So, let's do it. Search for 'OnPlayerEnterVehicle' in your gm and here we go. First we need to get the player's name. We create a variable for that:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new sendername[MAX_PLAYER_NAME];
    return 1;
}
After that, we get the player's name using the variable we've created before:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    return 1;
}
We got the player's name, now we check if the vehicle the player entered is the one you've created:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(vehicleid == car)
    {
    }
    return 1;
}
OK, now let's check the player's name. Instead of "Owner's name" write the nickname of the one you want to own that car.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(currveh == car)
    {
        if(strcmp(sendername, "Owner's name", false) == 0)
        {
        }
    }
    return 1;
}
Done, but now we have to do something when the player enters the car. If the owner's name is the player's one, we do nothing(return 1; ) Else, we will remove the player from the vehicle and we'll send him a message:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new sendername[MAX_PLAYER_NAME];
    new Float:x, Float:y, Float:z;//we create some variables for getting the player's positin
    GetPlayerPos(playerid, x, y, z);//we get the player's position using the variables we've created
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(currveh == car)
    {
        if(strcmp(sendername, "Owner's name", false) == 0)
        {
            SetPlayerPos(playerid, x, y, z);//we set the player's position to his initial one
            SendClientMessage(playerid, 0xFF0000FF, "This vehicle belongs to Owner's name, you don't have the keys!");
        }
        else
        {
            return 1;
        }
    }
    return 1;
}
I hope I helped you and if you have any problem just tell me here.
Reply


Messages In This Thread
How to make a personal car - by DiGiTaL_AnGeL - 09.01.2013, 21:28
Re: How to make a personal car - by InActtive™ - 10.01.2013, 00:53
Re: How to make a personal car - by DiGiTaL_AnGeL - 10.01.2013, 09:10
Re: How to make a personal car - by Vince - 10.01.2013, 09:18
Re: How to make a personal car - by DiGiTaL_AnGeL - 10.01.2013, 13:36
Re: How to make a personal car - by Mr.Anonymous - 10.01.2013, 20:18
Re: How to make a personal car - by DiGiTaL_AnGeL - 09.02.2013, 18:19
Re: How to make a personal car - by [WA]iRonan - 11.02.2013, 13:17
Re: How to make a personal car - by DiGiTaL_AnGeL - 11.02.2013, 15:50
Re: How to make a personal car - by DiffeReNt - 17.02.2013, 09:18

Forum Jump:


Users browsing this thread: 1 Guest(s)