4. MXG Weapon Mod - Advanced Crosshair
by Marcus L · 08/13/2010 (10:50 pm) · 29 comments
Tested on: 1.1b2
This resource will give you an advanced crosshair/reticle like most modern FPS games use (CoD). Parts of this resource is based of this resource.
-Crosshair spread depending on movement speed.
-Crosshair spread depending on pose.
-Crosshair spread depending on rotation speed.
-Crosshair "hit mark" that indicates if you've hit something/one.
-Crosshair image depending on aimed objects team.
--Ally crosshair
--Enemy crosshair
--Neutral crosshair
This resource (unlike the previous ones) does not require that you've installed any of my previous resources :D.
To install this resource you'll first need to download this file.
Then you'll need to place the guiAnimatedCrosshairHud.cpp in folder: T3D/fps/guiAnimatedCrosshairHud.cpp and add it in C++.
And then, some changes here and there, and like the previous, this is how to install this part:
Where it says // Added, it means that the line is added.
Where it says // Removed, it means that the line is removed.
Where it says // Changed, it means that the line is changed.
Where it says ..., it means that there is code between what ever that was last written.
Whenever it says ..., there will be an comment below describing what function it is.
I recommend you using CTRL + F to find where to put the code blocks. Remember to backup before installing.
Then, in T3D/shapeBase.cpp edit the following:
In T3D/shapeBase.h add the following:
Now, in T3D/shapeImage.cpp:
Soon there, only two edits left. Now in T3D/player.cpp:
Can't believe i forgot T3D/player.h (yes, i originally forgot it):
Now (re)build while you add the next part:
Ok, this is the TorqueScript part, first add the following to the bottom of scripts/client/client.cs:
Then add the following in all your player classes "damage" function; default class Armor::damage, located in scripts/server/player.cpp:
Next, add this for all the weapon images that uses a crosshair:
Next last, you'll have to add a team value to the player blocks by adding team = "teamval", where "teamval" is the team string (Ex. "Red" or "Blue").
Lastly, replace the current reticle block with this one:
Done!
Now for some notes:
First off, the prone crosshair is untested and therefore not intended to work, same for swimming. Second, the team system was really quickly and roughly made, so nothing special there. Third, the crosshair is set by reticle.setBitmap(path); and the path should not point to a file, it should point to the crosshair file base, for example:
An advice from me would be to have a look in the zip for a better overview of the structure.
Fourth note; There is something strange with the debug build, so if you're going to use debug, then note that the ticking will be slower.
Fifth note; When mounting vehicles or dismounting your weapon, it will screw up the crosshair. This can be fixed by calling reticle.setBitmap(""); to clear out the reticle. As for using weapons that are mounted to the vehicle it self, will require changes. Not sure how to fix it tho.
Last, oh wait, what's that? I can't hear you form across the interwebs. You demand a video? note: for some strange reason, frapsing slowed down the crosshair, so know that it is faster in-game.
Now lastly, if you stumble upon some issues, let me know.
Also know that my methods might not be correct, nor the most professional. Therefore if you see some silly mistakes please leave a comment with the "fix".
Next resource will be "FPS like inventory system", and no source change required :D.
Other resources in my Weapon Mod:
1. MXG Weapon Mod - Decals Depending on Material
2. MXG Weapon Mod - Explosion and SFX Depending on Material
3. MXG Weapon Mod - Structure and Armor Piercing Projectiles
4. MXG Weapon Mod - Advanced Crosshair
Thanks,
Marcus L.
This resource will give you an advanced crosshair/reticle like most modern FPS games use (CoD). Parts of this resource is based of this resource.
Quote:like most modern FPS gamesTo be exact:
-Crosshair spread depending on movement speed.
-Crosshair spread depending on pose.
-Crosshair spread depending on rotation speed.
-Crosshair "hit mark" that indicates if you've hit something/one.
-Crosshair image depending on aimed objects team.
--Ally crosshair
--Enemy crosshair
--Neutral crosshair
This resource (unlike the previous ones) does not require that you've installed any of my previous resources :D.
To install this resource you'll first need to download this file.
Then you'll need to place the guiAnimatedCrosshairHud.cpp in folder: T3D/fps/guiAnimatedCrosshairHud.cpp and add it in C++.
And then, some changes here and there, and like the previous, this is how to install this part:
Where it says // Added, it means that the line is added.
Where it says // Removed, it means that the line is removed.
Where it says // Changed, it means that the line is changed.
Where it says ..., it means that there is code between what ever that was last written.
Whenever it says ..., there will be an comment below describing what function it is.
I recommend you using CTRL + F to find where to put the code blocks. Remember to backup before installing.
Then, in T3D/shapeBase.cpp edit the following:
... //In ShapeBase::ShapeBase() mMass( 1.0f ), mOneOverMass( 1.0f ), mPose( "StandPose" ), // Added mTeam( "" ), // Addedthat was much O_o
In T3D/shapeBase.h add the following:
...
//In public of ShapeBaseImageData
bool accuFire; ///< Should we automatically make image's aim converge with the crosshair?
bool cloakable; ///< Is this image cloakable when mounted?
// Added ->
F32 maxSpread; ///< MaxSpread, how much should the crosshair spread?
F32 minSpread; ///< MinSpread, how low should it go?
F32 maxCrouchSpread; ///< MaxCrouchSpread, how much should the crosshair spread when crouching?
F32 minCrouchSpread; ///< MinCrouchSpread, how low should it go when crouching?
//F32 maxProneSpread; ///< MaxProneSpread, how much should the crosshair spread when proneing?
//F32 minProneSpread; ///< MinProneSpread, how low should the crosshair go when proneing?
// Added <-
...
//In protected of class ShapeBase
TSThread *mHulkThread;
VectorF damageDir;
const char* mPose; // Added
const char* mTeam; // Added
...
//In public of class ShapeBase
/// @return Damage factor, between 0.0 - 1.0
F32 getDamageValue();
/// Returns the rate at which the object regenerates damage
F32 getRepairRate() { return mRepairRate; }
// Added ->
/// Sets the player's pose.
void setPose(const char* pose) { mPose = pose; }
/// Gets the player's pose.
const char* getPoseString() { return mPose; }
/// Sets the player's team.
void setTeam(const char* team) { mTeam = team; }
/// Gets the player's team.
const char* getTeam() { return mTeam; }
// Added <-Now, in T3D/shapeImage.cpp:
...
//In ShapeBaseImageData::ShapeBaseImageData()
projectile = NULL;
cloakable = true;
maxSpread = 0; // Added ->
minSpread = 0;
maxCrouchSpread = 0;
minCrouchSpread = 0;
//maxProneSpread = 0;
//minProneSpread = 0; // Added <-
...
//In ShapeBaseImageData::initPersistFields()
addField( "minEnergy", TypeF32, Offset(minEnergy, ShapeBaseImageData),
"Minimum Image energy for it to be operable." );
addField( "accuFire", TypeBool, Offset(accuFire, ShapeBaseImageData),
"Flag to control whether the Image's aim is automatically converged with "
"the crosshair.nCurrently unused." );
addField("maxSpread", TypeF32, Offset(maxSpread, ShapeBaseImageData), // Added ->
"The value of the crosshairs max spread.");
addField("minSpread", TypeF32, Offset(minSpread, ShapeBaseImageData),
"The value of the crosshairs min spread.");
addField("maxCrouchSpread", TypeF32, Offset(maxCrouchSpread, ShapeBaseImageData),
"The value of the crosshairs max spread when crouching.");
addField("minCrouchSpread", TypeF32, Offset(minCrouchSpread, ShapeBaseImageData),
"The value of the crosshairs min spread when crouching.");
//addField("maxProneSpread", TypeF32, Offset(maxProneSpread, ShapeBaseImageData),
// "The value of the crosshairs max spread when proneing.");
//addField("minProneSpread", TypeF32, Offset(minProneSpread, ShapeBaseImageData),
// "The value of the crosshairs min spread when proneing."); // Added <-
...
//In ShapeBaseImageData::packData(BitStream* stream)
stream->write(minEnergy);
stream->writeFlag(hasFlash);
// Client doesn't need accuFire
stream->write(maxSpread); // Added ->
stream->write(minSpread);
stream->write(maxCrouchSpread);
stream->write(minCrouchSpread);
//stream->write(maxProneSpread);
//stream->write(minProneSpread); // Added <-
...
//In ShapeBaseImageData::unpackData(BitStream* stream)
stream->read(&minEnergy);
hasFlash = stream->readFlag();
stream->read(&maxSpread); // Added ->
stream->read(&minSpread);
stream->read(&maxCrouchSpread);
stream->read(&minCrouchSpread);
//stream->read(&maxProneSpread);
//stream->read(&minProneSpread); // Added <-Soon there, only two edits left. Now in T3D/player.cpp:
...
//In PlayerData::initPersistFields()
addField( "pickupRadius", TypeF32, Offset(pickupRadius, PlayerData),
"Radius around the player to collide with Items in the scene (on server)." );
addField( "maxTimeScale", TypeF32, Offset(maxTimeScale, PlayerData),
"Maximum time scale for action animations.n"
"Action animations are automatically scaled to match the ground "
"velocity; this field limits the maximum time scale." );
// Added ->
addField( "team", TypeString, Offset(team, PlayerData),
"Player's team variable" );
// Added <-
...
//In Player::onAdd()
mWorkingQueryBox.minExtents.set(-1e9f, -1e9f, -1e9f);
mWorkingQueryBox.maxExtents.set(-1e9f, -1e9f, -1e9f);
// Added ->
if(mDataBlock->team)
Parent::setTeam(mDataBlock->team);
// Added <-
...
//In Player::setPose( Pose pose )
// Not added yet, just assign the pose and return.
if ( !isProperlyAdded() )
return;
Point3F boxSize(1,1,1);
// Changed ->
// Resize the player boxes
switch (pose)
{
case StandPose:
boxSize = mDataBlock->boxSize;
Parent::setPose("StandPose");
break;
case CrouchPose:
boxSize = mDataBlock->crouchBoxSize;
Parent::setPose("CrouchPose");
break;
case PronePose:
boxSize = mDataBlock->proneBoxSize;
Parent::setPose("PronePose");
break;
case SwimPose:
boxSize = mDataBlock->swimBoxSize;
Parent::setPose("SwimPose");
break;
}
// Changed <-Can't believe i forgot T3D/player.h (yes, i originally forgot it):
// Jump off surfaces at their normal rather than straight up bool jumpTowardsNormal; // Added -> // The player's team variable. const char* team; // Added <-
Now (re)build while you add the next part:
Ok, this is the TorqueScript part, first add the following to the bottom of scripts/client/client.cs:
function clientCmdHitMark()
{
Reticle.setHitMark(1);
}Then add the following in all your player classes "damage" function; default class Armor::damage, located in scripts/server/player.cpp:
// Added -> // Render the HitMark commandToClient(%sourceClient, 'HitMark'); // Added <- // Update the numerical Health HUD %obj.updateHealth();
Next, add this for all the weapon images that uses a crosshair:
// Crosshair //MXG: These values are not messured in any way, // these values are only random values that // worked fine for the rifle i used for testing. maxSpread = 6.0; minSpread = 4.0; maxCrouchSpread = 3.5; minCrouchSpread = 2.5; //maxProneSpread = 2.0; //minProneSpread = 3.5;
Next last, you'll have to add a team value to the player blocks by adding team = "teamval", where "teamval" is the team string (Ex. "Red" or "Blue").
Lastly, replace the current reticle block with this one:
new GuiDynamicCrosshairHud(Reticle) {
position = "272 172";
extent = "256 256";
minExtent = "8 8";
horizSizing = "center";
vertSizing = "center";
profile = "GuiModelessDialogProfile";
visible = "0";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
bitmap = "art/gui/weaponHud/blank.png";
};Done!
Now for some notes:
First off, the prone crosshair is untested and therefore not intended to work, same for swimming. Second, the team system was really quickly and roughly made, so nothing special there. Third, the crosshair is set by reticle.setBitmap(path); and the path should not point to a file, it should point to the crosshair file base, for example:
defaultCrosshair_right.png defaultCrosshair_bottom.png defaultCrosshair_left.png defaultCrosshair_up.pngif that would be the case, then the setBitmap's path should point to "defaultCrosshair" not "defaultCrosshair_right.png" or "defaultCrosshair.png".
An advice from me would be to have a look in the zip for a better overview of the structure.
Fourth note; There is something strange with the debug build, so if you're going to use debug, then note that the ticking will be slower.
Fifth note; When mounting vehicles or dismounting your weapon, it will screw up the crosshair. This can be fixed by calling reticle.setBitmap(""); to clear out the reticle. As for using weapons that are mounted to the vehicle it self, will require changes. Not sure how to fix it tho.
Last, oh wait, what's that? I can't hear you form across the interwebs. You demand a video? note: for some strange reason, frapsing slowed down the crosshair, so know that it is faster in-game.
Now lastly, if you stumble upon some issues, let me know.
Also know that my methods might not be correct, nor the most professional. Therefore if you see some silly mistakes please leave a comment with the "fix".
Next resource will be "FPS like inventory system", and no source change required :D.
Other resources in my Weapon Mod:
1. MXG Weapon Mod - Decals Depending on Material
2. MXG Weapon Mod - Explosion and SFX Depending on Material
3. MXG Weapon Mod - Structure and Armor Piercing Projectiles
4. MXG Weapon Mod - Advanced Crosshair
Thanks,
Marcus L.
#22
Oh, and thanks for the crosshairs, much appreciated (:D.
08/29/2010 (8:51 pm)
Quote:Any thought on using image sequences so that you could animate instead of spreading the crosshair? I found myself wanting an animated reticle with a rotating outer ring and a spreading crosshair inside of it. Or a reticle that consists of an inner and outer ring that could grow or shrink instead of spreading pieces of it.Not sure how you would to do that, but it does in some respects sound like the behavior the original resource that this resource is based of was using. Unfortunately I might not be able to help you on this one, not my area of expertise ya know =/ (image sequences that is). I hope you'll figure it out to.
Oh, and thanks for the crosshairs, much appreciated (:D.
#23
I finally got time to install your resource.
The getspread will not work in multiplayer environment. It is linked to the GUI Object which is Client only. I'm sure this was what you planned, but I prefer notice it if people are not aware of.
Should not "bitmap = "art/gui/weaponHud/defaultCrosshair";" in the playgui?
I will look forward in the implementation you are working on (for me :D).
In you need any help or testing or else, don't hesitate. If you prefer use email, tell me!
One thing I found, if the spread is not defined in a datablock, the crosshair is messy. It could be great that, if not define that the crosshair is at the lowest spread as possible (0?).
08/31/2010 (5:19 pm)
Hi Marcus,I finally got time to install your resource.
The getspread will not work in multiplayer environment. It is linked to the GUI Object which is Client only. I'm sure this was what you planned, but I prefer notice it if people are not aware of.
Should not "bitmap = "art/gui/weaponHud/defaultCrosshair";" in the playgui?
I will look forward in the implementation you are working on (for me :D).
In you need any help or testing or else, don't hesitate. If you prefer use email, tell me!
One thing I found, if the spread is not defined in a datablock, the crosshair is messy. It could be great that, if not define that the crosshair is at the lowest spread as possible (0?).
#25
09/02/2010 (6:59 pm)
Quote:The getspread will not work in multiplayer environment. It is linked to the GUI Object which is Client only. I'm sure this was what you planned, but I prefer notice it if people are not aware of.Sorry, i never tested it multiplayer, but i believe it works. So just let me test and come up with an solution.
Quote:Should not "bitmap = "art/gui/weaponHud/defaultCrosshair";" in the playgui?Not really :P, weapons might use individuall crosshairs you know, and the crosshair is really applied when you mount a weapon.
Quote:I will look forward in the implementation you are working on (for me :D).I've gotten it to work, but it might not be exactly what you wanted, therefore I'll just send it to you and you tell me. (if you don't want to post your e-mail here, just send me an e-mail with the e-mail you want me to send it to)
Quote:One thing I found, if the spread is not defined in a datablock, the crosshair is messy. It could be great that, if not define that the crosshair is at the lowest spread as possible (0?).Yeah, you're right, I'll fix that soon. Thanks.
#27
09/19/2010 (12:50 pm)
Sorry about this, Noob here, but for some reasion the cursor only shows up after i dismount from a vehicle. Any way to fix this?
#28
Anyhow, for the people following this resource (and the rest of my resources) when I'll port them to 1.1b3 I'll include some fixes and improvements. More info when the time comes.
09/19/2010 (2:06 pm)
Umm, I would like to help you but you don't own a license =/... As far as I can see. Anyhow, for the people following this resource (and the rest of my resources) when I'll port them to 1.1b3 I'll include some fixes and improvements. More info when the time comes.
#29
03/29/2014 (4:03 am)
Anyone test this with Torque 3D 3.0 or 3.5? 
Associate Michael Hall
Distracted...
@Vehicle reticle problem: at the moment I've not modified my vehicle huds to use this Resource, but it would be useful to have ;)
Any thought on using image sequences so that you could animate instead of spreading the crosshair? I found myself wanting an animated reticle with a rotating outer ring and a spreading crosshair inside of it. Or a reticle that consists of an inner and outer ring that could grow or shrink instead of spreading pieces of it.