Add Player's name to car's name?
#1

Hey guys, today I'm puzzled with something I don't even know is possible. I'm have a W.I.P dealership system that stores a player's car to his .ini file, and when he logs in it spawns the car. Now the problem is giving the car a unique ID so that when the player logs in it spawns with a unique ID something like this...
Код:
new PlayerName[MAX_PLAYER_NAME], CarUName[32];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(CarUName, sizeof(CarUName),"%s's%s", PlayerName, PlayerInfo[playerid][CarName]); //Will return Player'sCar
And then spawn the car like this...

Код:
CarUName = CreateVehicle(playerid, PlayerInfo[playerid][CarID], PlayerInfo[playerid][CarX], PlayerInfo[playerid][CarY], PlayerInfo[playerid][CarZ], PlayerInfo[playerid][CarA], PlayerInfo[playerid][CarCol1], PlayerInfo[playerid][CarCol2], 0);
But it gives errors lol, is there a way I can do this?
Reply
#2

I did it otherwise. So, whenever a player buys a car, it makes a .ini file to store all his data. Make a new line named CarID or something. Then, when a player buys a car/connects, you make a new car. But store that under a variable, something like this:

pawn Код:
new carid = CreateVehicle(... //your things here)
Then you write the carid in the .ini file of the player, like:

pawn Код:
INI_WriteInt(File,"CarID", carid);
Something like that. Now the CarID in the player's .ini file is an unique car id! (I think..)
Reply
#3

Did you define CarUName?
I mean like, new CarUName; ?

EDIT: what Da_Noob said, is the easiest way to go I think, you'd better give that a try
Reply
#4

Quote:
Originally Posted by Jari_Johnson*
Посмотреть сообщение
Did you define CarUName?
I mean like, new CarUName; ?
Quote:
Originally Posted by Hyperfire
Посмотреть сообщение
new PlayerName[MAX_PLAYER_NAME], CarUName[32];
Yes, he did.
Reply
#5

Quote:
Originally Posted by DrDoom151
Посмотреть сообщение
Yes, he did.
Ups, my bad :$
Reply
#6

Wont what Da_Noob said only save the car's ID to the player's file? and make the car's id carid?
Reply
#7

When a vehicle is bought, Save it to a .ini file which also stores the following two variables

Players Name (The one who bought it)
Car Name (The cars name)

Then add it to your current enum/loading/saving system.
Now when you load it you could just do
pawn Код:
CarInfo[carid][PlayerName]; //Change this
CarInfo[carid][CarName];//Change this
Then add it to the name:
pawn Код:
format(bla,sizeof(bla), "%s's %s", CarInfo[carid][PlayerName], CarInfo[carid][CarName]");
Reply
#8

Quote:
Originally Posted by Ken97
Посмотреть сообщение
When a vehicle is bought, Save it to a .ini file which also stores the following two variables

Players Name (The one who bought it)
Car Name (The cars name)

Then add it to your current enum/loading/saving system.
Now when you load it you could just do
pawn Код:
CarInfo[carid][PlayerName]; //Change this
CarInfo[carid][CarName];//Change this
Then add it to the name:
pawn Код:
format(bla,sizeof(bla), "%s's %s", CarInfo[carid][PlayerName], CarInfo[carid][CarName]");
Ok now this is what I did...
Код:
new hashpass[129], pCarName[64];
format(pCarName, sizeof(pCarName),"%s'%s", PlayerInfo[playerid][UserName], PlayerInfo[playerid][CarID]);
WP_Hash(hashpass, sizeof(hashpass), inputtext);
if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
{
	SendClientMessage(playerid, 0x00FF00FF,"You have succesfully logged in.\nWelcome back to a Bum's Life!");
(1011)	pCarName = CreateVehicle(PlayerInfo[playerid][CarID], PlayerInfo[playerid][CarX], PlayerInfo[playerid][CarY], PlayerInfo[playerid][CarZ], PlayerInfo[playerid][CarA], PlayerInfo[playerid][CarCol1], PlayerInfo[playerid][CarCol2], 0);
	Finished = 1;
}
and this is what errors I get...
Код:
(1011) : error 033: array must be indexed (variable "pCarName")
That is the error I keep getting.
Reply
#9

pawn Код:
format(pCarName, sizeof(pCarName),"%s'%s", PlayerInfo[playerid][UserName], PlayerInfo[playerid][CarID]); //
This will output the car id not the vehicle's name.

Why not use the GetVehicleName function?


pawn Код:
stock GetVehicleName(vehicleid)
{
    new String[150];
    format(String,sizeof(String),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return String;
}


new VehicleNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
    "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
    "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
    "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
    "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
    "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
    "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
    "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
    "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};




This is what I have in my gm, might help you.
pawn Код:
car= Dealership_AddVehicle(DealershipID, vModel, vPaint, vComponents, vX, vY, vZ, vR, C1, C2);
                    new string5[150];
                   
     format(string5,sizeof(string5),"%s's %s" , VehicleData[car][Owner],GetVehicleName(car));
      new Text3D:ownedby = Create3DTextLabel(string5,0x00FF00FF,0.0,0.0,0.0,300.0,0,0);
Reply
#10

Quote:
Originally Posted by Ken97
Посмотреть сообщение
pawn Код:
format(pCarName, sizeof(pCarName),"%s'%s", PlayerInfo[playerid][UserName], PlayerInfo[playerid][CarID]); //
This will output the car id not the vehicle's name.

Why not use the GetVehicleName function?


pawn Код:
stock GetVehicleName(vehicleid)
{
    new String[150];
    format(String,sizeof(String),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return String;
}


new VehicleNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
    "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
    "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
    "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
    "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
    "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
    "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
    "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
    "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};




This is what I have in my gm, might help you.
pawn Код:
car= Dealership_AddVehicle(DealershipID, vModel, vPaint, vComponents, vX, vY, vZ, vR, C1, C2);
                    new string5[150];
                   
     format(string5,sizeof(string5),"%s's %s" , VehicleData[car][Owner],GetVehicleName(car));
      new Text3D:ownedby = Create3DTextLabel(string5,0x00FF00FF,0.0,0.0,0.0,300.0,0,0);
Im using the GetVehicleNameByModelId function to get the vehicle's name, and my previous code had a typho it should be...
Код:
{
	new hashpass[129], pCarName[64];
	format(pCarName, sizeof(pCarName),"%s'%s", PlayerInfo[playerid][UserName], PlayerInfo[playerid][CarName]);
	WP_Hash(hashpass, sizeof(hashpass), inputtext);
	if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
	{
		SendClientMessage(playerid, 0x00FF00FF,"You have succesfully logged in.\nWelcome back to a Bum's Life!");
		pCarName = CreateVehicle(PlayerInfo[playerid][CarID], PlayerInfo[playerid][CarX], PlayerInfo[playerid][CarY], PlayerInfo[playerid][CarZ], PlayerInfo[playerid][CarA], PlayerInfo[playerid][CarCol1], PlayerInfo[playerid][CarCol2], 0);
		Finished = 1;
	}
	else
	{
		ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","{FF0000}You have entered an Incorrect password!\n{FFFFFF}Please enter your Correct password to login.","Login","Quit");
		return 1;
	}
	return 1;
}
return 1;
Still gives me the error though.

Oh and my Enum looks like this...

Код:
enum PlayerData
{
	UserName[MAX_PLAYER_NAME],
	Password[129],
	Float:PosX,
	Float:PosY,
	Float:PosZ,
	Float:PosA,
	Interior,
	VirtualWorld,
	Skin,
	Wallet,
	Bank,
	CarName[32],
	CarID,
	CarVW,
	CarI,
	Float:CarX,
	Float:CarY,
	Float:CarZ,
	Float:CarA,
	CarCol1,
	CarCol2
}
new PlayerInfo[MAX_PLAYERS][PlayerData];
My save function looks like this...
Код:
stock Save_Info(playerid)
{
	GetPlayerPos(playerid, PlayerInfo[playerid][PosX], PlayerInfo[playerid][PosY], PlayerInfo[playerid][PosZ]);
	GetPlayerFacingAngle(playerid, PlayerInfo[playerid][PosA]);

	new	INI:File = INI_Open(PPath(playerid));
	INI_SetTag(File,"Player_Data");
	INI_WriteFloat(File,"PosX", PlayerInfo[playerid][PosX]);
	INI_WriteFloat(File,"PosY", PlayerInfo[playerid][PosY]);
	INI_WriteFloat(File,"PosZ", PlayerInfo[playerid][PosZ]);
	INI_WriteFloat(File,"PosA", PlayerInfo[playerid][PosA]);
	INI_WriteInt(File,"VirtualWorld", GetPlayerVirtualWorld(playerid));
	INI_WriteInt(File,"Interior", GetPlayerInterior(playerid));
	INI_WriteInt(File,"Skin", GetPlayerSkin(playerid));
	INI_WriteInt(File,"Wallet", PlayerInfo[playerid][Wallet]);
	INI_WriteInt(File,"Bank", PlayerInfo[playerid][Bank]);
	INI_WriteString(File,"CarName", PlayerInfo[playerid][CarName]);
	INI_WriteInt(File,"CarID", PlayerInfo[playerid][CarID]);
	INI_WriteInt(File,"CarVW", PlayerInfo[playerid][CarVW]);
	INI_WriteInt(File,"CarI", PlayerInfo[playerid][CarI]);
	INI_WriteFloat(File,"CarX", PlayerInfo[playerid][CarX]);
	INI_WriteFloat(File,"CarY", PlayerInfo[playerid][CarY]);
	INI_WriteFloat(File,"CarZ", PlayerInfo[playerid][CarZ]);
	INI_WriteFloat(File,"CarA", PlayerInfo[playerid][CarA]);
	INI_WriteInt(File,"CarColor1", PlayerInfo[playerid][CarCol1]);
	INI_WriteInt(File,"CarColor2", PlayerInfo[playerid][CarCol2]);
	INI_Close(File);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)