09.01.2013, 21:28
(
Последний раз редактировалось DiGiTaL_AnGeL; 01.04.2013 в 14:06.
Причина: updated
)
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:
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:
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:
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:
After that, we get the player's name using the variable we've created before:
We got the player's name, now we check if the vehicle the player entered is the one you've created:
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.
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:
I hope I helped you and if you have any problem just tell me here.
pawn Код:
new car;//you can name the variable however you want
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.
pawn Код:
public OnGameModeInit()
{
car = paste the code here
you'll see other codes here
return 1;
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new sendername[MAX_PLAYER_NAME];
return 1;
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new sendername[MAX_PLAYER_NAME];
GetPlayerName(playerid, sendername, sizeof(sendername));
return 1;
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new sendername[MAX_PLAYER_NAME];
GetPlayerName(playerid, sendername, sizeof(sendername));
if(vehicleid == car)
{
}
return 1;
}
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;
}
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;
}