Creating RTSUnits in C
by Aerospace · in RTS Starter Kit · 07/19/2005 (11:36 am) · 2 replies
I'm having some trouble creating RTSUnits in C++. I've been tinkering with translating the following script code into C++, but haven't been successful. Any help would be much appreciated.
From gameConnection.cs:
I haven't reproduced all the statements, mostly because I haven't figured out how yet, but here is a version of what I've got so far:
It runs, but it doesn't produce a unit in the scene. Am I close? What am I missing/doing wrong?
Thanks,
Will
From gameConnection.cs:
%player = new RTSUnit()
{
scale = "1 1 1";
dataBlock = %data;
shapeFile = "~/data/shapes/player/player.dts";
path = "";
};
MissionCleanup.add(%player);
%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);I haven't reproduced all the statements, mostly because I haven't figured out how yet, but here is a version of what I've got so far:
RTSUnit *unit = new RTSUnit();
unit->registerObject();
unit->setField("scale", "1, 1, 1");
unit->setField("dataBlock", "botBlock");
unit->setField("shapeFile", "~/data/shapes/player/player.dts");
unit->setField("path", "");
RTSConnection *connection = GameConnection::getLocalClientConnection();
unit->setControllingConnection(connection);
unit->setTeam(connection->getTeam());It runs, but it doesn't produce a unit in the scene. Am I close? What am I missing/doing wrong?
Thanks,
Will
#2
07/21/2005 (2:08 pm)
Thanks! That got it working. I also had to move the registerObject() call to follow the calls to setField(), but it seems to work now.
Torque Owner Robert Stewart
Is that a typo or are have you merged the RTSConnection with GameConnection? If you are using stock just change GameConnection to RTSConnection.