Reading YINI and String Comparision
#1

I have 3 vehicles saved to .ini files that the server saves / creates.
Vehicles are saved by their unique id, so I'm vehicles 0, 1 and 2.
Within each vehicle file, there is a line
Код:
owner = PlayerName
where owner is a String.

Now the Callback OnPlayerEnterVehicle:

Код:
public OnPlayerEnterVehicle (playerid, vehicleid, ispassenger)
{
new string [256];
new SenderName [MAX_PLAYER_NAME];
GetPlayerName (playerid, SenderName, sizeof (SenderName));
if (togDebug [playerid] == 1)
{
if (! strcmp (VehicleInfo [vehicleid] [vOwner] SenderName))
{
SendClientMessage (playerid, Color_White, "This vehicle is yours.");
}
else
{
SendClientMessage (playerid, Color_White, "This vehicle is not yours.");
format (string, sizeof (string), "This vehicle is in the name of:%s." VehicleInfo [vehicleid] [vOwner]);
SendClientMessage (playerid, Color_White, string);
}
}
}
Notice that the line:

Код:
if (! strcmp (VehicleInfo [vehicleid] [vOwner] SenderName))
I do the compare string. If the player The name is the same as is in the variable vOwner, which takes the name of the player and then Send Client Message.

Until then everything was working fine. The ID: 0 of the vehicle had my name there in his file, the other 2 did not have my name and it worked correctly, the problem is:
A new player has entered the server and tested to me and he entered the Vehicle ID 0, and the message he received is that the vehicle was his, so the comparison does not work properly, and is in the file:
Код:
owner = Hayden_Almeida
and the Player Name is totally different:
Код:
Kaio_Vit
What did I be doing wrong?


I discovered another problem. I used the GetPlayerVehicleID function and print to see WHAT was happening And i discover that all vehicles is server has the ID: 0

This is the thread i've following: https://sampforum.blast.hk/showthread.php?tid=416104
Reply
#2

Missing a , in the strcmp as far as I can see, you're currently only inputting one arg while strcmp requires 2, kinda surprised if you can compile that to be honest.
However, whether that is the sole problem I can't really tell.
Reply
#3

While this isn't really relevant I would suggest saving a unique ID instead of an Owner name, if their name was to change you'd have to change everything they own as opposed to doing nothing at all when it happens.
Reply
#4

In vehicle ID i have in his file:
Код:
owner = Hayden_Almeida
Then i create this code:
Код:
if(!strcmp(VehicleInfo[vehicleid][vOwner],sendername))
{
	SendClientMessage(playerid, COLOR_WHITE, "Este veнculo й seu.");
}
else
{
	SendClientMessage(playerid, COLOR_WHITE, "Este veнculo nгo й seu.");
	format(string,sizeof(string), "Este veнculo estб no Nome de: %s.", VehicleInfo[vehicleid][vOwner]);
	SendClientMessage(playerid, COLOR_WHITE, string);
}
When i enter the car, its Says the ELSE block:
Код:
"His Vehicle is in the Name of: HHayden_Almeida."
Why printing "HHayden_Almeida" and not "Hayden_Almeida" ?

-----------
EDIT:
Every time i do GMX, the file adds more one "H" in vehicle file in owner line, like this:
Код:
owner = HHayden_Almeida
WHY??



I have this codes for loading and save:

