SetVehicleSpeed, ModifyVehicleSpeed in MPH
#1

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.
Reply
#2

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

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.
Reply
#4

yeah it is cool, thanks
Reply
#5

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

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

Extremely useful, thank you sir.
Reply
#8

Thank you very much +rep
Reply
#9

How do i install it? and what includes needed?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)