SA-MP Forums Archive
Spawning vehicles without losing speed - 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: Spawning vehicles without losing speed (/showthread.php?tid=148380)



Spawning vehicles without losing speed - MummyKillerSLO - 16.05.2010

Hi all!

How can I replace vehicle without losing its velocity?
Example: I drive nrg-500 with 156km/h and then I spawn my Infernus and it drive forward with same (156km/h) speed.

I have my Car Spawn code here:

Код:
stock SpawnPlayerVehicle(playerid,ModelID)
{
	new Float:xPos,Float:yPos,Float:zPos,Float:Ang,Float:xVel,Float:yVel,Float:zVel;
	
	if(IsPlayerInAnyVehicle(playerid))
	{
		GetVehicleVelocity(playerid,xVel,yVel,zVel);
	}
	else
	{
		GetPlayerVelocity(playerid,xVel,yVel,zVel);
	}
	
	GetPlayerPos(playerid,xPos,yPos,zPos);
	GetPlayerFacingAngle(playerid,Ang);

	DestroyVehicle(Player[playerid][Vehicle]);
	Player[playerid][Vehicle] = CreateVehicle(ModelID,xPos,yPos,zPos + 1,Ang,-1,-1,0);
	SetVehicleVirtualWorld(Player[playerid][Vehicle],GetPlayerVirtualWorld(playerid));
	PutPlayerInVehicle(playerid,Player[playerid][Vehicle],0);
	SetVehicleVelocity(Player[playerid][Vehicle],xVel,yVel,zVel);
	SetPlayerVelocity(playerid,xVel,yVel,zVel);
	
	format(String,sizeof(String),"~w~Here is your ~r~%s",GetVehicleName(ModelID));
	GameTextForPlayer(playerid,String,5000,3);
	PlayerPlaySound(playerid,1056,0,0,0);
	return 1;
}
Please post edited working(tested) code because I have a lot of maps which I need this. Please help.


Re: Spawning vehicles without losing speed - MummyKillerSLO - 17.05.2010

Bump anyone?