Game Development Community

Player Selection

by Louis Dufresne · in Artist Corner · 01/09/2004 (8:23 am) · 85 replies

I have a GUI that allows you to select from 4 players. I have all the DTS's for each model and im using the Orc's animations at this time for each player model. Ive added to prefs.cs -> prefs::player::character = ""
In the selection GUI I just change this value to correspond to the player I want. Also I have a separate CS file for each player, all of which are included in the game.cs. Now im just not sure on how or where to tell the game, in script, which player model to load when the game starts. Anyone know where this is? Or how its done?
#21
10/23/2004 (11:12 am)
Never assume. I have seen the engine do some funky stuff when it's being corrupted by bad data, and I personally have been steered into the wrong code by the debugger under certain circumstances. Seriously, if you want to protect your code from others, then just send it to my email and you have my word that no one else besides me will see it and the chances of me stealing it are about as slim as your going to get. There isn't much in this engine that I haven't seen or done yet myself. There are folks here that will vouch for my ability to keep their code confidential if they wish to do so. I won't mention names because they may not wish for others to know they have asked for my help.
#22
10/23/2004 (1:09 pm)
Mines basically default with the armor stuff added - you dont have to have the datablocks in seperate files do ya?


Function GameConnection::onConnect( %client, %name ,%armor)
{
echo("swithing to : "@ %armor);
// Send down the connection error info, the client is
// responsible for displaying this message if a connection
// error occures.
messageClient(%client,'MsgConnectionError',"",$Pref::Server::ConnectionError);

// Send mission information to the client
sendLoadInfoToClient( %client );

// Simulated client lag for testing...
// %client.setSimulatedNetParams(0.1, 30);

// Get the client's unique id:
// %authInfo = %client.getAuthInfo();
// %client.guid = getField( %authInfo, 3 );
%client.guid = 0;
addToServerGuidList( %client.guid );

// Set admin status
if (%client.getAddress() $= "local") {
%client.isAdmin = true;
%client.isSuperAdmin = true;
}
else {
%client.isAdmin = false;
%client.isSuperAdmin = false;
}

%client.armor = %armor;
%client.setPlayerName(%name);
%client.score = 0;

//
$instantGroup = ServerGroup;
$instantGroup = MissionCleanup;
echo("CADD: " @ %client @ " " @ %client.getAddress());

// Inform the client of all the other clients
%count = ClientGroup.getCount();
for (%cl = 0; %cl < %count; %cl++) {
%other = ClientGroup.getObject(%cl);
if ((%other != %client)) {
// These should be "silent" versions of these messages...
messageClient(%client, 'MsgClientJoin', "",
%other.name,
%other,
%other.sendGuid,
%other.score,
%other.isAIControlled(),
%other.isAdmin,
%other.isSuperAdmin);
}
}

// Inform the client we've joined up
messageClient(%client,
'MsgClientJoin', $iWelcome ,
%client.name,
%client,
%client.sendGuid,
%client.score,
%client.isAiControlled(),
%client.isAdmin,
%client.isSuperAdmin);

// Inform all the other clients of the new guy
messageAllExcept(%client, -1, 'MsgClientJoin', '\c1%1 joined the game.',
%client.name,
%client,
%client.sendGuid,
%client.score,
%client.isAiControlled(),
%client.isAdmin,
%client.isSuperAdmin);

// If the mission is running, go ahead download it to the client
if ($missionRunning)
%client.loadMission();
$Server::PlayerCount++;
}
#23
10/23/2004 (1:43 pm)
That all looks fine, I'm not sure what you are inputing with "$iWelcome" so I can't speak for that, can you show me your

function GameConnection::createPlayer(%this, %spawnPoint)


code so I can look at it real fast? My player datablocks reside in the player.cs file. My files don't look anything like the originals, all my troubleshooting fo others is done with the stock scripts. But as long as your datablock is good, that shouldn't be a problem. In fact, post the player datablock you are trying to allocate just so we can be sure. Or you can email them to me, your choice.
#24
10/23/2004 (1:44 pm)
Hmmm Im thinking my dts got jacked some how..
if i make it load from

avatars/default/TEST.dif
/karl/TEST1.dif
/naomi/TEST2.diff


each dts file is the same just renamed everything seems to work fine..

EDIT:
Gonzo your always 1 step ahead of me!

edit again:
i called it a dif file!
#25
10/23/2004 (1:46 pm)
Function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
echo("choosing armor:" @ %this.armor);
// Create the player object
%player = new Player() {
dataBlock = %this.armor;

client = %this;
};
MissionCleanup.add(%player);

