SA-MP Forums Archive
[Tutorial] How to make a personal car - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make a personal car (/showthread.php?tid=406309)



How to make a personal car - DiGiTaL_AnGeL - 09.01.2013

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.


Re: How to make a personal car - InActtive™ - 10.01.2013

I was just searching for something similar to this for my new gamemode. Thanks a million bro. I'll let you know if I stumble upon any errors. GJ!


Re: How to make a personal car - DiGiTaL_AnGeL - 10.01.2013

Quote:
Originally Posted by InActtive™
Посмотреть сообщение
I was just searching for something similar to this for my new gamemode. Thanks a million bro. I'll let you know if I stumble upon any errors. GJ!
I'm glad I could help you!


Re: How to make a personal car - Vince - 10.01.2013

Obviously not tested, because it won't work. You have the 'vehicleid' parameter in the header of OnPlayerEnterVehicle. Use it. Using GetPlayerVehicleID in OnPlayerEnterVehicle will always return 0 because the player isn't in the vehicle yet. Furthermore, you have not defined newstate. It looks to me like you mixed up OnPlayerEnterVehicle with OnPlayerStateChange.


Re: How to make a personal car - DiGiTaL_AnGeL - 10.01.2013

Quote:
Originally Posted by Vince
Посмотреть сообщение
Obviously not tested, because it won't work. You have the 'vehicleid' parameter in the header of OnPlayerEnterVehicle. Use it. Using GetPlayerVehicleID in OnPlayerEnterVehicle will always return 0 because the player isn't in the vehicle yet. Furthermore, you have not defined newstate. It looks to me like you mixed up OnPlayerEnterVehicle with OnPlayerStateChange.
Posted at 01:40, I was sleepy. Modified, thanks for notifying.


Re: How to make a personal car - Mr.Anonymous - 10.01.2013

Why it doesn't work with my name? I tried "Mr.Anonymous" but it doesn't work


Re: How to make a personal car - DiGiTaL_AnGeL - 09.02.2013

Quote:
Originally Posted by Mr.Anonymous
Посмотреть сообщение
Why it doesn't work with my name? I tried "Mr.Anonymous" but it doesn't work
Updated, try now. I remembered that I was a bit drunk when I made the tutorial. =))


Re: How to make a personal car - [WA]iRonan - 11.02.2013

Nice job,

*[WA]iRonan throws a +REP to DiGiTaL_AnGeL


Re: How to make a personal car - DiGiTaL_AnGeL - 11.02.2013

Thanks


Re: How to make a personal car - DiffeReNt - 17.02.2013

nice.....+rep