C++ and script
by gamer · in Torque Game Engine · 06/06/2006 (4:28 pm) · 3 replies
I am trying to display amingLocation on my enemy's body,
inside the CrossHairGuiHud::onRender() I have the following relevant code:
script side I have
two issues:
1.the Id displayingAmingLoc echos out is different from the one I am seeing by looking at the enemy player in the mission editor. why?? they are both handles to an aiplayer though.
2. in the c++ code, Can I check to see if (ShapeBase* obj) is actually an instance of the Player class and then cast the (ShapeBase* obj) into a Player? can someone provide some sample code?
thanks!
inside the CrossHairGuiHud::onRender() I have the following relevant code:
if (ShapeBase* obj = dynamic_cast<ShapeBase*>(info.object))
if (obj->getShapeName()) {
Con::executef(this,7,"displayAimingLoc",obj->getClassName(),Con::getIntArg(obj->getId()),Con::getFloatArg(endPos.x),Con::getFloatArg(endPos.y),Con::getFloatArg(endPos.z), Con::getFloatArg(obj->getDamageValue()));
...script side I have
function GuiCrossHairhud::displayAimingLoc(%this,%className,%id,%x,%y,%z, %damageVal)
{
echo("className is "@%className);
echo("id is "@%id);
}two issues:
1.the Id displayingAmingLoc echos out is different from the one I am seeing by looking at the enemy player in the mission editor. why?? they are both handles to an aiplayer though.
2. in the c++ code, Can I check to see if (ShapeBase* obj) is actually an instance of the Player class and then cast the (ShapeBase* obj) into a Player? can someone provide some sample code?
thanks!
About the author
#2
Have a look in netConnection.h around line 820 you'll see several functions that can be used to convert to and from a ghost index.
To test if a ShapeBase is a specific type you can use getType(), in this specific case you'll want to compare against the PlayerObjectType E.G
06/06/2006 (5:09 pm)
In the CrossHairGuiHud you'll be dealing with the client version of objects which are assigned ghost ID's, these ID's are different to the ID's the server assigned to the same object (the server maintains a translation map to convert between the server ID and the ghost ID on a specific client, see resolveObjectFromGhostIndex), the mission editor afaik displays the server ID's.Have a look in netConnection.h around line 820 you'll see several functions that can be used to convert to and from a ghost index.
To test if a ShapeBase is a specific type you can use getType(), in this specific case you'll want to compare against the PlayerObjectType E.G
if (obj->getType() & PlayerObjectType)
{
// obj is a player
Player* pPlayer = static_cast<Player*>(obj);
// do stuff
}
#3
I just posted this exact same problem. lol Did you get it to work. I had diffculties implimenting the resolveghostid, etc. Neither the getGhostID or the ResolveGhostIndex would ever work out to be something I could use in the server(*script*) code. Can you post your CrossHairGuiHud code for an example.
10/06/2006 (9:40 am)
@gamerI just posted this exact same problem. lol Did you get it to work. I had diffculties implimenting the resolveghostid, etc. Neither the getGhostID or the ResolveGhostIndex would ever work out to be something I could use in the server(*script*) code. Can you post your CrossHairGuiHud code for an example.
Torque Owner Cinder Games