Game Development Community

Question about Datablocks

by MJ-meo-dmt · in Torque 3D Beginner · 10/10/2014 (1:33 am) · 7 replies

Hi,

I read that Datablocks are considered static, but you can change values but its not advised.
Now the question is if I make use of datablocks for my items, which would fit perfectly but these items would be randomly generated. Each with a different set of stats and so forth. Would it work if i make use of the dynamic fields? or should i just go and make use of scriptObjects rather than using the datablocks. or mix them? (The game is multiplayer focused)

These objects will be drop-able in the world. Like in rpg's where you kill something and it drops some loot, but instead of doing it like most rpg's do, I would like to have it the same way the current "Full" template does with ammo and health bottles.

I hope this makes sense :)
Thanks
Mj

About the author

Open minded; Independent Thinker / Analytical Thinker; A Dreamer; A friend.


#1
10/10/2014 (6:15 am)
Datablocks are for static information that would be common to objects - like, for instance, TreeA uses TreeAData because that datablock defines the shape file for that tree type.

In my opinion the object itself should hold object-specific data. Additionally, you're going to want to add server commands to access and update these objects - that way you can somewhat filter attempted cheats.

Additionally, you can't drop either datablocks or scriptobjects in the world - though every object in the world is assigned a datablock and scriptobjects can be attached to them in dynamic fields.

So, if you have an item pick-up that gives the player a weapon you would have a datablock defined for the weapon (and the pick-up item as well, see http://www.garagegames.com/products/torque-3d/fps#/5-weapons) and define the weapon's properties there. If that weapon had some other "interesting" properties that could be altered on a per-instance basis you would then want to attach each instance's data to itself and validate each access on the server.
#2
10/11/2014 (5:25 am)
I may be wrong here, but I'm 99% sure you can't change datablocks in a multiplayer situation, unless you go way out of your way to do so. The reason it's not advised is because it won't work in any multiplayer scenario.

You should be fine to make your items use their datablocks for static information (shape file and so on), but storing stats in the object itself. You can either have those stats be dynamic properties (in which case they won't be networked), or add them to the engine source and network them yourself.
#3
10/11/2014 (7:49 am)
They won't be networked automatically - you can still shove data back and forth using server and client commands. It can get confusing and cumbersome, so design carefully....
#4
10/12/2014 (2:47 am)
Hi, thanks for the replies.

I think I'm going to skip that idea of having the "loot" objects as an actual object in the 3d world. (Like what borderlands did) Instead i'm just going to go with the common loot window style like in most mmo's.

I just wanted to know what happens when you do something like this function used for creating the dropped items in the template.

The thing is the shape stays the same, a basic_fireShard is a basic fireshard, but the effects that it gives or stats if you wane call it that is randomly generated and attached on it.

So this way will work only for single player? or will it make the item in the world and available for any client, with the attached "randomEffects".

//datablock on server
datablock ItemData(FireShard)
{
   // Mission editor category
   category = "Shards";

   // Add the Ammo namespace as a parent.  The ammo namespace provides
   // common ammo related functions and hooks into the inventory system.
   className = "Shards";

   // Basic fireshard model will always stay the same
   shapeFile = "art/shapes/uberItem/basic_fireShard.DAE";
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;

   // Dynamic properties defined by the scripts
   pickUpName = "Basic Fire Shard";
};

// in scripts/server
function ItemData::createItem(%data)
{
   %obj = new Item()
   {
      dataBlock = %data;
      static = true;
      rotate = true;
      //randomEffects[] generated based on the player level and whatnot/area/creature bla bla...
      randomEffects[0] = "theUberEffect101";
      randomEffects[1] = "theUberestEffect101of101s";
      randomEffects[2] = 10000;

   };
   return %obj;
}

If this doesn't get networked automatically then I get what you said Richard having to make the cmds for handling the object/item/loot creations. One question though, how would I make it "kinda" safe/hack free. Because if i make a server sided function to generate the stats and the item details, then send to the client with args(containing the details) and then on the client have a createLoot or w/e? how would i be able to make that so that its not abused... Hope it makes sense.

Thanks again.
MJ
#5
10/12/2014 (8:49 am)
Those stats I believe are attached to the object - and since it's created on the server they will be there when you pick it up. However, when you pick that object up it is usually destroyed - so you have to transfer those extra stats to the inventory object that you would create during the pick-up. Have to look at how weapon, ammo, and health pick-ups are handled - your case is more complex (adding a gui to view the inventory) but ultimately it should start with this method. See scripts/server/inventory.cs for that bit.

Give it a shot and see what happens. Call it a learning exercise....
#6
10/12/2014 (3:16 pm)
Quote:Because if i make a server sided function to generate the stats and the item details, then send to the client with args(containing the details) and then on the client have a createLoot or w/e?
Basically that, yep. Those dynamic properties you added to the Item (randomEffects) only exist on the server because dynamic fields aren't networked. So if you want the client to have that information you'll have to use a NetEvent or a commandToClient. when you do that and what you do with the information is up to you. At a basic level, you could just send that command to the client when the loot object is created, and the client could add the same dynamic properties to its copy of the object. Or you could directly display the information in the HUD. Whatever!
#7
10/14/2014 (4:40 am)
Thanks for the replies guys.
It all makes sense.