[HowTo] Making a working Cruise control
#1

Hey,
I want to make an cruise control. If the player press "C' when driving, the speed of the vehicle was saved in a variable and his speed stays constant by using SetVehicleVelocity. Only if i drive into an car and i activate the cruise control, the car flys up into the air and catch fire. I want a constant speed, not a flying car :S. Anyone know how to repair this?
Greetz
sean5874
Reply
#2

What values are you saving when the user activates cruise control?
I would imagine you would only need to set the x and y velocity, and leave the z velocity alone (the z velocity controls the vertical velocity of the car)
Reply
#3

I remade an piece by using your advice, if im in a car, and that car dont move, everything is fine. The car dont go in cruise control, cuz the speed is 0. But when i go for a trip, and i do /cc (my cruise control command) the whole server crashes! Below you see my piece of script:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/cc", cmdtext, true, 10) == 0)
	{
		new Float:vX, vY, vZ;
		GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
             SetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, 0.0); // im not using vZ
		SendClientMessage(playerid, COLOR_RED,"CRUISE CONTROL: Cc is on, use key S to turn it off.");
		return 1;
	}
	return 0;
}
Someone know whats wrong?
Reply
#4

Quote:
Originally Posted by sean5874
Hey,
I want to make an cruise control. If the player press "C' when driving, the speed of the vehicle was saved in a variable and his speed stays constant by using SetVehicleVelocity. Only if i drive into an car and i activate the cruise control, the car flys up into the air and catch fire. I want a constant speed, not a flying car :S. Anyone know how to repair this?
Greetz
sean5874
Theres already a filterscript that does this
Reply
#5

Quote:
Originally Posted by sean5874
I remade an piece by using your advice, if im in a car, and that car dont move, everything is fine. The car dont go in cruise control, cuz the speed is 0. But when i go for a trip, and i do /cc (my cruise control command) the whole server crashes! Below you see my piece of script:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/cc", cmdtext, true, 10) == 0)
	{
		new Float:vX, vY, vZ;
		GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
             SetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, 0.0); // im not using vZ
		SendClientMessage(playerid, COLOR_RED,"CRUISE CONTROL: Cc is on, use key S to turn it off.");
		return 1;
	}
	return 0;
}
Someone know whats wrong?
You need to reapply the velocity in timer. Also leave the vZ as it is, don't zero it, otherwise car won't go downhill but stay in the air. And you won't be able to make turns with your car. Check the FS in my sig for ready Cruise Control solution.
Reply
#6

btw
Код:
		new Float:vX, vY, vZ;
should be
Код:
		new Float:vX, Float:vY, Float:vZ;
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)