Blockland Forums > Modification Help
Changing Jet force, constant force on player, onDataBlockCreate? (and other Q's)
<< < (2/4) > >>
Gadgethm:
For number four, the way most scripts do it is they make a new playertype, which is a datablock, and do what lordican says.  They change the player datablock.  I believe that is the only way to do it.
lordician:

--- Quote from: Gadgethm on September 14, 2010, 07:05:25 PM ---For number four, the way most scripts do it is they make a new playertype, which is a datablock, and do what lordican says.  They change the player datablock.  I believe that is the only way to do it.

--- End quote ---
Rotondo, Space Guy and far more use new datablocks, it's no like they would do that if there was an easier way. :S
Uristqwerty:
#2:

--- Code: ---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);
}
--- End code ---
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).
ArmyUnit:

--- Quote from: Uristqwerty on September 15, 2010, 09:17:18 PM ---#2:
-codesnip-
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).

--- End quote ---

Thank you very very much! I will most definitely use that. If I release anything using it, I will give you credit. ;)


This handles both input cases, correct? (holding jet key, or tapping jet key) 
Uristqwerty:
It's not set up to use the jet key. It does do most of the math and actual movement, but I reccomend that before you even try using it you try to understand it, and then customize it to your purpose.

For example, if you wanted it to go until disabled, you would probably want to change the test at the end to checking a var on the player. Actually, for just about any purpose, I reccomend removing the schedule at the end and writing a function of your own that calls it and repeats itself, since that way you could have three different versions of it with different terminating conditions while keeping the core code readable.
Navigation
Message Index
Next page
Previous page

Go to full version