Give Player Vehicle command.
#1

Dear people,

My problem is, when i give a vehicle to a player, it won't notice the name. But the ID. I need to get player names.


Here's my code.

Код:
CMD:givepv(playerid, params[])
{
	if(!IsAdmin(playerid, 1)) return SendClientMessage(playerid, COLOR_RED, "You are not admin!");
	if(!IsPlayerSpawned(playerid)) return SendClientMessage(playerid, COLOR_RED, "You can't use this command now!");
	new model[32], modelid, giveplayerid, color1, color2;
	if(sscanf(params, "dsdd", giveplayerid, model, color1, color2))
		return SendClientMessage(playerid, COLOR_GREY, "USAGE: /addv [playerid] [model] [color1] [color2]");
	if(!IsPlayerConnected(giveplayerid)) return SendClientMessage(playerid, COLOR_RED, "Player isn't connected.");
	if(IsNumeric(model)) modelid = strval(model);
	else modelid = GetVehicleModelIDFromName(model);
	if(modelid < 400 || modelid > 611) return SendClientMessage(playerid, COLOR_RED, "Invalid model ID!");
	if(color1 < 0 || color2 < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
	if(GetPlayerVehicles(giveplayerid) >= MAX_PLAYER_VEHICLES)
	{
		ShowErrorDialog(playerid, "This player can't have any more vehicles. Max: " #MAX_PLAYER_VEHICLES );
		return 1;
	}
	new Float:X, Float:Y, Float:Z, Float:angle;
	GetPlayerPos(playerid, X, Y, Z);
	GetPlayerFacingAngle(playerid, angle);
	X += floatmul(floatsin(-angle, degrees), 4.0);
	Y += floatmul(floatcos(-angle, degrees), 4.0);
	for(new i=1; i < MAX_DVEHICLES; i++)
	{
		if(!VehicleCreated[i])
		{
			new msg[128];
			VehicleCreated[i] = VEHICLE_PLAYER;
			VehicleModel[i] = modelid;
			VehiclePos[i][0] = X;
			VehiclePos[i][1] = Y;
			VehiclePos[i][2] = Z;
			VehiclePos[i][3] = angle+90.0;
			VehicleColor[i][0] = color1;
			VehicleColor[i][1] = color2;
			VehicleInterior[i] = GetPlayerInterior(giveplayerid);
			VehicleWorld[i] = GetPlayerVirtualWorld(giveplayerid);
			GetPlayerName(giveplayerid, VehicleOwner[giveplayerid], sizeof(VehicleOwner[]));
			valstr(VehicleOwner[i], giveplayerid);
			VehicleNumberPlate[i] = DEFAULT_NUMBER_PLATE;
			for(new d=0; d < sizeof(VehicleTrunk[]); d++)
			{
				VehicleTrunk[i][d][0] = 0;
				VehicleTrunk[i][d][1] = 0;
			}
			for(new d=0; d < sizeof(VehicleMods[]); d++)
			{
				VehicleMods[i][d] = 0;
			}
			VehiclePaintjob[i] = 255;
			VehicleLock[i] = 0;
			VehicleAlarm[i] = 0;
			UpdateVehicle(i, 0);
			SaveVehicle(i);
			format(msg, sizeof(msg), "You gave ID:(%d) a car.", giveplayerid);
			SendClientMessage(playerid, COLOR_WHITE, msg);
			return 1;
		}
	}
	SendClientMessage(playerid, COLOR_RED, "Can't add any more vehicles!");
	return 1;
}

Thank you.

Mariooo
Reply
#2

this ?

Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(giveplayerid,name,MAX_PLAYER_NAME);
format(msg, sizeof(msg), "You gave player %s ID:(%d) a car.",giveplayerid ,name);
SendClientMessage(playerid, COLOR_WHITE, msg);
Reply
#3

Quote:
Originally Posted by dEcooR
Посмотреть сообщение
this ?

Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(giveplayerid,name,MAX_PLAYER_NAME);
format(msg, sizeof(msg), "You gave player %s ID:(%d) a car.",giveplayerid ,name);
SendClientMessage(playerid, COLOR_WHITE, msg);
When i use this command, the car will be noticed on the player's name. That's what i need.

Now it will show this when entering a vehicle: "This vehicle belongs to 0"

But i need: "This vehicle belongs to Mario"
Reply
#4

Do you want that it will show the player's name who will get vehicle or who will give vehicle
Reply
#5

Quote:
Originally Posted by PrinceKumar
Посмотреть сообщение
Do you want that it will show the player's name who will get vehicle or who will give vehicle
Show the player's name who get the vehicle.
Reply
#6

If yes then use this code
pawn Код:
new string[24], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string)," %s[%d] get a car/vehicle", pname(giveplayerid), giveplayerid);
it is a example if you want this.
Reply
#7

Quote:
Originally Posted by PrinceKumar
Посмотреть сообщение
If yes then use this code
pawn Код:
new string[24], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string)," %s[%d] get a car/vehicle", pname(giveplayerid), giveplayerid);
it is a example if you want this.
Can you explain more or edit my code?

I'll get this warning in my console:

Код:
[20:54:33] Warning: Update data buffer trying to exceed 8189/8192 characters (name: Mario_Leone, field: )
Reply
#8

pawn Код:
new string[24], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string)," %s[%d] get a car/vehicle", pname, giveplayerid);
maybe this should work
Reply
#9

Quote:
Originally Posted by Namer
Посмотреть сообщение
pawn Код:
new string[24], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string)," %s[%d] get a car/vehicle", pname, giveplayerid);
maybe this should work
This is exactly the same what he said.
Reply
#10

nope that's not same try to look at
this

mine
pawn Код:
format(string, sizeof(string)," %s[%d] get a car/vehicle", pname, giveplayerid);

and
his
pawn Код:
format(string, sizeof(string)," %s[%d] get a car/vehicle", pname(giveplayerid), giveplayerid);
giveplayerid is already used then why pname(giveplayerid)?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)