Vehicle System HELP
#1

Hello, i have edited the Vehicle System dynamic on Carlito's RolePlay..
This is a code:
Код HTML:
public LoadDynamicCars()
{
	new arrCoords[10][64];
	new strFromFile2[256];
	new File: file = fopen("CRP_Scriptfiles/Cars/carspawns.cfg", io_read);
	if (file)
	{
		new idx;
		while (idx < sizeof(DynamicCars))
		{
			fread(file, strFromFile2);
			split(strFromFile2, arrCoords, '|');
			DynamicCars[idx][CarModel] = strval(arrCoords[0]);
			DynamicCars[idx][CarX] = floatstr(arrCoords[1]);
			DynamicCars[idx][CarY] = floatstr(arrCoords[2]);
			DynamicCars[idx][CarZ] = floatstr(arrCoords[3]);
			DynamicCars[idx][CarAngle] = floatstr(arrCoords[4]);
			DynamicCars[idx][CarColor1] = strval(arrCoords[5]);
			DynamicCars[idx][CarColor2] = strval(arrCoords[6]);
			DynamicCars[idx][FactionCar] = strval(arrCoords[7]);
			DynamicCars[idx][CarType] = strval(arrCoords[8]);
			strmid(DynamicCars[idx][Owner], arrCoords[9], 0, strlen(arrCoords[1]), 255);
			
			new vehicleid = CreateVehicle(DynamicCars[idx][CarModel],DynamicCars[idx][CarX],DynamicCars[idx][CarY],DynamicCars[idx][CarZ],DynamicCars[idx][CarAngle],DynamicCars[idx][CarColor1],DynamicCars[idx][CarColor2], -1);

			if(DynamicCars[idx][FactionCar] != 255)
			{
				SetVehicleNumberPlate(vehicleid, DynamicFactions[DynamicCars[idx][FactionCar]][fName]);
				SetVehicleToRespawn(vehicleid);
			}

			idx++;
		}
		fclose(file);
	}
	return 1;
}
public SaveDynamicCars()
{
	new idx;
	new File: file2;
	while (idx < sizeof(DynamicCars))
	{

		new coordsstring[512];
		format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d|%d|%d|%s\n",
		DynamicCars[idx][CarModel],
		DynamicCars[idx][CarX],
		DynamicCars[idx][CarY],
		DynamicCars[idx][CarZ],
		DynamicCars[idx][CarAngle],
		DynamicCars[idx][CarColor1],
		DynamicCars[idx][CarColor2],
		DynamicCars[idx][FactionCar],
		DynamicCars[idx][CarType],
		DynamicCars[idx][Owner]);

		if(idx == 0)
		{
			file2 = fopen("CRP_Scriptfiles/Cars/carspawns.cfg", io_write);
		}
		else
		{
			file2 = fopen("CRP_Scriptfiles/Cars/carspawns.cfg", io_append);
		}
		fwrite(file2, coordsstring);
		idx++;
		fclose(file2);
	}
	return 1;
}
you can see the string Owner added by me..
I need a script that if the player enters the vehicle if the string Owner equal to the Nickname the player enter in vehicle, else Remove player from vehicle.. Sorry my bad english, i'm a italian.. I have a try create this code:
Код HTML:
		if(DynamicCars[vehicleid][Owner] == GetName)
		{
                } else {
                RemovePlayerFromVehicle(playerid);
                }
Error
C:\Users\Tony\Desktop\Atlantis City Role Play GameMode\gamemodes\crp.pwn(27519) : error 076: syntax error in the expression, or invalid function call

Please help me fix this code in the OnPlayerStateChange
Reply
#2

pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
       if(newstate == PLAYER_STATE_DRIVER)
       {
            new Name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
            if(!strcmp(DynamicCars[GetPlayerVehicleID(playerid)][Owner], Name, false)) { }
            else RemovePlayerFromVehicle(playerid);
       }
       return 1;
}
I don't know the dynamic car-system, so I don't know if this will work, but:
You should use strcmp to check if two strings are equal or not
=D
Reply
#3

no errors but does not work..
Example string Vehicle:
580|1073.041015|-1629.462402|13.559938|86.794097|-1|-1|255|0|Dealerships
allows to enter same in the car
Reply
#4

i have retries this code:
if(newstate == PLAYER_STATE_DRIVER)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
if(DynamicCars[GetPlayerVehicleID(playerid)-1][Owner] != Name)
{
RemoveDriverFromVehicle(playerid);
}
}
Error:
C:\Users\Tony\Desktop\Atlantis City Role Play GameMode\gamemodes\crp.pwn(27525) : error 033: array must be indexed (variable "Name")
Reply
#5

What have I said three posts about? xD
Use strcmp! xD
Reply
#6

post your code please!!
Reply
#7

this code:
if(newstate == PLAYER_STATE_DRIVER)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
if(!strcmp(DynamicCars[GetPlayerVehicleID(playerid)][Owner], Name, false)) { }
else RemovePlayerFromVehicle(playerid);
}
does not work
Reply
#8

Try this:
Код:
public OnPlayerEnterVehicle(playerid,vehicleid)
{
	new name[64];
	GetPlayerName(playerid,name,64);

	if(strcmp(DynamicCars[vehicleid][Owner],name)) return RemovePlayerFromVehicle(playerid);

	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)