SA-MP Forums Archive
Vehicle System HELP - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicle System HELP (/showthread.php?tid=161577)



Vehicle System HELP - Fab10 - 20.07.2010

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


Re: Vehicle System HELP - Last_Stand_Guardian - 20.07.2010

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


Re: Vehicle System HELP - Fab10 - 20.07.2010

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


Re: Vehicle System HELP - Fab10 - 20.07.2010

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")


Re: Vehicle System HELP - Last_Stand_Guardian - 20.07.2010

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


Re: Vehicle System HELP - Fab10 - 20.07.2010

post your code please!!


Re: Vehicle System HELP - Fab10 - 20.07.2010

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


Re: Vehicle System HELP - DJDhan - 20.07.2010

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

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

	return 1;
}