Custom player stats
by GAMEHACK3R · in Technical Issues · 07/15/2007 (10:00 pm) · 9 replies
From IRC::
i dont need to be able to dynamically change the stats in game .
what i am doing is letting the player customise their character before they enter the game. And when they chose a mission then the "player" is created with the custom stats that they chose. It has to work in multiplayer and my AI shares the same datablock.
The stats im looking at making customisable are
minJumpSpeed = 20;
maxJumpSpeed = 30;
jumpForce = 8.3 * 90;
jumpEnergyDrain = 0;
minJumpEnergy = 0;
jumpDelay = 15;
runForce = 48 * 90;
runEnergyDrain = 0;
minRunEnergy = 0;
maxForwardSpeed = 54;
maxBackwardSpeed = 53;
maxSideSpeed = 53;
mass = 90;
drag = 0.3;
maxdrag = 0.4;
density = 10;
maxDamage = 100;
maxEnergy = 60;
repairRate = 0.33;
energyPerDamagePoint = 75.0;
rechargeRate = 0.256;
i have already looked at teh dynamic speed change , custom stats (not multiplayer) and breaking energy and health out of the data block resources
is there a method for doing this with script ie when the playermodel is created and using a multiplier to change the stat??????
player::minJumpSpeed = player::minJumpSpeed x 0.3;
am i heading in the right direction ,if not can someone point me in the right direction
i dont need to be able to dynamically change the stats in game .
what i am doing is letting the player customise their character before they enter the game. And when they chose a mission then the "player" is created with the custom stats that they chose. It has to work in multiplayer and my AI shares the same datablock.
The stats im looking at making customisable are
minJumpSpeed = 20;
maxJumpSpeed = 30;
jumpForce = 8.3 * 90;
jumpEnergyDrain = 0;
minJumpEnergy = 0;
jumpDelay = 15;
runForce = 48 * 90;
runEnergyDrain = 0;
minRunEnergy = 0;
maxForwardSpeed = 54;
maxBackwardSpeed = 53;
maxSideSpeed = 53;
mass = 90;
drag = 0.3;
maxdrag = 0.4;
density = 10;
maxDamage = 100;
maxEnergy = 60;
repairRate = 0.33;
energyPerDamagePoint = 75.0;
rechargeRate = 0.256;
i have already looked at teh dynamic speed change , custom stats (not multiplayer) and breaking energy and health out of the data block resources
is there a method for doing this with script ie when the playermodel is created and using a multiplier to change the stat??????
player::minJumpSpeed = player::minJumpSpeed x 0.3;
am i heading in the right direction ,if not can someone point me in the right direction
#2
07/17/2007 (5:39 pm)
Datablocks are meant to only be sent once when the client is connecting to the server. They're not meant to dynamically change. You might want to add a value to the player object in C++ that impacts the player object movement function.
#3
ATM this works in single player only and is entirely script based it also does NOT effect any ai that share the playerdata block ie AI guard or Killer kork
for those of you wanting a simple method for changing player stats here it is and it work for ALL vars in the player data block
Create a new GUI that is linked to the mainMenu
new GuiControl(customisePlayer) {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiChunkedBitmapCtrl() {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "2 1";
Extent = "800 602";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "./background.jpg";
useVariable = "0";
tile = "0";
};
new GuiButtonCtrl(fastplayer) {
canSaveDynamicFields = "0";
Profile = "GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "74 158";
Extent = "207 161";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "setfastplayer();";
hovertime = "1000";
text = "fastPlayer";
groupNum = "-1";
buttonType = "PushButton";
};
new GuiButtonCtrl(slowplayer) {
canSaveDynamicFields = "0";
Profile = "GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "330 158";
Extent = "198 159";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "setslowplayer();";
hovertime = "1000";
text = "slowPlayer";
groupNum = "-1";
buttonType = "PushButton";
};
new GuiButtonCtrl(BackToMainMenu) {
canSaveDynamicFields = "0";
Profile = "GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "226 383";
Extent = "140 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "Canvas.setContent(mainMenuGui);";
hovertime = "1000";
text = "back";
groupNum = "-1";
buttonType = "PushButton";
};
new GuiTextCtrl(checkmySTAT) {
canSaveDynamicFields = "0";
Profile = "GuiBigTextProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "212 440";
Extent = "174 40";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
text = "sfdafasdfadf";
maxLength = "1024";
};
};
//--- OBJECT WRITE END ---
function setslowplayer()
{
$myNewPlayerSpeed = 2;
echo("stat decreased");
checkmySTAT.setTEXT( $myNewPlayerSpeed );
}
function setfastplayer()
{
$myNewPlayerSpeed = 200;
echo("stat increased");
checkmySTAT.setTEXT( $myNewPlayerSpeed );
}
sorry bout it looking terrible but its just to give u an idea what to do
it has two buttons which change the movement speed from 2 to 200 which gives a noticeable change
you can set your new speed by pressing one of the two buttons
open your Game.cs and add to GameConnection::createPlayer
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!" );
}
// Create the player object
%player = new Player() {
dataBlock = PlayerBody;
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Starting equipment
%player.setInventory(Crossbow,1);
%player.setInventory(CrossbowAmmo,10);
%player.mountImage(CrossbowImage,0);
// 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);
++ %this.player.getDataBlock().maxForwardSpeed = $myNewPlayerSpeed; //this is what changes the speed
}
NB if someone knows how to make this work for multiplayer drop me a line .. ill be working on it either way
07/18/2007 (5:25 am)
!!!!!!!! Success !!!!!!!! ATM this works in single player only and is entirely script based it also does NOT effect any ai that share the playerdata block ie AI guard or Killer kork
for those of you wanting a simple method for changing player stats here it is and it work for ALL vars in the player data block
Create a new GUI that is linked to the mainMenu
new GuiControl(customisePlayer) {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiChunkedBitmapCtrl() {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "2 1";
Extent = "800 602";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "./background.jpg";
useVariable = "0";
tile = "0";
};
new GuiButtonCtrl(fastplayer) {
canSaveDynamicFields = "0";
Profile = "GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "74 158";
Extent = "207 161";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "setfastplayer();";
hovertime = "1000";
text = "fastPlayer";
groupNum = "-1";
buttonType = "PushButton";
};
new GuiButtonCtrl(slowplayer) {
canSaveDynamicFields = "0";
Profile = "GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "330 158";
Extent = "198 159";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "setslowplayer();";
hovertime = "1000";
text = "slowPlayer";
groupNum = "-1";
buttonType = "PushButton";
};
new GuiButtonCtrl(BackToMainMenu) {
canSaveDynamicFields = "0";
Profile = "GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "226 383";
Extent = "140 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "Canvas.setContent(mainMenuGui);";
hovertime = "1000";
text = "back";
groupNum = "-1";
buttonType = "PushButton";
};
new GuiTextCtrl(checkmySTAT) {
canSaveDynamicFields = "0";
Profile = "GuiBigTextProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "212 440";
Extent = "174 40";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
text = "sfdafasdfadf";
maxLength = "1024";
};
};
//--- OBJECT WRITE END ---
function setslowplayer()
{
$myNewPlayerSpeed = 2;
echo("stat decreased");
checkmySTAT.setTEXT( $myNewPlayerSpeed );
}
function setfastplayer()
{
$myNewPlayerSpeed = 200;
echo("stat increased");
checkmySTAT.setTEXT( $myNewPlayerSpeed );
}
sorry bout it looking terrible but its just to give u an idea what to do
it has two buttons which change the movement speed from 2 to 200 which gives a noticeable change
you can set your new speed by pressing one of the two buttons
open your Game.cs and add to GameConnection::createPlayer
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!" );
}
// Create the player object
%player = new Player() {
dataBlock = PlayerBody;
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Starting equipment
%player.setInventory(Crossbow,1);
%player.setInventory(CrossbowAmmo,10);
%player.mountImage(CrossbowImage,0);
// 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);
++ %this.player.getDataBlock().maxForwardSpeed = $myNewPlayerSpeed; //this is what changes the speed
}
NB if someone knows how to make this work for multiplayer drop me a line .. ill be working on it either way
#4
07/18/2007 (5:34 am)
Congrats on making progress. But as Matt said, you do not want to modify the values of a datablock dynamically. This will be a problem as work on the multi-player portion of your game.
#5
07/18/2007 (5:54 am)
What kind of problems am i going to be facing ?
#6
07/18/2007 (6:06 am)
If the effects are stable, which they are not guaranteed to be, you'll most likely only see them affecting the client portion of the game play, and not the server side.
#7
While not the only way, this method is clean, quick to implement, and preserves the client/server architecture.
07/18/2007 (6:31 am)
Have a look at this resource: Variable Player Stats.While not the only way, this method is clean, quick to implement, and preserves the client/server architecture.
#8
that resource is single player only as well :( but im going to use it
also since the variable that i am using is created before the server is created(in the mainMenu) and it is a global it will exist on the server when a single player game is created , but when a client connects (multiplayer) they share the same variable that the client/server holds and not the one they selected.
how do i send a variable to the server that the client has created before the player is created on the server ie like a Pref::???? so that the change that the client has made are used on the server for multiplayer
07/18/2007 (6:25 pm)
@michaelthat resource is single player only as well :( but im going to use it
also since the variable that i am using is created before the server is created(in the mainMenu) and it is a global it will exist on the server when a single player game is created , but when a client connects (multiplayer) they share the same variable that the client/server holds and not the one they selected.
how do i send a variable to the server that the client has created before the player is created on the server ie like a Pref::???? so that the change that the client has made are used on the server for multiplayer
#9
this is an expansion on the single player above, and this works in multiplayer , and does not effect AI's that share the same datablock. ATM it player customisation is set before the player is created , so this would be a perfect method for someone trying to do a player model/character select. But im am using it to make the players Speeds/health/energy/mass/ammo customisable by the client.
in your "joinServerGUI.gui" go to "function joinServerGui::join(%this)" and change "%conn.setConnectArgs($pref::Player::Name);"
to
%conn.setConnectArgs($pref::Player::Name, $myNewPlayerSpeed);
do the same in "startMissionGui.gui" , "function SM_StartMission()"
now when the player logs into the server, the clients will tell the server what their "$myNewPlayerSpeed" variable is.
Now you have to make "$myNewPlayerSpeed" usable on the server, to do this go to "common/server/clientConnections.cs" . Change
"function GameConnection::onConnect( %client, %name)"
to
function GameConnection::onConnect( %client, %name , $myNewPlayerSpeed)
and add the line
%client.myNewPlayerSpeed = $myNewPlayerSpeed;
after " %client.score = 0; " in "function GameConnection::onConnect"
this will make it so we can use " $myNewPlayerSpeed " on the server
now all we need to do is to change ""%this.player.getDataBlock().maxForwardSpeed = $myNewPlayerSpeed;" which was the single player only version in "starter.fps/server/game/cs"
%this.player.getDataBlock().maxForwardSpeed = %this.myNewPlayerSpeed;
and we are done. This method works perfectly for LAN multiplayer or Single player but you will notice LAG when playing ONLINE(not tested with a remote client, this has been expressed on IRC). This method suits myself since i have a large degree of player customisation and this provides the flexibility i need you can change ANYTHING in the playerdata block using this method. Also note that if one of the players is killed/respawned all of the players variables will be effected by this.
07/20/2007 (6:46 pm)
!!!!!!!!WORKING !!!!!!!!!!! Multiplayer Stat/character/pref selectionthis is an expansion on the single player above, and this works in multiplayer , and does not effect AI's that share the same datablock. ATM it player customisation is set before the player is created , so this would be a perfect method for someone trying to do a player model/character select. But im am using it to make the players Speeds/health/energy/mass/ammo customisable by the client.
in your "joinServerGUI.gui" go to "function joinServerGui::join(%this)" and change "%conn.setConnectArgs($pref::Player::Name);"
to
%conn.setConnectArgs($pref::Player::Name, $myNewPlayerSpeed);
do the same in "startMissionGui.gui" , "function SM_StartMission()"
now when the player logs into the server, the clients will tell the server what their "$myNewPlayerSpeed" variable is.
Now you have to make "$myNewPlayerSpeed" usable on the server, to do this go to "common/server/clientConnections.cs" . Change
"function GameConnection::onConnect( %client, %name)"
to
function GameConnection::onConnect( %client, %name , $myNewPlayerSpeed)
and add the line
%client.myNewPlayerSpeed = $myNewPlayerSpeed;
after " %client.score = 0; " in "function GameConnection::onConnect"
this will make it so we can use " $myNewPlayerSpeed " on the server
now all we need to do is to change ""%this.player.getDataBlock().maxForwardSpeed = $myNewPlayerSpeed;" which was the single player only version in "starter.fps/server/game/cs"
%this.player.getDataBlock().maxForwardSpeed = %this.myNewPlayerSpeed;
and we are done. This method works perfectly for LAN multiplayer or Single player but you will notice LAG when playing ONLINE(not tested with a remote client, this has been expressed on IRC). This method suits myself since i have a large degree of player customisation and this provides the flexibility i need you can change ANYTHING in the playerdata block using this method. Also note that if one of the players is killed/respawned all of the players variables will be effected by this.
Torque Owner GAMEHACK3R
%this.player.getDataBlock().MaxForwardSpeed = 200;
this does not effect my AI(which is a good thing) but i have no idea how to make each client have their own maxforwardspeed
i would like to be able to use a variable that is modified by a + or - button before the player is created ie "$mystat"