Author Topic: Playertype Help: Sprinting and Changing to a NoMovement/NoWeaponUsage Playertype  (Read 4062 times)

I'm trying to get into torque script and to do so I'm practicing on making a custom playertype. I am having trouble with these problems:

1. How do I add in sprinting like the sports playertype? If I could actually find the code for the sports playertype then I'd probably be able to add this in myself, but I can't find it.

2. How would I make it so that when the player takes out their weapons/items with q, they turn into a no movement playertype? They would revert back to moving when they put their items away.

I have the rest of the playertype done like speed, camera position, etc., it is just these two parts I am having trouble with.

1. The code for the sports playertype is in Item_Sports/support.cs. You should make you're sprinting work a similar way, but not the same way. It changes the player's datablocks to change their speed, but you should use the %player.setMaxSTUFFSpeed functions instead.

2. Package serverCmdUseTool and serverCmdUnUseTool. But again. Instead of changing their playertype, you should use the functions I mentioned above.

Quote
//Sport player datablock, can jet while jumping and crouching, "tackling" so to speak
datablock PlayerData(PlayerSportArmor : PlayerStandardArmor)
{
   isSportPlayer = 1;
   runForce = 50 * 90;
   runEnergyDrain = 0;
   minRunEnergy = 0;
   maxForwardSpeed = 8;
   maxBackwardSpeed = 5;
   maxSideSpeed = 5;

   maxForwardCrouchSpeed = 3;
   maxBackwardCrouchSpeed = 2;
   maxSideCrouchSpeed = 2;

   jumpForce = 9 * 90; //8.3 * 90;
   jumpEnergyDrain = 0;
   minJumpEnergy = 0;
   jumpDelay = 0;

   runSurfaceAngle  = 55;
   jumpSurfaceAngle = 55;

   minJetEnergy = 10;
   jetEnergyDrain = 10;
   canJet = 0;

   rechargeRate = 0.5;

   uiName = "Sport Player";
   showEnergyBar = true;
};

function PlayerSportArmor::onTrigger(%this, %obj, %trigger, %val)
{
   if(%trigger == 4 && %val == 1 && !%obj.hasSportBall)
   {
      %obj.hesOnFire = 1;
      delaySportPlayerCheck(%obj, 1);
   }

   parent::onTrigger(%this, %obj, %trigger, %val);
}

// shoe fire effect
datablock ShapeBaseImageData( HesOnFireLImage )
{
   shapeFile = "base/data/shapes/empty.dts";
   emap = false;

   mountPoint = 4;//$HeadSlot;

   offset = "0 -0.3 0.1";
   rotation = "1 0 0 180";

   stateName[0]               = "Ready";
   stateTransitionOnTimeout[0]      = "FireA";
   stateTimeoutValue[0]         = 0.01;

   stateName[1]               = "FireA";
   stateTransitionOnTimeout[1]      = "Ready";
   stateWaitForTimeout[1]         = True;
   stateTimeoutValue[1]         = 35;
   stateEmitter[1]               = PlayerJetEmitter;
   stateEmitterTime[1]            = 35;

   // stateName[2]               = "Done";
   // stateScript[2]               = "onDone";
};

datablock ShapeBaseImageData( HesOnFireRImage )
{
   shapeFile = "base/data/shapes/empty.dts";
   emap = false;

   mountPoint = 3;//$HeadSlot;

   offset = "0 -0.3 0.1";
   rotation = "1 0 0 180";

   stateName[0]               = "Ready";
   stateTransitionOnTimeout[0]      = "FireA";
   stateTimeoutValue[0]         = 0.01;

   stateName[1]               = "FireA";
   stateTransitionOnTimeout[1]      = "Ready";
   stateWaitForTimeout[1]         = True;
   stateTimeoutValue[1]         = 35;
   stateEmitter[1]               = PlayerJetEmitter;
   stateEmitterTime[1]            = 35;

   // stateName[2]               = "Done";
   // stateScript[2]               = "onDone";
};

