Author Topic: Changing Jet force, constant force on player, onDataBlockCreate? (and other Q's)  (Read 1538 times)

Hello everyone, I'm going to be creating several new playertypes, and I need to know how to do the things listed below before I can complete them:  (script-wise anyway :P)


1-  for several of my projects I need the player jets to give much more force then they currently do with the default playertypes. I'm hoping this isn't too hard to achieve, but I am no scripter, soo...


2- I'm going to be making a playertype with a jetpack. The jetpack needs to accelerate the player to a certain speed, hold at that speed for about 2 seconds, then completely shut off. (I was originally thinking of using the player jets for this, but I think an item image may work better) What I need help with is getting the item image to apply a constant force to the player (similar to the jets). If possible the movement of the player should be as smooth as possible (not jerky/laggy). Also, for another playertype I am working on, I will need to use this same system, but instead of causing the player to shoot up, it needs to force the player in the direction they are looking (why I can't us jets).
Any help with this would be very greatly appreciated, since I need this function the most.


3-  Is there a way to make a playertype datablock, say, play an animation, when a player's datablock is changed to it? (example: player clicks on evented brick that changes his datablock to a scorpion>scorpion plays sting animation)


4-  Is there a way to change values of a player datablock (movement speed, drag, mass, etc) by an item script?



As always, any help is greatly appreciated. <3

you cannot change jet force

you cannot change jet force

Yeah, I was suspecting that.. :/

Too bad there isn't any way to view the jet script. Then I could probably make my own version.
« Last Edit: September 11, 2010, 09:49:53 PM by ArmyUnit »

I think i can fix some of those for you.

1. I thought it was possible, but is SpreadsPlague is right, i could find an other way around anyway.
2. Should the player hold the fire button/jet button? Or does it have to do it automatically? The best way is to let the player hold the key as it will be somewhat less jerkier.
3. Playertypenameher::OnNewDatablock(%this , %obj)
Then letting it perform an animation would be like:
%this.playThread(slotnumberhere, "animationname");
But i'll get ya the full script if you PM me with the information for what it is, how the namehere's should be filled and stuff like that.
4. Unless you change the playertype. Nope.

Why didn't you PM me right away? D:
I know i am a bit/quite inactive on the job lately, but hey, i could have answered some of those right away. :P

I think i can fix some of those for you.

1. I thought it was possible, but is SpreadsPlague is right, i could find an other way around anyway. kk
2. Should the player hold the fire button/jet button? Or does it have to do it automatically? The best way is to let the player hold the key as it will be somewhat less jerkier. I will need both. They will both use the Jet Key
3. Playertypenameher::OnNewDatablock(%this , %obj)
Then letting it perform an animation would be like:
%this.playThread(slotnumberhere, "animationname");
But i'll get ya the full script if you PM me with the information for what it is, how the namehere's should be filled and stuff like that.  Awesome, thanks!
4. Unless you change the playertype. Nope. Are you completely sure? I think Nicro327 said he had gotten a script working that does this. He may have meant changing the datablock though, I need to ask him for more info. :/

Why didn't you PM me right away? D:
I know i am a bit/quite inactive on the job lately, but hey, i could have answered some of those right away. :P\
Originally I was going to PM you, but I ended up posting it here anyway :P

Replies in bold.

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.

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.
Rotondo, Space Guy and far more use new datablocks, it's no like they would do that if there was an easier way. :S

#2:
Code: [Select]
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).

#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).

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) 

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.

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) 

Any add-on you release containing that code would be failed. The real jet code is within the engine itself - any implementation in the script is going to be tragic.

This script implementation, however, is designed for specific situations where the built-in one does not work: Directional movement and specific speed/scceleration. Yes, the default would be best, but it can't travel at 30 units/sec at a 48 degree angle. It's rather unfortunate, and thus this.

Any add-on you release containing that code would be failed. The real jet code is within the engine itself - any implementation in the script is going to be tragic.
Like it would bork the main jet code? :S

Not sure, but I recall decreasing something like the playertype's mass allowed your jets to be stronger.

Not sure, but I recall decreasing something like the playertype's mass allowed your jets to be stronger.
I think this works too.
I shall try it out soon.