Game Development Community

Help with Design Theory

by Jacob Williams · in Torque Game Engine · 12/11/2008 (2:59 pm) · 3 replies

I am trying to accomplish a couple of things and I need to know the best way to go about it without breaking the multiplayer aspect of the game. Currently, I have a login system that validates against a database, and a number of player stats and skills that are stored in the database. I have written all the functions to access the database via TorqueScript (I am horrible with C++), so It is not a problem to get database values into variable. The database information is only access when joining a game (Select) and exiting a game (Update). So no in-game database access is required. I have written a number of functions to calculate various player interactions (hit chance, dodge chance, total hp, weapon damage). The question is, how do I apply these stats to the player when entering the game. I thought I had it all figured out, but when I tested a multiplayer game, on the host's stats were stored into global variables.

Here is my idea:
Write a generic datablock similar to the pseudo one written below.

datablock PlayerData(%client.name)
{
   renderFirstPerson = false;
   emap = true;
   
   className = getPlayerClass(); //these functions select the values from the DB
   shapeFile = getPlayerShape();
  
   maxDamage = getPlayerHP();
   agiliy = getPlayerStat[AGI]();
   endurance = getPlayerStat[END]();
...
}


And when creating the player in GameConnection::createPlayer:

// Create the player object
   %player = new Player() {
      dataBlock = %client.name;
      client = %this;
   };

Would something like this actually work (including in multiplayer) or is there a better way?

Thanks!
-Jacob

#1
12/11/2008 (5:16 pm)
I would not recommend it. Because there is only ever one instance of any given datablock, changing a property will change it for all instances of the datablock.
#2
12/11/2008 (5:20 pm)
But the theory here is to have a new datablock created when a new player enters, named after the player. So datablock PlayerData(Jacob) wouldn't change when player Dan entered the game and datablock PlayerData(Dan) was created. It just seems that there should be a better way to do this in script...
#3
12/11/2008 (5:23 pm)
Well, that's not really the intent datablocks were made with. It would probably be a better idea to save the data in a text file and assign it to either the client or player object (not datablock).