datablock PlayerData(PlayerSportTurboArmor : PlayerStandardArmor)
{
   isTurboSportPlayer = 1;
   runForce = 100 * 90;
   runEnergyDrain = 0;
   minRunEnergy = 0;
   maxForwardSpeed = 12;
   maxBackwardSpeed = 8;
   maxSideSpeed = 12;

   maxForwardCrouchSpeed = 7;
   maxBackwardCrouchSpeed = 6;
   maxSideCrouchSpeed = 6;

   jumpForce = 12 * 90; //8.3 * 90;
   jumpEnergyDrain = 0;
   minJumpEnergy = 0;
   jumpDelay = 0;

   runSurfaceAngle  = 55;
   jumpSurfaceAngle = 55;

   minJetEnergy = 10;
   jetEnergyDrain = 8;
   canJet = 0;

   rechargeRate = -1.0;

   uiName = "";
   showEnergyBar = true;
};
function PlayerSportTurboArmor::onTrigger(%this, %obj, %trigger, %val)
{
   if(%trigger == 4 && %val == 0)
   {
      delaySportPlayerCheck(%obj);
      %obj.hesOnFire = 0;
   }
   parent::onTrigger(%this, %obj, %trigger, %val);
}

//
function delaySportPlayerCheck( %obj, %type )
{
   // make sure we're not dead
   if(%obj.isDisabled())
      return;

   // cancel the last sport schedule if there was one
   cancel(%obj.sportPlayerSched);
   
   %dataBlock = %obj.getDataBlock();
   
   if( %type != 1 && %dataBlock != PlayerSportTurboArmor.getID() )
   {
      // he's not on fire :(
      %obj.unMountImage( 2 );
      %obj.unMountImage( 3 );
      
      return;
   }
   
   if(%type == 1)
   {
      %obj.setDataBlock("PlayerSportTurboArmor");
      
      // color the shoes & peglegs nba jam style
      // should maybe add some effect?
      %obj.setNodeColor("lshoe", "1 0 0 1");
      %obj.setNodeColor("rshoe", "1 0 0 1");
      
      %obj.setNodeColor("lpeg", "1 0 0 1");
      %obj.setNodeColor("rpeg", "1 0 0 1");
      
      // he's on fire!
      %obj.mountImage( HesOnFireLImage, 2 );
      %obj.mountImage( HesOnFireRImage, 3 );
      
      %obj.sportPlayerSched = schedule(%obj.getEnergyLevel()*32.5, %obj, delaySportPlayerCheck,%obj);
   }
   else
   {
      // set the player back to normal
      %obj.setDataBlock("PlayerSportArmor");
      %obj.client.applyBodyColors();
      
      // he's not on fire :(
      %obj.unMountImage( 2 );
      %obj.unMountImage( 3 );
   }
}


i'm pretty sure this is it (sports playertype code)

i found it in the location jes00 said

i had to shrink it down because of the pagestretch-iness


i'm pretty sure this is it (sports playertype code)

i found it in the location jes00 said

i had to shrink it down because of the pagestretch-iness

What in the loving hell?
That looked a lot like loving zalgo-text from afar?
But zoomed in? Why does the text doubles out?

So I'm having trouble trying to understand how this activates when you right click. Is it the onTrigger of "function PlayerSportTurboArmor::onTrigger(%this, %obj, %trigger, %val)?" Should I make a support.cs file to put all of this in for my playertype as well?

What in the loving hell?
That looked a lot like loving zalgo-text from afar?
But zoomed in? Why does the text doubles out?
it's better to copy and paste it, or quote my post to see what it actually says

"function PlayerSportTurboArmor::onTrigger(%this, %obj, %trigger, %val)"
This is the function that triggers when the client using the playertype presses a button.

The if function beneath it then checks which button is pressed:
Code: [Select]
if(%trigger == 4 && %val == 0)
%trigger =
0 - right hand (mouseFire)
1 - left hand (altTrigger)
2 - crouch
3 - jump
4 - Jet

%Val is whether the button is
pressed = 1
released = 0

Please bare with me, but this is what I have so far:
Code: [Select]
function PlayerNameArmor::onTrigger(%this, %obj, %trigger, %val)
{
   if(%trigger == 4 && %val == 1)
   {
    %obj.setMaxForwardSpeed = 11; 
   }

   else //or should I do if(%trigger == 4 && %val == 0) instead?
   {
%obj.setMaxForwardSpeed = 8;
   }
   parent::onTrigger(%this, %obj, %trigger, %val);
}

I noticed the sports playertype does this delay called "delaySportPlayerCheck(%obj)" which then actually has all the code for switching datablocks and etc. Should I be doing something like this or will my code be fine? Also, how can I make it so that it drains fuel from the player's energy?

I just tested this and nothing happened so I'm missing stuff then.

First of all. You were right in the comment you made for the else statement. So change it to that instead.

