Client side onAdd mimic needed?
by Novack · in RTS Starter Kit · 10/31/2007 (11:43 am) · 6 replies
This is the second time I found myself in this chokepoint, so I dont know if its is cause I have some conceptual misunderstanding.
I need to somehow know when effectively a unit/building is ghosted to the client/s. Without that info, I cant send inmediate commands affecting that recently created units/buildings to the client, cause I dont know exactly if it were actually ghosted. So the next move would be to send a message from the client when the unit/building "appears" and that way the server reacts, and can send the proper orders.
My biggest doubt is if Im concetually wrong here, because there are no "onAdd" client side events, maybe there is a purpose for that, or there is no point at all on having that functions.
I have two concrete cases:
1) for a period of time X, I need to show a different gui for a new building. The problem is that I give the directives for that from the server, but when I sent commandToClient instructions, I found that still there is no building client side (ghost id returning -1).
2) I need to add a new gui control attached to a new unit/s. The gui is obviously client side, but I dont know when to attach it, since I dont know when its ghosted (again, ghost id returning -1).
I would appreciate if someone can give me hand on understand this better.
I need to somehow know when effectively a unit/building is ghosted to the client/s. Without that info, I cant send inmediate commands affecting that recently created units/buildings to the client, cause I dont know exactly if it were actually ghosted. So the next move would be to send a message from the client when the unit/building "appears" and that way the server reacts, and can send the proper orders.
My biggest doubt is if Im concetually wrong here, because there are no "onAdd" client side events, maybe there is a purpose for that, or there is no point at all on having that functions.
I have two concrete cases:
1) for a period of time X, I need to show a different gui for a new building. The problem is that I give the directives for that from the server, but when I sent commandToClient instructions, I found that still there is no building client side (ghost id returning -1).
2) I need to add a new gui control attached to a new unit/s. The gui is obviously client side, but I dont know when to attach it, since I dont know when its ghosted (again, ghost id returning -1).
I would appreciate if someone can give me hand on understand this better.
About the author
http://cyberiansoftware.com.ar/
#2
Although RTSBuilding::onAdd doesnt work (and I only see RTSBuildingMarker::onAdd on C++ side, which I neither cant make to work on script), RTSUnitData::onAdd catches the new building, but I dont know if this is the right moment, cause I dont understand very well this, and for some reason, the .client dina-field is not working on the catched new unit/building. That bring me to another question, how I know what parameters such function have to/can use?
Hope you have the enough good humor to try to organize this mess...
Edit: Ok to put some order, to my futil initial rush:
* RTSBuilding::onAdd should be the same as RTSUnit::onAdd, cos it inherits from RTSUnit, thats why I didnt see on C++ (sorry)
* In the script it exists a server side RTSUnitData::onAdd(%this,%obj) but it receives the unit/building before the assignment of tagged fields, which I think means that there is no ghost yet, just too early.
10/31/2007 (3:02 pm)
Thanks Stephen, so I was almost on the right path. Nevertheless Ive been playing with RTSBuilding::onAdd(...) without results. How it works? I mean, the callback works in wich direction? How would be the sequence? And you mean that only adding such script function will catch the event?Although RTSBuilding::onAdd doesnt work (and I only see RTSBuildingMarker::onAdd on C++ side, which I neither cant make to work on script), RTSUnitData::onAdd catches the new building, but I dont know if this is the right moment, cause I dont understand very well this, and for some reason, the .client dina-field is not working on the catched new unit/building. That bring me to another question, how I know what parameters such function have to/can use?
Hope you have the enough good humor to try to organize this mess...
Edit: Ok to put some order, to my futil initial rush:
* RTSBuilding::onAdd should be the same as RTSUnit::onAdd, cos it inherits from RTSUnit, thats why I didnt see on C++ (sorry)
* In the script it exists a server side RTSUnitData::onAdd(%this,%obj) but it receives the unit/building before the assignment of tagged fields, which I think means that there is no ghost yet, just too early.
#3
Im very confused now, cause "::onAdd" should work only in server side then...
10/31/2007 (4:31 pm)
BTW, this is on void GameBase::scriptOnAdd()if (!isGhost())
Con::executef(mDataBlock,2,"onAdd",scriptThis());Im very confused now, cause "::onAdd" should work only in server side then...
#4
You could turn it around by putting in a line just like that (without the !isGhost()) to a unique callback (can just make one up), such as :
and then you would catch your objects adding via script:
That's all off the top of my head--won't work right off the bat, but should get you close.
10/31/2007 (4:36 pm)
Ah you are actually correct---I had forgotten GameBase threw that in.You could turn it around by putting in a line just like that (without the !isGhost()) to a unique callback (can just make one up), such as :
if (isGhost() )
Con::executef(this, 2, "onAddOnClient" );and then you would catch your objects adding via script:
RTSBuilding::onAddOnClient(%this)
{
...
}That's all off the top of my head--won't work right off the bat, but should get you close.
#5
10/31/2007 (4:39 pm)
Ok, Stephen thank you, Ill give it a try now!
#6
It works like a charm :)
11/01/2007 (8:06 pm)
Ok that exactly does'nt work, and my knowledge of Torque is still limited to understand why, so I came back to RTSUnit.cc, and on bool RTSUnit::onAdd() (around line 195) added right before the "return true;" line:if (isClientObject()) Con::executef(this, 1, "onAddOnClient");
It works like a charm :)
Torque 3D Owner Stephen Zepp
It's possible you may be having trouble catching the onAdd() call, but something like RTSBuilding::onAdd(...) should do the trick if I'm thinking this through properly.