DTS/Scripting/AddingObjects
From TDN
{{Template:ContentStandard|
Importing DTS Objects Into Your Game World
(or, On The Subject Of TSStatic vs GameBase Objects)
This is a very basic explanation about importing your DTS objects into your game world (ie, your mission file). When I started going through this process myself, I found some aspects to be confusing. Now that I think it's cleared up, I thought this would make a decent little introductory article for beginners.
There are, essentially, two types of DTS objects in a Torque-based game: simple objects and complex objects. Simple objects don't do anything; they just sit there, like scenery. They can't be animated, and players can't interact with them (other than bumping into them). They are usually referred to as static objects. If you want an object to do more than this, like be animated or to display some sort of specific game-related behavior, then you would want your object to be a complex object.
Both types are derived from the SceneObject class, which is the foundation for all 3D objects in Torque.
The sub-class of SceneObject that is used for static (simple) objects is the TSStatic class.
The sub-class of SceneObject that is used for complex objects is the GameBase class.
The GameBase class itself gives rise to sub-classes like Debris, Lightning, Triggers, and the ShapeBase class--which itself gives rise to lots of sub-classes like Items, Players, Vehicles, and the (curiously named) StaticShape class.
Questions & Answers
What are the main differences between TSStatic shapes and GameBase-derived shapes?
Probably the most important difference is that GameBase objects use datablocks. Another important difference is that GameBase objects can be animated. GameBase objects are also editable during a game (eg, they can be hidden). TSStatic objects cannot do any of those.
The use of datablocks by GameBase-derived objects allows you to define specific behaviors for that object, like what happens when you try to pick it up, when to play certain animations, and so on.
When should I designate my DTS object to be a TSStatic shape or a GameBase-derived shape?
Basically, it comes down to this: If you want your DTS object to be a simple object that doesn't require any interaction with the player and is not animated, it should be a TSStatic object. If you want your DTS object to have any kind of behavior during the game, including scenery objects with only simple ambient animations (like grass waving in the breeze), then it should be a GameBase-derived object. Any DTS model can be designated a TSStatic or GameBase-derived object; you just have to tell the engine which one you want it to be.
How do I assign my DTS object to be a TSStatic or GameBase-derived object?
Which type it's assigned to is determined by two factors: how it is added to the game world (ie, mission file), and whether or not a datablock has been defined in the script that uses the shape model.
In the World Editor Creator, the object tree in the lower right contains two categories of interest: Shapes, and Static Shapes. Within each category is a tree of objects that belong to that category. How does the World Editor Creator make these categories?
-The "Shapes" category is compiled from all of the Datablocks that are defined in the game script belonging to GameBaseData or one of its derivatives (such as ShapeBaseData, ItemData, or even StaticShapeData...but I think PlayerData is excluded, for some reason).
-The "Static Shapes" category (not to be confused with the StaticShape class) is compiled from all of the DTS object files that it finds in your /mod/data folder (like in the /starter.fps/data folder, for example).
You'll find that DTS objects can appear in both lists. For example, in the starter.fps game, health kits appear in both the Shapes and Static Shapes categories. What you'll find is that the entry under Shapes (HealthKit) refers to the datablock-associated object, while the entry under Static Shapes (healthKit) is just the simple DTS file. When you add both to the game world, you'll find that the Shape health kit rotates and has all of the usual properties of the health kit (eg, can be picked up, used, etc), while the Static Shape health kit does nothing but sit there.
Also notice what happens in the object tree (upper right in the World Editor Creator) when you add each type of object to your game world. If you add the "Shape" health kit to the world, the object tree will list it as an Item. That's because the health kit shape is associated with a datablock, and the datablock is of the ItemData class (it's defined in /starter.fps/server/scripts/health.cs). If you add the "Static Shape" health kit to the world, the object tree will list it as a TSStatic. The latter is done because the engine is adding only the DTS object to the world, not a DTS-datablock combination, so it uses the simplest object form without a datablock (TSStatic).
What about simple objects that don't require any interaction with players, but have simple ambient animations (like swaying grass)?
This can be a bit confusing because of naming conventions, but simple objects that don't require interaction but do have simple ambient animations should be StaticShape objects. The StaticShape class is a subclass of the ShapeBase class, which itself is a sub-class of the GameBase class. So these objects should have datablocks associated with them, but they will have less overhead.
Why even have a TSStatic class? Why not just make all game objects derivatives of the GameBase class?
TSStatic shapes have very low overhead. No datablocks, very little code. Makes it easy to include lots of them in your game. Once an object inherits from GameBase, it starts chewing up more memory and engine time. At least that's my impression.
How can I play animations in .dsq files?
I spent some time trying to get the actual animations to play in my shape and thought this would be a good place to put the results of my findings since this is where I started my search. I used StaticShapeData as my datablock class. Once I created the shape in my mission I could use %myobj.playThread(0,"hammer");, which would play the animation named hammer. If my dts file was called ("botmodel.dts") then this would load and play the dsq file "botmodel_hammer.dsq");
You have to stop the animation by hand with %myobj.stopThread(0);
All shapes based on ShapeBase have four thread for animations. The number 0, represents thread 1.
How can I play animations in .dts files?
First, you need to make sure the animation object has a Static Shape .CS file in the bin/server folder. Then inside the "StaticShapeData( name )" datablock, you need to put the following code: category = "animated shapes";
Second, you need to execute the .CS file inside the Game.cs file (located in your bin/server folder) by typing the following code inside the OnServerCreated function: exec("./RENAME.cs");
Thirdly, open up your torque game, and bring in your object. To animate it you will type the following command into the console: OBJECT_NAME.playthread(0,SEQUENCE_NAME);



