Unique Units
by John Eckhardt · in RTS Starter Kit · 10/23/2006 (7:42 am) · 6 replies
I'm wondering what the best way to go about something would be. I would like my game to consist of units which are unique.
For example, let's say there's a race of Humans. The average human has 100 health, but the amount a human can have ranges between 70 and 130. There would of course be more stats that varied besides health.
What would the best way to do this? Every time I build a unit, I want it to calculate random stats for the unit. Obviously, I don't want to have thousands of datablocks for the different possibilities, so maybe is there a way that I could have a base Human datablock and modify the MaxDamage, Armor, etc. every time I create a unit?
Maybe there's a way to do it with buffs?
Thanks in advance for the help
For example, let's say there's a race of Humans. The average human has 100 health, but the amount a human can have ranges between 70 and 130. There would of course be more stats that varied besides health.
What would the best way to do this? Every time I build a unit, I want it to calculate random stats for the unit. Obviously, I don't want to have thousands of datablocks for the different possibilities, so maybe is there a way that I could have a base Human datablock and modify the MaxDamage, Armor, etc. every time I create a unit?
Maybe there's a way to do it with buffs?
Thanks in advance for the help
#2
That is once you create the object in your game:
You simply make a variable associated with that object in script:
10/24/2006 (10:52 am)
I forgot to mention that there is a second way that you could do this, but it is much more sloppy and is not recommended in this case.That is once you create the object in your game:
$myVar = new myObj(){};You simply make a variable associated with that object in script:
$myVar = new myObj()
{
datablock = "myDataBlock";
health = 100;
};
#3
In the datablock, I tried changing the maxDamage by using maxDamage = getRandom(400,600); and like you thought, it generated one random value when the datablock was loaded into the client, so all of the units had the same 'random' health.
I tried putting a maxDamage variable like you suggested in the second example, and it didn't change anything either.
Also, what didn't work is when (outside of the new unit block) I tried %player.maxDamage = 124.
Neither of those last two changes appeared to have an affect, so does anybody have any ideas?
For reference, here's the code along with what I changed:
10/31/2006 (2:01 pm)
I couldn't get this to work out on my own, so I went back to the included example and attempted unsuccessfully.In the datablock, I tried changing the maxDamage by using maxDamage = getRandom(400,600); and like you thought, it generated one random value when the datablock was loaded into the client, so all of the units had the same 'random' health.
I tried putting a maxDamage variable like you suggested in the second example, and it didn't change anything either.
Also, what didn't work is when (outside of the new unit block) I tried %player.maxDamage = 124.
Neither of those last two changes appeared to have an affect, so does anybody have any ideas?
For reference, here's the code along with what I changed:
function RTSConnection::createPlayer(%this, %spawnPoint, %index, %ai)
{
switch(%index % 3)
{
case 0:
%data = botBlock;
case 1:
%data = riflemanBlock;
case 2:
%data = shockerBlock;
}
%player = new RTSUnit()
{
scale = "1 1 1";
dataBlock = %data;
shapeFile = "~/data/shapes/player/player.dts";
path = "";
// Tried adding maxDamage = xxx in here ----------------------------------------------------------
};
MissionCleanup.add(%player);
%player.maxDamage = 177; // tried here too -------------------------------------------------------
%player.isAI = %ai;
%player.setControllingConnection(%this);
%player.setSkinName( getWord($Pref::Server::TeamInfo[%this.getTeam()], 3) );
%player.setTeam(%this.getTeam());
%player.setTransform(%spawnPoint);
%player.client = %this;
%player.stats["Kills"] = (getRandom() * 5) % 5;
%player.stats["Damage Delt"] = (getRandom() * 1000) % 1000;
// Add the unit to the group of units
%this.units.add(%player);
}
#4
I have the same problem
@Nathan i sent oyu an email askign for help with implmenting a variable and making it accessable by script
i would love to know how to do that
11/16/2006 (3:41 am)
Did you solve this?I have the same problem
@Nathan i sent oyu an email askign for help with implmenting a variable and making it accessable by script
i would love to know how to do that
#5
11/19/2006 (8:06 am)
Thats because you cant edit a datablock and the functions related to max damage are accessing the units datablock not the unit namespace. So when you put it in the units namespace it doesent have anything to do with the one in the datablock. When you declare a script object it does not inherit any thing from a datablock. The thing you should do is go into c++ and move the maxdamage variable form the datablock class to the unit class.
#6
create normal datablocks with average values, like you say the average health should be 100 for humans.
then go to /server/scripts/core/commands.cs and change the following function:
function serverCmdApplyModifier(%client, %modifier, %targetID, %duration)
{
%target = %client.resolveObjectFromGhostIndex(%targetID);
%target.addModifier(%modifier.getID());
%target.schedule(%duration, "removeModifier", %modifier.getID());
}
to
function serverCmdApplyModifier(%client, %modifier, %targetID, %duration)
{
%target = %client.resolveObjectFromGhostIndex(%targetID);
%target.addModifier(%modifier.getID());
if ( %duration )
{
%target.schedule(%duration, "removeModifier", %modifier.getID());
}
}
this will make sure that the modifiers will not wear off if the %duration == 0
next go to /server/scripts/core/buffs.cs and create some buffs that change the health to
70 percent, 80 percent, 90 percent, 100 percent, 110 pct 120 pct and 130 pct of its standard value.
then when spawning the unit you will want to take one of these modifiers randomly (no matter what race your unit is) and apply it to get this "unique" charactaristic.
12/09/2006 (7:02 am)
I really don't understand how you were planning to change the datablock from script. i thought datablocks were loaded on the start of the mission and thats it. if I wanted to do something like you right now i would to the following:create normal datablocks with average values, like you say the average health should be 100 for humans.
then go to /server/scripts/core/commands.cs and change the following function:
function serverCmdApplyModifier(%client, %modifier, %targetID, %duration)
{
%target = %client.resolveObjectFromGhostIndex(%targetID);
%target.addModifier(%modifier.getID());
%target.schedule(%duration, "removeModifier", %modifier.getID());
}
to
function serverCmdApplyModifier(%client, %modifier, %targetID, %duration)
{
%target = %client.resolveObjectFromGhostIndex(%targetID);
%target.addModifier(%modifier.getID());
if ( %duration )
{
%target.schedule(%duration, "removeModifier", %modifier.getID());
}
}
this will make sure that the modifiers will not wear off if the %duration == 0
next go to /server/scripts/core/buffs.cs and create some buffs that change the health to
70 percent, 80 percent, 90 percent, 100 percent, 110 pct 120 pct and 130 pct of its standard value.
then when spawning the unit you will want to take one of these modifiers randomly (no matter what race your unit is) and apply it to get this "unique" charactaristic.
Torque 3D Owner Nathan Bowhay - ESAL
ESALPllc
If you need help with this, just email me saying that you need further help and put a link to this thread in there as well and I will post the steps on this thread.. My email is at skienemy5555@yahoo.com.