Important Commands


Code:
constructAccessory(%type, %name, %offset, %rotation, %shapeFile, %datablockname, %customMountPoint);
getAccessoryGroup(%type);


The arguments to constructAccessory are as follows.

  • %type is one of $Accessories::NoneType, $Accessories::HeadGearType, $Accessories::AccentType, $Accessories::BodyGearType, or $Accessories::OtherType. I can't think of any particular reason why NoneType would be used in constructing an accessory other than the default $Accessories::None (used to insert "None" into all the accessory menus), but I'm including it for documentation purposes. HeadGear and BodyGear represent hats/helmets/hair/etc and backpacks/air tanks/armor/etc. AccentType is for things like visors and feathery things in hats. OtherType is used for things like left handed accessories, beards, and birds, and anything else weird.
  • %name is how the accessory will be identified in options menus and other gui elements.
  • %offset is a 3-vector representing offset from the mount node. If passed an empty string this defaults to "0 0 0"
  • %rotation is a normal TGE axis-angle rotation (a unit length 3-vector describing the axis of rotation followed by an angle in degrees). If passed an empty string this defaults to "0 0 1 0"
  • %shapeFile is a string with the path to the model for this accessory.
  • %datablockName is the name to be used for the datablock that will automagically be generated for this accessory. DO NOT CODE YOUR OWN DATABLOCK FOR THE ACCESSORY
  • %customMountPoint allows you to specify a non-standard mount node for your accessory. For convenience, $Accessories::RightHandMount, $Accessories::LeftHandMount, $Accessories::BodyMount, $Accessories::RightFootMount, $Accessories::LeftFootMount, $Accessories::HeadMount, and $Accessories::VisorMount are defined. If passed a blank string, OtherType accessories will default to LeftHandMount, AccentType accessories will default to VisorMount, BodyGearType accessories will default to BodyMount and HeadGearType accessories will default to HeadMount.


getAccessoryGroup(%type) returns the SimSet containing accessories of type %type or errors if passed NoneType (or an unknown type).

Sample Code

Code:
   %og = getAccessoryGroup($Accessories::OtherType);

   %og.add(constructAccessory($Accessories::OtherType, "Shield", "", "", "core/data/shapes/player/left/shield.dts", "shieldShowImage", ""));
   %og.add(constructAccessory($Accessories::OtherType, "Goblet", "", "", "core/data/shapes/player/left/goblet.dts", "gobletShowImage", ""));
   %og.add(constructAccessory($Accessories::OtherType, "Beard", "", "", "core/data/shapes/player/left/beard.dts", "BeardShowImage", $Accessories::HeadMount));
   %og.add(constructAccessory($Accessories::OtherType, "Sickle", "0 0 -0.5", "1 0 0 12", "core/data/shapes/player/left/sickle.dts", "sickleShowImage", ""));
   %og.add(constructAccessory($Accessories::OtherType, "Push Broom", "0 0 1.2", "-1 0 0 180", "core/data/shapes/player/left/pushbroom.dts", "broomShowImage", ""));
   %og.add(constructAccessory($Accessories::OtherType, "Whip", "", "", "core/data/shapes/player/left/whip.dts", "whipShowImage", ""));
   %og.add(constructAccessory($Accessories::OtherType, "Bird", "0.45 0.2 0.2", "", "core/data/shapes/player/left/bird2.dts", "birdShowImage", $Accessories::BodyMount));






This is EVERYTHING that needs to be done to add your custom accessories to the player customization menu. A few glitches with skinning are still being ironed out of the system, but this is all you need to know for creating a content pack.

When LDraw support is added, the same interface will allow you to use arbitrary LDraw models for player customization (or make your own unofficial ones), but will be extended for arms, legs, hands, head, and torso


[edit]
Be sure your accessories are initialized somewhere that ensures dedicated servers will see them.
What if I need to create a datablock for my accessory item in order to add a special effect(audible breathing Darth Vader mask, flaming skull, etc.)?
can you give me an example of how you would code this normally?

Functions in that datablock's namespace should behave as usual, since the name specified will be used.
Well, if I wanted a flaming skull, I'd use the weapon state system to call a particleemitter, then loop that state. If I wanted a breathing Darth Vader mask, I'd do the same thing, but call the breathing sound, and add a delay before the next loop.

Also, either make it so that accessories aren't rendered in first person, or are rendered with an eye offset of "0 0 5" or something so they can't be seen. This will keep helmets and such from blocking the players view. I suppose you could also add an extra value to that function for toggling whether an item is rendered in first person or not, so if someone makes a helmet with a textured HUD or something they really want the player to see, they can enable that.
DShiznit wrote:
Well, if I wanted a flaming skull, I'd use the weapon state system to call a particleemitter, then loop that state. If I wanted a breathing Darth Vader mask, I'd do the same thing, but call the breathing sound, and add a delay before the next loop.

You'll need to create your own package of functions to create ScriptObjects with, at the least, the following fields

Code:
function constructAccessory(%type, %accname, %offset, %rotation, %shapeFile, %datablockName, %customMount){
      if(%shapeFile !$= "" && !activeModPath(%shapeFile)){
         error("Can't use" SPC %shapeFIle SPC "because it is in a mod that is not yet active");
         return -1;
      }
      return new ScriptObject(){
         class = Accessory;
         type = %type;
         datablockInit = 0;
         accname = %accname;
         transform = ((getWordCount(%offset) != 3) ? "0 0 0" : %offset) SPC ((getWordCount(%rotation) != 4) ? "0 0 1 0" : %rotation);
         shapeFile = %shapeFile;
         mount = (%customMount $= "") ? getMountPointByType(%type) : %customMount;
         datablockName = %datablockName;
      };
   }

You would change that code so that superClass = Accessory and that class is something like StateEnabledAccessory, and then add code to deal with your extra fields. Then write a new getDatablock function for your new subclass that handles the new fields, and you're good to go. The base getDatablock function for the Accessory class currently looks like this (obviously you may need to change className to WeaponImage or something like that):

Code:
function Accessory::getDatablock(%this){
      if(%this.isDatablockInited()){
         return nametoid(%this.datablockName);
      } else{
         %ndb = "datablock ShapeBaseImageData("@%this.datablockName@") {" NL
            "shapeFile = \"" @ %this.getShapeFile() @"\";" NL
            "cloaktexture = \"core/data/shapes/cloakTexture\";" NL
            "mountPoint = " @ %this.getMountNode() @ ";" NL
            "offset = \"" @ %this.getMountOffset() @ "\";" NL
            "rotation = \"" @ %this.getMountRotation() @ "\";" NL
            "className = \"ItemImage\";" NL "};";
         eval(%ndb);
         %this.dataBlockInit = (nametoid(%this.datablockName) != -1);
          if(%this.dataBlockInit){
             $Accessories::lastDatablock = %this.datablockName;
             return nametoid($Accessories::lastDatablock);
          } else{
             return -1;
          }
      }
   }


Quote:
This will keep helmets and such from blocking the players view. I suppose you could also add an extra value to that function for toggling whether an item is rendered in first person or not, so if someone makes a helmet with a textured HUD or something they really want the player to see, they can enable that.

Hmmmmm, I guess I could do something along those lines. I kinda like seeing things like the helmet though. I do need to fix the camera when in crouching position though, so it's not aimed out the top of your head.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement