There are many situations within a game, that you might want the objects to pass information to other objects. One option is to get a handle to the object and get the instance of the class to which it is a member. But there are times where you want to pass information to a generic object without wanting to have direct access to the object's members. To do this, you can pass messages to other objects using the following method:
Code:
// Send this message to the player object
ILTMessage_Write *pMsg;
g_pLTSCommon->CreateMessage(pMsg);
pMsg->Writeuint32(OBJ_MID_PICKUP);
pMsg->Writeuint8(m_nPickupType);
pMsg->Writefloat(m_fPickupValue);
g_pLTServer->SendToObject(pMsg->Read(), m_hObject, hObj, 0);
As you may notice, you need to create a message in the same manner that you create a message for any other purpose. You also need an HOBJECT handle to the object which is sending the message, and one to the object to which you wish to send the message.
You will also notice above that the OBJ_MID_PICKUP is getting pushed onto the message.
Code:
(in shared/msgids.h)
enum EObjMessageID
{
OBJ_MID_PICKUP = 0
};
This is a value that we have defined in game code which gets referenced by the target object to determine if it has a way to deal with the incomming message. This is done below.
Code:
uint32 CPlayerSrvr::ObjectMessageFn(HOBJECT hSender, ILTMessage_Read *pMsg)
{
pMsg->SeekTo(0);
uint32 messageID = pMsg->Readuint32();
switch(messageID)
{
case OBJ_MID_PICKUP:
{
uint8 nPickupType = pMsg->Readuint8();
float fPickupValue = pMsg->Readfloat();
g_pLTServer->CPrint("PlayerSrvr -> OBJ_MID_PICKUP %d %f", nPickupType, fPickupValue);
}
break;
default:
break;
}
return BaseClass::ObjectMessageFn(hSender, pMsg);
}
credits for once are to me and the lithtech jupiter enterprise package. Found this while learning about clientFX (because shits about to get real)