SA-MP Forums Archive
How do I put a players initials in a string? - 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)
+--- Thread: How do I put a players initials in a string? (/showthread.php?tid=612298)



How do I put a players initials in a string? - Unfriendly - 16.07.2016

For my vehicle plate system I'd like to set it up so that a players tag is made using his/her first and last initials,followed by the vehicle ID when a player buys a vehicle.

Example: John_Smith buys vehicle id 420 (not model id, but vehicle id)

His vehicle plate: JS420


Re: How do I put a players initials in a string? - Stinged - 16.07.2016

Код:
new str[24], pos;
GetPlayerName(playerid, str, 24);
pos = strfind(str, "_");
if (pos != -1)
{
    new vehicleid = GetPlayerVehcileID(playerid);
    format(str, sizeof (str), "%c%c%i", str[0], str[pos+1], vehicleid);
    SetVehicleNumberPlate(vehicleid, str);
}



Re: How do I put a players initials in a string? - Vince - 16.07.2016

PHP код:
format(platesizeof plate"%c%c%03d"name[0], name[strfind(name"_") + 1], vehicleid
Something like that.

Edit: ^ we had the same idea. ^_^


Re: How do I put a players initials in a string? - Unfriendly - 16.07.2016

Thanks so much for the replies. Here's what I have now.
I get this error when I compile : error 047: array sizes do not match, or destination array is too small

edit: I put stars near the part of the code you actually need to read.

Код:
	if(dialogid == DIALOG_VEHICLE_BUY)
	{
		if(response)
		{
			if(GetPlayerVehicles(playerid) >= MAX_PLAYER_VEHICLES)
			{
				ShowErrorDialog(playerid, "You can't buy any more vehicles! Max: " #MAX_PLAYER_VEHICLES );
				return 1;
			}
			new id = GetPVarInt(playerid, "DialogValue1");
			if(GetPlayerMoney(playerid) < VehicleValue[id])
			{
				ShowErrorDialog(playerid, "You don't have enough money to buy this vehicle!");
				return 1;
			}
			new freeid = GetFreeVehicleID();
			if(!freeid)
			{
				ShowErrorDialog(playerid, "Vehicle dealership is out of stock!");
				return 1;
			}
			GivePlayerMoney(playerid, -VehicleValue[id]);
			new dealerid = strval(VehicleOwner[id]);
			VehicleCreated[freeid] = VEHICLE_PLAYER;
			VehicleModel[freeid] = VehicleModel[id];
			VehiclePos[freeid] = DealershipPos[dealerid];
			VehicleColor[freeid] = VehicleColor[id];
			VehicleInterior[freeid] = VehicleInterior[id];
			VehicleWorld[freeid] = VehicleWorld[id];
			VehicleValue[freeid] = VehicleValue[id];
			GetPlayerName(playerid, VehicleOwner[freeid], sizeof(VehicleOwner[]));
			new str[24], pos;
*************GetPlayerName(playerid, str, 24);
			pos = strfind(str, "_");
			if (pos != -1)
			{
			    new vehicleid = GetPlayerVehicleID(playerid);
			    format(str, sizeof (str), "%c%c%i", str[0], str[pos+1], vehicleid);
			}
************** VehicleNumberPlate[freeid] = str;
			for(new d=0; d < sizeof(VehicleTrunk[]); d++)
			{
				VehicleTrunk[freeid][d][0] = 0;
				VehicleTrunk[freeid][d][1] = 0;
			}
			for(new d=0; d < sizeof(VehicleMods[]); d++)
			{
				VehicleMods[freeid][d] = 0;
			}
			VehiclePaintjob[freeid] = 255;
			VehicleLock[freeid] = 0;
			VehicleAlarm[freeid] = 0;
			UpdateVehicle(freeid, 0);
			SaveVehicle(freeid);
			new msg[128];
			format(msg, sizeof(msg), "You have bought this vehicle for $%d", VehicleValue[id]);
			SendClientMessage(playerid, COLOR_WHITE, msg);
		}
		else
		{
			new id = GetPVarInt(playerid, "DialogValue1");
			if(GetPlayerVehicleAccess(playerid, id) < 1)
			{
				RemovePlayerFromVehicle(playerid);
			}
		}
		return 1;
	}



Re: How do I put a players initials in a string? - Unfriendly - 16.07.2016

Would you like to work together possibly? Everything else I have works fine. ^^


Re: How do I put a players initials in a string? - Stinged - 16.07.2016

Use this function to copy strings. Don't do something like "string = str"
Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)

or

strcpy(dest[], const source[], dest_size = sizeof dest)
{
    dest[0] = '\0';
    strcat(dest, source, dest_size);
}
And then use
Код:
strcpy(VehicleNumberPlate[freeid], str, 7);
Also, what's the size of VehicleNumberPlate? It needs to be at least 7.


Re: How do I put a players initials in a string? - Unfriendly - 16.07.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Use this function to copy strings. Don't do something like "string = str"
Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)

or

strcpy(dest[], const source[], dest_size = sizeof dest)
{
    dest[0] = '\0';
    strcat(dest, source, dest_size);
}
And then use
Код:
strcpy(VehicleNumberPlate[freeid], str, 7);
Also, what's the size of VehicleNumberPlate? It needs to be at least 7.
Not sure I understand how to implement that into my code.
The size of VehicleNumberPlate is 16

Edit: Nvm I figured it out. LOL.
It compiled. We'll see if it works.

Edit 2: It works flawlessly! Thanks so much.