setMaxForwardSpeed is a function. Not a variable. So do .setMaxForwardSpeed(NUMBER);
You'll want to set a variable on the player to their max forward speed before they started sprinting, so you can set it to the proper speed when they stop. Use .getMaxFowardSpeed(); for this.

But looking at the sports player again. You might want to use the datablock changing method instead.
You either need to run a looping function with a small delay, that drains their energy. Or you'll want to run a looping function with a longer delay, that changes their datablock.
The sprinting playertype for the sports player is set to always have it's energy draining.

I might be wrong but you can only change the maxforwardspeed of a playertype, not of a player itself.
And when you do, all players with that playertype will feel the effect of the changed maxforwardspeed.

For example with the sports playertype.
If one player pressed the sprint button, then every player with that playertype in the server would sprint.

So it is indeed better to change the playertype.

Alright I'll look over it again and see how the sports playertype delay function works.

I might be wrong but you can only change the maxforwardspeed of a playertype, not of a player itself.
And when you do, all players with that playertype will feel the effect of the changed maxforwardspeed.

For example with the sports playertype.
If one player pressed the sprint button, then every player with that playertype in the server would sprint.

So it is indeed better to change the playertype.
You are wrong. Changing speed per player was added in r1956.

Code: [Select]
function PlayerNameArmor::onTrigger(%this, %obj, %trigger, %val)
{
   if(%trigger == 4 && %val == 1)
   {
     %obj.setMaxForwardSpeed = 11;  
   }

   else //or should I do if(%trigger == 4 && %val == 0) instead?
   {
%obj.setMaxForwardSpeed = 8;
   }
   parent::onTrigger(%this, %obj, %trigger, %val);
}
Also, you should indeed do "if(%trigger == 4 && %val == 0)" instead of the else.
Currently it will also trigger the the else function if %trigger = 3 and %Val = 1


You are wrong. Changing speed per player was added in r1956.
Yet again my information was outdated because of my absence of Blockland.
Thanks for pointing that out!

Well I'm getting somewhere because it changes to the faster speed when I right click, but stays at that speed even when I'm not holding it and won't change back. Here's my new code:
Code: [Select]
function PlayerArmor::onTrigger(%this, %obj, %trigger, %val)
{
   %playerSpeed = %obj.getMaxForwardSpeed();

   if(%trigger == 4 && %val == 1)
   {
     %obj.setMaxForwardSpeed(11);  
   }

   if(%trigger == 4 && %val == 0)
   {
%obj.setMaxForwardSpeed(%playerSpeed);
   }
   parent::onTrigger(%this, %obj, %trigger, %val);
}
I'm guessing I didn't create the variable to store the player's speed properly? (Is it because it's constantly getting the new speed of the player, which is the new faster setMaxForwardSpeed of 11?)

EDIT: I just changed the second setMaxForwardSpeed to 8 (which is the normal speed) and it works fine. Should I still do it the other way by using %playerSpeed = %obj.getMaxForwardSpeed();?
« Last Edit: February 01, 2016, 03:33:54 PM by Legodude77 »

Yay double posting
So I got some other help on this and it was suggested to me to use .getDatablock().maxForwardSpeed in order to change back to the default speed when not sprinting. I also tried going into coding the freezing when you equip and unequip tools. Here's what I got:
Code: [Select]
function PlayerArmor::onTrigger(%this, %obj, %trigger, %val)
{
   %db = %obj.getDatablock();   

   if(%trigger == 4 && %val == 1)
   {
    %obj.setMaxForwardSpeed(11); 
   }

   if(%trigger == 4 && %val == 0)
   {
%obj.setMaxForwardSpeed(%db.maxFowardSpeed);
   }
   parent::onTrigger(%this, %obj, %trigger, %val);
}

function serverCmdUseTool(%client, %slot)
{
   if (isObject(%client.player) && %client.isPlayerType == 1)
   {
%client.player.setMaxForwardSpeed(0);
   }
}

function serverCmdUnUseTool(%client)
{
  if (isObject(%client.player) && %client.isPlayerType == 1)
   {
%client.player.setMaxForwardSpeed(8);
   }
}

Now I got more issues:
1. Sprinting still doesn't work. But if I do just %obj.setMaxForwardSpeed(8); on the second if statement it works fine. Did I not store the variable right?

2. I'm overriding the default function for serverCmdUseTool and UnUseTool because when I hit q with any playertype I can scroll through items but not actually use any, and if I take out the brick tool it says even when I hit q again. So I made the isPlayerType variable in my playertype to check to make sure they are the right playertype, but I am assuming I'm not calling that correctly either.