// Player setup...
%player.setTransform(%spawnPoint);
%player.setEnergyLevel(60);
//' %player.setShapeName(%this.name);

// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());

// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}
#26
10/23/2004 (2:14 pm)
Made some dummy dts files. spher cube and triangle

and it appears to be working..


@Gonz
I took your advise and added your switch statement.. as well..
#27
10/23/2004 (2:18 pm)
Cool, so you no longer crash and you get the correct armor when you join?
#28
10/23/2004 (3:08 pm)
Yah it seems to work fine even in dedicated..could it have had something to do with the numeber of nodes and/or animations being differnet?
#29
12/03/2004 (10:54 am)
This is some great posting guys. I tried something similar to this a few months back and was told that it was impossible. I wqonder if we can zip this all up into a pack where ppl could install it easily and not input so much code by themselves possible messing something up. I'll work on it unless you guys beat me to it, as it seems ur always a step ahead of me.
#30
12/03/2004 (8:01 pm)
I don't have a

clientConnections.cs

is that due to having 1.3, not the HEAD ?
#31
12/03/2004 (8:07 pm)
*kicks his own ass causing his foot to fall out of his mouth*...

lol just found it... null my last post
#32
12/03/2004 (8:37 pm)
I'm having a problem. I'm trying to set it up so that my dmgame (which has been slightly altered to allow one flag so it has a steal the flag theme) comes up with a character selection screen before joining the server. In which case a player could select their character before joining into the server. I cant sem to get it working. If I could, then it should be possible to make the changes lised above so that it would enter players into the game with the characters they selected. I got it working on the ctf style gameplay but running a dmgame game it seems to not function the correct way. Any suggestions?
#33
01/11/2005 (8:26 am)
When you change the Armor to something like alienArmor do you also have to change the Player (Player methods) to alienPlayer at the bottom of player.cs (alien.cs) file. the only reason I ask is that if you use multiple .cs files the engine will overwrite the Player with the last Player executed according to the order of the exec(); in game.cs.

Also where would you recommend putting the
exec("~/data/shapes/player/player.cs");
if you do not want to use dsq files for all models (or if they are different)
#34
01/12/2005 (11:04 am)
Also do you have to change these settings to startMissiongui.gui if you want the player to be able to use that character in the game single player.
#35
01/12/2005 (11:21 am)
OK well I was trying to implament this and found out that this code must be old. there is no gameconnection::onconnect anymore and there is no clientconnections.cs.

EDIT: FOUND IT IN COMMON FOLDER DUH :P
#36
03/21/2005 (11:44 pm)
I'm trying to do this ... however my switch always defaults and loads whatever player type I have in there. It's as if the "armor" (I used "character") is never correct? I'm using push buttons in the gui with the command field set to $playerCharacter = Orc; ... or whatever it may be for each button. How is it that my global $playerCharacter variable is not recognized or sent properly when the join function is called. All of my scripts compile.
#37
03/22/2005 (12:04 am)
Oh, figured it out ... you need to also add $playerArmor or whatever to the %conn.setConnectArgs() in startMissionGui.gui.
#38
03/27/2005 (6:50 am)
I'm dispaired, i have try to change the player character dependent on the player name.
So i use Realm Wars and i have do this in the baseGame.cs


function GameConnection::createSinglePlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
error( "Attempting to create an angus ghost!" );
}

commandToClient(%this,'ClearInventory');

// Create the player object

%rawName = stripChars( detag( getTaggedString( %this.name ) ), "\cp\co\c6\c7\c8\c9" );

switch$(%rawName)
{
case "Elf":
%model = elf;
case "Gnome":
%model = gnome;
case "Orc":
%model = orc;
default:
%model = orc;
}


%player = new Player() {

dataBlock = %model;
client = %this;
};

This work well in the local mode but if i make a dedicated server and someone joins, Realm Wars always crashed!!
Any ideas??
#39
06/10/2005 (3:08 pm)
Anybody any idea what is wrong with that code?
#40
06/11/2005 (11:23 am)
You don't assign a client variable within the new Player() block--the block is used only for initializing persistent fields within the object being instantiated (and %client isn't one of those). You would want to do it something like %player.client = %this; after the scope of the new { } block.

You may also have some scoping issues with %model, since as far as we can tell from this example, it's first used within the switch block, but then later referenced after the switch block. I do not honestly know if this is a problem or not, but it would be something to check.