Код:
stock VehiclePath(vehicleID)
{
	new strPath[256];
	format(strPath, sizeof(strPath), "DMRPG/Veiculos/%d.ini",vehicleID);

	return strPath;
}
stock VehicleGetFreeSlot()
{
	for(new i = 1; i < MAX_VEHICLES; i++)
	{
		if(!vCreated[i]) return i;
	}
	return -1;
}
stock VehicleCreate(vehicleModel, Float:x,Float:y,Float:z,Float:angle, vehicleColor1, vehicleColor2, vehicleRespawn, key,vehicleOwner[]) //vehicleOwner[]
{
	new vehicleid = VehicleGetFreeSlot();
	VehicleInfo[vehicleid][vModel] = vehicleModel;
	VehicleInfo[vehicleid][xspawn] = x;
    VehicleInfo[vehicleid][yspawn] = y;
    VehicleInfo[vehicleid][zspawn] = z;
    VehicleInfo[vehicleid][anglespawn] = angle;
	VehicleInfo[vehicleid][vColor1] = vehicleColor1;
	VehicleInfo[vehicleid][vColor2] = vehicleColor2;
	VehicleInfo[vehicleid][vRespawn] = vehicleRespawn;
	VehicleInfo[vehicleid][vKey] = key;
	format(VehicleInfo[vehicleid][vOwner], MAX_PLAYER_NAME, vehicleOwner);
	VehicleInfo[vehicleid][vID] = CreateVehicle(vehicleModel, x, y,z, angle, vehicleColor1, vehicleColor2,
	vehicleRespawn);


	vCreated[vehicleid] = true;

	return vehicleid;
}
stock VehicleGet(vehicleID)
{
	GetVehiclePos(VehicleInfo[vehicleID][vID], VehicleInfo[vehicleID][xspawn], VehicleInfo[vehicleID][yspawn], VehicleInfo[vehicleID][zspawn]);
	GetVehicleZAngle(VehicleInfo[vehicleID][vID], VehicleInfo[vehicleID][anglespawn]);
}
stock VehicleLoad(vehicleID, file[])
{
	INI_ParseFile(file, "LoadVehicleData", .bExtra = true, .extra = vehicleID);
	VehicleCreate(VehicleInfo[vehicleID][vModel],
	VehicleInfo[vehicleID][xspawn], VehicleInfo[vehicleID][yspawn],VehicleInfo[vehicleID][zspawn],VehicleInfo[vehicleID][anglespawn],VehicleInfo[vehicleID][vColor1], VehicleInfo[vehicleID][vColor2], VehicleInfo[vehicleID][vRespawn], VehicleInfo[vehicleID][vOwner], VehicleInfo[vehicleID][vKey]);
	
	//new vehicleid = VehicleInfo[vehicleID][vID];
	new alarm, doors, bonnet, boot, objective;
    SetVehicleParamsEx(vehicleID, 0, 0, alarm, doors, bonnet, boot, objective);
}
forward public LoadVehicleData(vehicleID, name[], value[]);
public LoadVehicleData(vehicleID, name[], value[]) // This a callback with the parameter of the vehicleID send from our VehicleLoad function. This function will pretty much parse the data from the file.
{
	INI_Int("model", VehicleInfo[vehicleID][vModel]);
	INI_Float("XSpawn", VehicleInfo[vehicleID][xspawn]);
	INI_Float("YSpawn", VehicleInfo[vehicleID][yspawn]);
	INI_Float("ZSpawn", VehicleInfo[vehicleID][zspawn]);
	INI_Float("AngleSpawn", VehicleInfo[vehicleID][anglespawn]);
	INI_Int("color1", VehicleInfo[vehicleID][vColor1]);
	INI_Int("color2", VehicleInfo[vehicleID][vColor2]);
	INI_Int("respawn", VehicleInfo[vehicleID][vRespawn]);
	INI_Int("Key", VehicleInfo[vehicleID][vKey]);
	INI_String("owner", VehicleInfo[vehicleID][vOwner], MAX_PLAYER_NAME);
	
	return 1;
}
stock VehicleSave(vehicleID)
{
	new INI:dFile = INI_Open(VehiclePath(vehicleID));

	INI_WriteInt(dFile, "model", VehicleInfo[vehicleID][vModel]);
	INI_WriteFloat(dFile,"XSpawn", VehicleInfo[vehicleID][xspawn]);
	INI_WriteFloat(dFile,"YSpawn", VehicleInfo[vehicleID][yspawn]);
	INI_WriteFloat(dFile,"ZSpawn", VehicleInfo[vehicleID][zspawn]);
	INI_WriteFloat(dFile,"AngleSpawn", VehicleInfo[vehicleID][anglespawn]);
	INI_WriteInt(dFile, "color1", VehicleInfo[vehicleID][vColor1]);
	INI_WriteInt(dFile, "color2", VehicleInfo[vehicleID][vColor2]);
	INI_WriteInt(dFile, "respawn", VehicleInfo[vehicleID][vRespawn]);
	INI_WriteInt(dFile, "Key", VehicleInfo[vehicleID][vKey]);
	INI_WriteString(dFile, "owner", VehicleInfo[vehicleID][vOwner]);
	INI_Close(dFile);
}
stock VehicleLoadAll()
{
	new index = 1;

	while(fexist(VehiclePath(index)))
	{
		VehicleLoad(index, VehiclePath(index));
		index++;
	}

	printf("Vehicles Loaded: %d", index);
}
stock VehicleSaveAll()
{
	new index = 1;

	for(new i = 1; i < MAX_VEHICLES; i++)
	{
		if(vCreated[i])
		{
			VehicleGet(index);
			VehicleSave(index);
			index++;
		}
	}

	printf("Vehicles Saved: %d", index);
}
stock VehicleValid(vehicleID) //Get's the system's vehicle id from sa-mp's vehicle id.
{
	for(new i = 1; i < MAX_VEHICLES; i++) // For every vehicles till the maximum amount
	{
		if((vCreated[i]) && (VehicleInfo[i][vID] == vehicleID)) return i; // Is this vehicle created and it's the same sa-mp id as the argument provided? Return the system's id then.
	}

	return -1; // Return invalid system's vehicle id if it was not found.
}
Reply
#5

upppp
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)