How to add a player. (TGEA)
by Tim Tebow · 05/08/2008 (10:33 am) · 12 comments
I am new to this community so any help would be great if you see me going in the wrong direction but I'm hoping to help my fellow noob community out.
This tutorial is going to be using the default atlas demo that ships with TGEA. As you know or will know it does not come with a playable character enabled its just the camera. So instead of gimping out and using lets say T3D example I chose to dig down and figure out what exactly needed to be done to add a character that the camera is bound to.
So here it goes.
//-----------------------------------------------------------------------------------------------------------------------------------
First we will need to transfer some files so I am going to grab all the ones I need from the T3D folder.
- Client Folder
No files need to be moved to the client folder.
- Server Folder
In your project you will need to go into your scripts folder and then create a folder named "players"
You want to go to your T3D example and in the scriptsandassets/server/scripts/player grab the
"player.cs" and "SpaceOrc.cs" and dump them into your newly created folder.
- Data Folder
Go into your scriptsandassets/data/shapes folder and create "players" folder.
Then go back to you T3D example in the scriptsandassets/data/shapes folder and grab the
"animations" "common" and "SpaceOrc" folders copy them into your newly created "players" folder
I think thats all we need to move for now.
Now go into your scriptsandassets/client folder and open init.cs we will be making a few changes and hopefully I can clarify what most of the things do.
Scroll down to where you see loadDefaultMission() and right above it you will want to put in the following code
This will basically tell the program to look at the player.cs and load our defaults for the player model we have chosen to use.
Save and close that file for now.
Next lets go into the scriptsandassets/server/scripts/game.cs file. We will make a few changes here...
First change is right at the top it will look like this -
if you go into scriptsandassets/server/scripts/players/SpaceOrc.cs you will see where the "SpaceOrcData" comes from and what its doing.
Next in the same file scroll down to where your executing your scripts and in the "onServerCreated()" function add
This will load our defualt player which is defined at the top of player.cs
Next scroll down to the function "GameConnection::onClientEnterGame(%this)" and uncomment
Now, scroll down to the function "GameConnection::createPlayer(%this, %spawnPoint)" and where you see
change it to
We are done with that file now. Now lets just do some adjusting on where your player will be dropped so go into your scriptsandassets/data/missions/simple.mis file and go down to the area where you see
and change it to
This will just move the spawn point over a bit and on dry land.
Now if you have it creating dso's make sure you delete them and run your atlas demo and you should now have control of a SpaceOrc and be able to run around and do the normal thing :)
If you have any suggestions / comments / corrections let me know I will edit the resource to reflect the changes.
I'm a pretty big noob to all this so, sorry if these resources seem pointless but I do know if I was trying to figure it out more then likely there are others out there and I'm here to try to help them...
PS: quite a legal document you got to read to submit a resource ;)
This tutorial is going to be using the default atlas demo that ships with TGEA. As you know or will know it does not come with a playable character enabled its just the camera. So instead of gimping out and using lets say T3D example I chose to dig down and figure out what exactly needed to be done to add a character that the camera is bound to.
So here it goes.
//-----------------------------------------------------------------------------------------------------------------------------------
First we will need to transfer some files so I am going to grab all the ones I need from the T3D folder.
- Client Folder
No files need to be moved to the client folder.
- Server Folder
In your project you will need to go into your scripts folder and then create a folder named "players"
You want to go to your T3D example and in the scriptsandassets/server/scripts/player grab the
"player.cs" and "SpaceOrc.cs" and dump them into your newly created folder.
- Data Folder
Go into your scriptsandassets/data/shapes folder and create "players" folder.
Then go back to you T3D example in the scriptsandassets/data/shapes folder and grab the
"animations" "common" and "SpaceOrc" folders copy them into your newly created "players" folder
I think thats all we need to move for now.
Now go into your scriptsandassets/client folder and open init.cs we will be making a few changes and hopefully I can clarify what most of the things do.
Scroll down to where you see loadDefaultMission() and right above it you will want to put in the following code
function loadPlayerPickerData()
{
// Create our SimSet to hold the player datablocks for the picker
if (!isObject(PlayerDatasGroup))
new SimSet(PlayerDatasGroup);
// We have to load these audio profiles to avoid a set of warnings
exec("~/server/scripts/audioProfiles.cs");
// Load our default player script
exec("~/server/scripts/players/player.cs");
}This will basically tell the program to look at the player.cs and load our defaults for the player model we have chosen to use.
Save and close that file for now.
Next lets go into the scriptsandassets/server/scripts/game.cs file. We will make a few changes here...
First change is right at the top it will look like this -
// Pause while looking over the end game screen (in secs) $Game::EndGamePause = 10; // Our default player datablock if ($pref::Player:PlayerDB $= "") $pref::Player:PlayerDB = "SpaceOrcData";
if you go into scriptsandassets/server/scripts/players/SpaceOrc.cs you will see where the "SpaceOrcData" comes from and what its doing.
Next in the same file scroll down to where your executing your scripts and in the "onServerCreated()" function add
exec("./players/player.cs");
exec("./players/SpaceOrc.cs");This will load our defualt player which is defined at the top of player.cs
Next scroll down to the function "GameConnection::onClientEnterGame(%this)" and uncomment
// Create a player object. // %this.spawnPlayer(); UNCOMMENT THIS LINE
Now, scroll down to the function "GameConnection::createPlayer(%this, %spawnPoint)" and where you see
// Create the player object
%player = new Player() {
dataBlock = LightMaleHumanArmor;
client = %this;change it to
if (%this.playerDB $= "")
%this.playerDB = $pref::Player:PlayerDB;
// Create the player object
%player = new Player() {
dataBlock = %this.playerDB;
client = %this;We are done with that file now. Now lets just do some adjusting on where your player will be dropped so go into your scriptsandassets/data/missions/simple.mis file and go down to the area where you see
new SimGroup(PlayerDropPoints) {
new SpawnSphere() {
position = "734.208 837.731 19.2223";
rotation = "0.03379 0.088947 0.995463 221.43";
scale = "0.940827 1.97505 1";
dataBlock = "SpawnSphereMarker";
Radius = "10";
sphereWeight = "1";
indoorWeight = "1";
outdoorWeight = "1";
lockCount = "0";
locked = "False";
homingCount = "0";
};and change it to
new SimGroup(PlayerDropPoints) {
canSaveDynamicFields = "1";
Enabled = "1";
new SpawnSphere() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "646.739 354.166 36.4103";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "SpawnSphereMarker";
Radius = "10";
sphereWeight = "1";
indoorWeight = "1";
outdoorWeight = "1";
};This will just move the spawn point over a bit and on dry land.
Now if you have it creating dso's make sure you delete them and run your atlas demo and you should now have control of a SpaceOrc and be able to run around and do the normal thing :)
If you have any suggestions / comments / corrections let me know I will edit the resource to reflect the changes.
I'm a pretty big noob to all this so, sorry if these resources seem pointless but I do know if I was trying to figure it out more then likely there are others out there and I'm here to try to help them...
PS: quite a legal document you got to read to submit a resource ;)
#2
05/08/2008 (12:09 pm)
Nice little resource. You'd be surprised just how many new developers resources like this spark the thought processes needed to break into this engine.
#3
05/08/2008 (12:33 pm)
Thank You Michael and Brian!
#4
05/09/2008 (4:40 am)
Thanks, this will be a good introductory resource!
#5
05/20/2008 (1:45 am)
Nice tutorial ;)
#6
If I can suggest one correction, in scriptsAndAssets / Client / init.cs you define a new function called loadPlayerPickerData(), but in your description, this function never gets called.
I have placed the code for the function loadPlayerPickerData() at the end of init.cs and make the call to this function like this:
loadMainMenu();
loadPlayerPickerData();
loadDefaultMission();
This was tested in TGEA 1_7_1
10/13/2008 (7:35 pm)
Thankyou for the tutorial.If I can suggest one correction, in scriptsAndAssets / Client / init.cs you define a new function called loadPlayerPickerData(), but in your description, this function never gets called.
I have placed the code for the function loadPlayerPickerData() at the end of init.cs and make the call to this function like this:
loadMainMenu();
loadPlayerPickerData();
loadDefaultMission();
This was tested in TGEA 1_7_1
#7
12/28/2008 (9:09 pm)
Sweet, thanks for the tutorial. You just saved me a few hours of trying to figure it out myself :)
#8
Work has been working me a lot so not to much time a night.
12/29/2008 (4:55 pm)
No problem hopefully here soon ill be able to upload a ton of tutorials that are kind of like this one. Alot of people probably are thinking what the heck why would I post something like this but for us guys that are beginners or use to be beginners need these.Work has been working me a lot so not to much time a night.
#9
I'm only showing 21 lines in total
~GOD I HATE THESE NEW FORUMS,everything so hard to find now
02/02/2009 (8:44 am)
when I open SpaceOrc.cs I don't see onServerCreated()" or any of the other lines mentionedI'm only showing 21 lines in total
~GOD I HATE THESE NEW FORUMS,everything so hard to find now
#10
02/02/2009 (11:18 am)
What version of TGEA are you using? And I agree, these new forums / new site took away from the good look / feel they had before. But just my opinion.
#11
02/02/2009 (11:22 am)
forgot to add that, Im using TGEA_1_7_1
#12
02/15/2009 (1:19 pm)
Wulvgar sorry its taken me a while to get back on this issue with you. I am downloading 8.1 right now to see if I can find the orc script. If anyone else can please upload it in a code box for wulvgar. Otherwise may be a few more days but definitely want to help ya. 
Torque 3D Owner Michael Cozzolino
Big Monk Games