Same player different ghost ids
by DIAG · in Torque Game Engine · 11/16/2004 (3:00 am) · 3 replies
Hello,
Could somebody answer me this quick question before i go mad?? :) Does a player that is ghosted across, for example, two connections, have the same ghost id (on the server) for each connection, or can it be different for different connections?
Damien
Could somebody answer me this quick question before i go mad?? :) Does a player that is ghosted across, for example, two connections, have the same ghost id (on the server) for each connection, or can it be different for different connections?
Damien
#2
11/16/2004 (7:29 pm)
Josh of course means to send a _reference_ to an object. The ghost system is responsible for sending the actual object, and any code you should write should be prepared to deal with the case that the object isn't ghosted on that connection. That's why there are if() statements in Josh's example code - if the object isn't ghosted, it has to deal with that case. getGhostIndex can return -1 if the object isn't ghosted.
#3
12/14/2004 (5:44 am)
Hey, forgot to thank you for this! it did help a great deal. cheers
Torque Owner Josh Albrecht
//write function { ... bstream->writeRangedU32(U32(con->getGhostIndex(object)), 0, NetConnection::MaxGhostCount); ... } //read function { ... //get the id of the object S32 mClientId = bstream->readRangedU32(0, NetConnection::MaxGhostCount); //find the corresponding object on teh server NetObject* pObject = con->resolveObjectFromGhostIndex(mClientId); if(pObject) { //do whatever you want with pObject } ... }If you want to send from the server to the client, use resolveGhost in the read function instead of resolveObjectFromGhostIndex.
Hope that helped!