Author Topic: Image mount on spawn  (Read 1724 times)

I've been searching and testing code for about an hour now, and frankly, I have no idea what to do.

I want the code to mount the image "JuggernautImage" when the player spawns with this Playertype.
Here is the code I currently have:
Code: [Select]
//Juggernaut

//a new player datablock with Juggernaut-like movement and armor

datablock ShapeBaseImageData(JuggernautImage)
{
   // Basic Item properties
   shapeFile = "./Juggernaut.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = $BackSlot;
   offset = "0 0 0";
   eyeOffset = 0; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 180" );
   scale = "3 3 3";
   offset = "0 0 -0.5";

   doColorShift = true;
   colorShiftColor = "0.100 0.100 0.100 1.000";
};

//function serverCmdJuggernaut(%Client,%Arg)
//{
//if(isObject(%client.player))
// {
// %client.player.mountImage(JuggernautImage,2);
// }
//}


package EquipArmor
{
function GameConnection::spawnPlayer(%this)
{
%this.mountImage(JuggernautImage,2);
parent::SpawnPlayer(%this);
}
};
activatepackage(EquipArmor);


datablock PlayerData(PlayerJuggernautArmor : PlayerStandardArmor)
{
   runForce = 100 * 90;
   runEnergyDrain = 0;
   minRunEnergy = 0;
   maxForwardSpeed = 3;
   maxBackwardSpeed = 1;
   maxSideSpeed = 1;
   maxForwardCrouchSpeed = 0;
   maxBackwardCrouchSpeed = 0;
   maxSideCrouchSpeed = 0;

   jumpForce = 7.5 * 90; //3 * 0;
   jumpEnergyDrain = 0;
   minJumpEnergy = 0;
   jumpDelay = 0;

   minJetEnergy = 0;
   jetEnergyDrain = 0;
   canJet = 0;
   uiName = "Juggernaut";
   showEnergyBar = false;
};

I think you can put that in PlayerJuggernautArmor::onMount.

I think you can put that in PlayerJuggernautArmor::onMount.

Could you make me some sample code? I'm still learning all this stuff.

Try this:

Code: [Select]
function PlayerJuggernautArmor::onAdd(%this,%player)
{
        %player.mountImage(JuggernautImage,2);
}

I haven't tested it, I was just wondering if you could do it this way instead of a package. If it doesn't work, then this code should work inside your package:

Code: [Select]
function GameConnection::spawnPlayer(%this)
{
        %result = parent::spawnPlayer(%this); //I think this might return something
        %player = %this.player;

        if(isObject(%player))
                        %player.mountImage(JuggernautImage,2);

        return %result;
}

That first method did it. Thanks so much.

Last question, how would I hide any backpacks or shoulder-pads the user might have?
« Last Edit: December 21, 2011, 12:41:21 AM by Thorax »

Last question, how would I hide any backpacks or shoulder-pads the user might have?

Code: [Select]
function PlayerJuggernautArmor::onAdd(%this,%player)
{
%player.mountImage(JuggernautImage,2);

%player.hideNode(armor);
%player.hideNode(bucket);
%player.hideNode(cape);
%player.hideNode(pack);
%player.hideNode(quiver);
%player.hideNode(tank);
}

Code: [Select]
function PlayerJuggernautArmor::onAdd(%this,%player)
{
%player.mountImage(JuggernautImage,2);

%player.hideNode(armor);
%player.hideNode(bucket);
%player.hideNode(cape);
%player.hideNode(pack);
%player.hideNode(quiver);
%player.hideNode(tank);
}



It didn't work.

I put it in with the /juggernaut command and it works. I just doesn't work with the spawn one.
« Last Edit: December 21, 2011, 03:46:38 PM by Thorax »

%player.hideNode($pack[%player.client.pack]);
%player.hideNode($secondpack[%player.client.secondpack]);

Going to bet that onAdd is called before the player has their avatar applied, so it is reshowing it after hiding it.

Going to bet that onAdd is called before the player has their avatar applied, so it is reshowing it after hiding it.

What should I do to fix that issue?

What should I do to fix that issue?
make a schedule that gets applied after 1 second?

make a schedule that gets applied after 1 second?
Or .001 second, because torque sees every single calculation as going instantly for some stupid reason.

Singlethreaded scripts, won't start a schedule until the current call stack finishes to avoid complex synchronization issues, then goes with whichever one is the most overdue? That's what I would guess...

You can do a schedule of 0 and it will have the same effect I think.