Car system trouble.
#1

Hey there,

I'm currently running a modified version of LVRCR 1.8.

The car system on it, is flawed and I can't seem to figure out how to fix it. Basically, the problem is that when a player purchases a car, the script stores the ID of the player, instead of the playername. So here's a hypothetical situation:

Me (ID: 0) buys car.
I log out.
Someone else logs into server and becomes ID: 0.
That person now owns my car!

Can anyone help me?

Pawno (Car Command):

Код:
	if(strcmp(cmd,"/buycar",true)==0)
	{
  if(IsSpawned[playerid] == 0) {
	SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
  return 1;
  }
	//if(IsSpawned[playerid] == 1) {
	//SendClientMessage(playerid, COLOR_ERROR, "This command has been disabled due to upgrades. Check back soon");
  //return 1;
  //}
  if(Jailed[playerid] == 1) {
	SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
  return 1;
  }
  if(!IsPlayerInCheckpoint(playerid)) {
  SendClientMessage(playerid,COLOR_ERROR,"You need to be in the checkpoint at AutoBahn to attempt to sell a car");
  return 1;
  }
  autobahnowner[playerid]=dUserINT(PlayerName(playerid)).("autobahnowner");
	if(autobahnowner[playerid] == 1337) {
	SendClientMessage(playerid,COLOR_ERROR,"You are the owner of AutoBahn. You cannot buy any vehicle from AutoBahn");
	return 1;
	}

  if(IsPlayerInCheckpoint(playerid) && getCheckpointType(playerid) == 19)
  {
  if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) {
  SendClientMessage(playerid, 0xA9A9A9AA, "|_Vehicle Purchase Failed_|");
	SendClientMessage(playerid, COLOR_ERROR, "You cannot be in a car when using this command");
  return 1;
	}
  new buyername[24];
  GetPlayerName(playerid,buyername, 24);
	new x_nr[256];
			x_nr = strtok(cmdtext, idx);
			if(!strlen(x_nr)) {
				SendClientMessage(playerid, COLOR_ERROR, "USAGE: /buycar 1-10");
   			return 1;
			}
		  if(strcmp(x_nr,"1",true) == 0)
			{
			  if(GetPlayerMoney(playerid) <= 39999) {
			  SendClientMessage(playerid, 0xA9A9A9AA, "|_Vehicle Purchase Failed_|");
			  SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy a Sultan car ($40000)");
			  return 1;
			}
			  new boughtcar;
			  GetPlayerName(playerid,buyername,24);
     	  boughtcar = CreateVehicle(560, 2174.2114,1421.0642,10.5913,91.0247, -1, -1, 99999999999);
     	  BoughtCars[boughtcar] =999;
     	  BoughtCarsOwner[boughtcar] =playerid;
			  SendClientMessage(playerid, 0xA9A9A9AA, "|_Vehicle Purchased_|");
			  SendClientMessage(playerid, 0x00C7FFAA, "You have bought a Sultan vehicle from AutoBahn for $40000");
			  GivePlayerMoney(playerid,-40000);
			  PutPlayerInVehicle(playerid, boughtcar, 0);
			  printf("**(CAR PURCHASE)** %s(%d) has purchased a Sultan car from AutoBahn ($40000)",buyername,playerid);
			for(new i=0;i<MAX_PLAYERS;i++)
			{
			if(IsPlayerConnected(i))
			{
				  autobahnowner[i]=dUserINT(PlayerName(i)).("autobahnowner");
			if(autobahnowner[i] == 1337)
			{
				new autoowner[24];
				GetPlayerName(i,autoowner,24);
				SendClientMessage(i, 0xA9A9A9AA, "|_Vehicle Sold_|");
				format(string, sizeof(string), "AutoBahn salesmen have sold a Sultan vehicle to %s(%d) - You receive $40000",buyername,playerid);
  			SendClientMessage(i, 0x00C7FFAA, string);
			  SendClientMessage(i, 0x00C7FFAA, "You can sell the AutoBahn business to a player using /sellautobahn (id)");
			  GivePlayerMoney(i,40000);
			  printf("**(CAR PURCHASE CASH)** AutoBahn owner %s(%d) has received $40000 from a Sultan car sale",autoowner,i);
			}
			}
			}
			}
			else if(strcmp(x_nr,"2",true) == 0)
			{
        if(GetPlayerMoney(playerid) <= 59999) {
			  SendClientMessage(playerid, 0xA9A9A9AA, "|_Vehicle Purchase Failed_|");
			  SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy a Elegy car ($60000)");
			  return 1;
			}
        new boughtcar;
			  GetPlayerName(playerid,buyername,24);
     	  boughtcar = CreateVehicle(562, 2174.2114,1421.0642,10.5913,91.0247, -1, -1, 99999999999);
     	  BoughtCars[boughtcar] =999;
     	  BoughtCarsOwner[boughtcar] =playerid;
			  SendClientMessage(playerid, 0xA9A9A9AA, "|_Vehicle Purchased_|");
			  SendClientMessage(playerid, 0x00C7FFAA, "You have bought a Elegy vehicle from AutoBahn for $60000");
			  GivePlayerMoney(playerid,-60000);
			  PutPlayerInVehicle(playerid, boughtcar, 0);
			  printf("**(CAR PURCHASE)** %s(%d) has purchased a Elegy car from AutoBahn ($60000)",buyername,playerid);
			for(new i=0;i<MAX_PLAYERS;i++)
			{
			if(IsPlayerConnected(i))
			{
				  autobahnowner[i]=dUserINT(PlayerName(i)).("autobahnowner");
			if(autobahnowner[i] == 1337)
			{
			  new autoowner[24];
				GetPlayerName(i,autoowner,24);
				SendClientMessage(i, 0xA9A9A9AA, "|_Vehicle Sold_|");
				format(string, sizeof(string), "AutoBahn salesmen have sold a Elegy vehicle to %s(%d) - You receive $60000",buyername,playerid);
  			SendClientMessage(i, 0x00C7FFAA, string);
			  SendClientMessage(i, 0x00C7FFAA, "You can sell the AutoBahn business to a player using /sellautobahn (id)");
			  GivePlayerMoney(i,60000);
			  printf("**(CAR PURCHASE CASH)** AutoBahn owner %s(%d) has received $60000 from a Elegy car sale",autoowner,i);
			}
			}
			}
			}
All the way to 10... etc...

Pawno (Message):

Код:
  new string[256];

  if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER && BoughtCars[GetPlayerVehicleID(playerid)] == 999 && BoughtCarsOwner[GetPlayerVehicleID(playerid)] != playerid) {
	SendClientMessage(playerid,COLOR_YELLOW,"This car has been purchased from AutoBahn. You are not the owner");
	format(string, sizeof(string), "This vehicle is registered to playerid: %d",BoughtCarsOwner[GetPlayerVehicleID(playerid)]);
	SendClientMessage(playerid, COLOR_YELLOW, string);
	RemovePlayerFromVehicle(playerid);
	return 1;
Reply
#2

*bump*

Sorry, I just really need help on this... anyone?
Reply
#3

The problem lies here...

pawn Код:
BoughtCarsOwner[boughtcar] =playerid;
In order to fix it, that variable needs to be a string for max size of 24 and use strmid to get the players name in there. Now for the features, use strcmp to compare their name and the car owners name.
Reply
#4

It's technically not a "bug", the way it was originally scripted was intended to lock it to the ID, not the name.

It is quite hard and tricky to get this lock to name.
I have one on my server, it can mess up at times though.
Reply
#5

I'd start from using enum instead of so many MAX_VEHICLES/PLAYERS.
It's more organized.
Set the person to own the vehicle by using his name. Not by the ID or something..
Reply
#6

Ahh Byrner, I didn't know that! I just didn't think it would have much purpose if the player left the server without actually destroying the car.

Anyway, thanks for the advice guys. I got it working fine now, by using strmid and locking it to playername.
Reply
#7

Well done !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)