#2:
function custom_jet(%player, %fly_up, %desired_speed, %acceleration_rate, %num_times, %iteration, %repeat_speed)
{
if(!isobject(%player))//If there isn't a player to move, quit early.
{
return;
}
if(%fly_up)//What direction do we want to be going?
{
%dir = "0 0 1"; //up
}
else
{
%dir = %player.getEyeVector(); //The direction the player is facing
}
%dir = vectorNormalize(%dir); //Not required, but a good practise: Ensure that the vector is length 1.
%dir = vectorScale(%dir, %desired_speed); //This is what we want the player's velocity to be, eventually.
%vel = %player.getVelocity(); //Get the player's current velocity.
%dif = vectorSub(%dir, %vel); //What is the difference between the player's current velocity, and what we want it to be?
%len = vectorLen(%dif); //How long is that difference
if(%len < %acceleration_rate)
{
%vec = %dir; //They are similar enough that we should just use the desired velocity.
}
else
{
%dif = vectorNormalize(%dif); //Set it's length to 1...
%dif = vectorScale(%dif, %acceleration_rate); //Then multiply it by the acceleration rate. (1 * X = X...)
%vec = vectorAdd(%vel, %dif); //Add %dif to the player's velocity...
}
%player.setVelocity(%vec); // This is the new velocity.
//About here, this should schedule itself again...
%iteration = %iteration + 1;
if(%iteration < %num_times)
{
schedule(%repeat_speed, 0, custom_jet, %player, %fly_up, %desired_speed, %acceleration_rate, %num_times, %iteration, %repeat_speed);
}
}
function servercmdj(%client, %speed, %rate, %time)
{
if(%speed $= "")
%speed = 20;
if(%rate $= "")
%rate = 2;
if(%time $= "")
%time = 5;
custom_jet(%client.player, 0, %speed, %rate, %time * 20, 0, 50);
}
Acceleration of 1.3 or greater is required to beat gravity, 1.6 or greater to take off without an initial jump. The servercmd function makes a chat message of /j (with three optional parameters) test it, so it would be best to remove that when you aren't playing with it. It would also be a good idea to rename the function.
I commented it as best as I could(not the servercmd, though).