RTSUnit Paradox
by SimU Group · in RTS Starter Kit · 11/03/2007 (2:46 pm) · 8 replies
When I create a unit using $conn.CreatePlayer(%point, 1); it gets created, and as I've understood there are two copies of this unit: on on the client side, and one on the server side.
I looked into the "CreatePlayer" function, and made it return the created unit:
But now when I try to:
I get an error, because the object ID that was returned seems to be the one created on the client side. I need to know the ID of the unit that was created on the server side (the one that is produced when, for example, the function onMouseDownUnit gets called).
I looked into the "CreatePlayer" function, and made it return the created unit:
%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);
return %player; But now when I try to:
%s = $conn.CreatePlayer(%point, 1);
PlayGUI.selectObject(%s);
commandToServer('IssueMove', getRandom(200, 150) , getRandom(200, 150), 100);I get an error, because the object ID that was returned seems to be the one created on the client side. I need to know the ID of the unit that was created on the server side (the one that is produced when, for example, the function onMouseDownUnit gets called).
#2
but now I'm back to the commandToServer trouble again !!
I'm trying to loop over a group of units, and send each of them to a separate destination !!
But using 'commandToServer' won't work, as it happens asynchronously. I played around with the netEvent.cc and netConnection.cc trying to force the server to handle the event once it occurs, but I failed !
Any ideas??
11/03/2007 (6:43 pm)
Thanks Novack !! That really is helpful... I'll remember to give you lots of credits in our acknowledgments page ;) !!but now I'm back to the commandToServer trouble again !!
I'm trying to loop over a group of units, and send each of them to a separate destination !!
But using 'commandToServer' won't work, as it happens asynchronously. I played around with the netEvent.cc and netConnection.cc trying to force the server to handle the event once it occurs, but I failed !
Any ideas??
#3
11/03/2007 (8:38 pm)
I dont see the problem, why that stops you from giving a group separate destinations?
#4
Consider the following:
This just moves the students randomly to buildings. Although I use the 'IssueMove', the result is this weird movement with no animation played !
This is because I have to wait after each 'IssueMove' for the command to get processed at the server side. I just need to make it a synchronous call.. that'll solve the problem I guess.
11/04/2007 (1:33 am)
When I only use the 'setMoveGoal' without the 'IssueMove', the units move in a wierd way, without playing the movement sequence.Consider the following:
for (%i = 0 ; %i < $Students.getCount() ; %i++)
{
%s = $Students.getObject(%i);
%s.client.selection.clear();
%s.setMoveGoal(getRandom(200, 150) SPC getRandom(200, 150) SPC "100");
%s.client.selection.add(%s);
sendAllStatsToClient(%s.client, %s);
%b = Buildings.getObject(getRandom(0, Buildings.getCount() - 1));
commandToServer('IssueMove', getword(%b.getPosition(), 0) , getword(%b.getPosition(), 1), 100);
}This just moves the students randomly to buildings. Although I use the 'IssueMove', the result is this weird movement with no animation played !
This is because I have to wait after each 'IssueMove' for the command to get processed at the server side. I just need to make it a synchronous call.. that'll solve the problem I guess.
#5
What I think confuses you, is the name of the method, setMoveGoal, but actually it not only set the goal, but triggers the movement itself, so no other command is needed after that, the unit will move.
The weird movement with setMoveGoal can be solved by adding this line:
What I see weird is that you need to select the units even when they move are in different directions, whats the purpose of have selected the units? The only sense I see on that is that later you call "issueMove", that even when is not correct, I understand something like you want to give the units a movement direction, but why, if you want them to go to some building, you give them first random destinations?
Better tell conceptually what you wanna do, stop writing this crazy code :D
11/04/2007 (8:08 am)
Lol, pal, you are doing the same thing again. CommandToServer is supossed to be done from the client, while setMoveGoal is done in the server, and both are supossed to have almost the same effect.What I think confuses you, is the name of the method, setMoveGoal, but actually it not only set the goal, but triggers the movement itself, so no other command is needed after that, the unit will move.
The weird movement with setMoveGoal can be solved by adding this line:
%this.clearAim();to Player::setMoveGoal in .\starter.RTS\server\scripts\avatars\player.cs
What I see weird is that you need to select the units even when they move are in different directions, whats the purpose of have selected the units? The only sense I see on that is that later you call "issueMove", that even when is not correct, I understand something like you want to give the units a movement direction, but why, if you want them to go to some building, you give them first random destinations?
Better tell conceptually what you wanna do, stop writing this crazy code :D
#6
I actually wanted to demonstrate... I knew setMoveGoal initiates the movement.. and I did the selection and the issueMove thing to demonstrate what I'm actually doing...
11/04/2007 (9:43 am)
Thanks Novack :$I actually wanted to demonstrate... I knew setMoveGoal initiates the movement.. and I did the selection and the issueMove thing to demonstrate what I'm actually doing...
#7
If what you want to do, is to move the units to different buildings/locations, from server side, you should do something like:
But Im not sure if that is what you wanna do.
11/04/2007 (10:08 am)
Yes, no problem at all, I just want to understand what you wanna do, to try to help you.If what you want to do, is to move the units to different buildings/locations, from server side, you should do something like:
for (%i = 0 ; %i < $Students.getCount() ; %i++)
{
%s = $Students.getObject(%i);
%b = Buildings.getObject(getRandom(0, Buildings.getCount() - 1));
%s.setMoveGoal(getword(%b.getPosition(), 0) SPC getword(%b.getPosition(), 1) SPC "100");
}But Im not sure if that is what you wanna do.
#8
Adding %this.clearAim(); fixed the whole problem...
11/04/2007 (11:13 am)
Yep.. thanks a lot... that does it ;)Adding %this.clearAim(); fixed the whole problem...
Torque 3D Owner Novack
CyberianSoftware
What you are doing in your example, is to mix commands given from the client and from the server. The creation phase, is made on the server, as the movemement itself, while the selection through the Playgui is made client side. All can be done server side, but using the proper commands (ie, see .\starter.RTS\server\scripts\core\commands.cs)
What you wanna do, should be something like this (from server side):
And BTW, be care how you use $conn, cause its client specific, which means that if you dont update it properly, you will have communication with only one client.