SA-MP Forums Archive
SetVehicleSpeed, ModifyVehicleSpeed in MPH - 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)
+--- Thread: SetVehicleSpeed, ModifyVehicleSpeed in MPH (/showthread.php?tid=95888)



SetVehicleSpeed, ModifyVehicleSpeed in MPH - NeedAName - 05.09.2009

A couple of functions to modify vehicle speed. Works in MPH feel free to convert it to km/h.

NOTE: Doesn't work with aircraft, has some interesting effects but aircraft speed will not exceed 150mph.
Another NOTE: Vehicles will slow back down to their default top speed if the function is not constantly called.

P.S. Entering 0 into SetVehicleSpeed makes a handy instant break and using negative values sends you in the opposite direction (obviously :P)

Screenshots: SF Docks to The Big Ear!




Код:
//Sets Vehicle Speed To MPH Entered
stock SetVehicleSpeed(vehicleid,mph) //Miles Per Hour
{
	new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
	GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
	DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
	if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
	{
		multiple = (mph / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
		return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
	}
	return 0;
}

//Increases or Decreases Current Vehicle Speed By MPH Entered
stock ModifyVehicleSpeed(vehicleid,mph) //Miles Per Hour
{
	new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
	GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
	DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
	if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
	{
		multiple = ((mph + DV * 100) / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
		return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
	}
	return 0;
}
Regards, Code Rae.


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - gijsmin - 05.09.2009

this function will set the Speed for everytime
or do i need to add this in a Timer?


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - NeedAName - 05.09.2009

Quote:
Originally Posted by Gijs (TSG-Hosting.de)
this function will set the Speed for everytime
or do i need to add this in a Timer?
If you wish to keep the speed constant then you can use a timer. I'm currently using it under OnPlayerKeyStateChange so everytime a certain key is pressed it will boost the speed.

Regards, Code Rae.


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - gijsmin - 05.09.2009

yeah it is cool, thanks


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - DMSOrg - 05.09.2009

Awesome! +Bookmark (Attachment's broken for the server download )


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - cosmion - 24.12.2009

please help me.....i'm a beginnner.....how do i install this?


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - Calon - 24.12.2009

Extremely useful, thank you sir.


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - WARRI0R - 16.10.2011

Thank you very much +rep


Re: SetVehicleSpeed, ModifyVehicleSpeed in MPH - lider1241 - 10.07.2013

How do i install it? and what includes needed?