[How To] Add weapon side slot

Status
Not open for further replies.
Newbie Spellweaver
Joined
May 2, 2013
Messages
96
Reaction score
141
The weapon side slot is this placement of secondary weapon when you have your primary weapon equipped:
zSMAtK1 - [How To] Add weapon side slot - RaGEZONE Forums


First we go in AI_PlayerAnim.cpp ( \WarZ\src\EclipseStudio\Sources\ObjectsCode\AI\AI_PlayerAnim.cpp )

Remove the lines marked with red
Code:
void CUberEquip::DrawSlot(ESlot slotId, const D3DXMATRIX& world, DrawType dt, bool skin, bool draw_firstperson, const r3dSkeleton* wpnSkeleton)
{
[COLOR=#FF0000]    if(slotId == SLOT_WeaponSide)
        return;[/COLOR]
    if(draw_firstperson)
    {
        if(slotId == SLOT_Armor || slotId == SLOT_LowerBody || slotId == SLOT_Head || slotId == SLOT_Helmet || slotId == SLOT_Backpack)
            return;
    }

Ok cool, that added the side slot, but now it looks like this:
oRJgPjA - [How To] Add weapon side slot - RaGEZONE Forums

This only happens with melee weapons, not with pistols etc. if you only allow melee weapons in secondary slot, this is not a problem, but I allow pistols too, so needs a fix..
So let's fix this :)

In same file (AI_PlayerAnim.cpp)

Add the lines I marked with green
Code:
void CUberEquip::Draw(const r3dSkeleton* skel, const D3DXMATRIX& CharMat, bool draw_weapon, DrawType dt, bool first_person)
{
    //todo: call extern void r3dMeshSetWorldMatrix(const D3DXMATRIX& world)
    // instead of mesh->SetWorldMatrix

    // in first person mode we need to render player and gun into different Z range
    if(dt == DT_AURA)
    {
        float expandConst[ 4 ] = { r_aura_extrude->GetFloat(), 0.f, 0.f, 0.f } ;
        D3D_V(r3dRenderer->pd3ddev->SetVertexShaderConstantF(23, expandConst, 1)) ;
    }

    skel->SetShaderConstants();

    for(int i=0; i<=SLOT_Backpack; i++)
    {
        DrawSlot((ESlot)i, CharMat, dt, true, first_person, NULL);
    }

    if(dt != DT_AURA)
    {
        D3DXMATRIX world = getWeaponBone(skel, CharMat);
        if(!first_person)
        {
            if(slots_[SLOT_WeaponBackRight].wpn)
            {
                skel->GetBoneWorldTM("Weapon_BackRight", &world, CharMat);
                DrawSlot(SLOT_WeaponBackRight, world, dt, false, first_person, NULL);
            }
            if(slots_[SLOT_WeaponSide].wpn)
            {
                skel->GetBoneWorldTM("Weapon_Side", &world, CharMat);

[COLOR=#00CC00]                if(slots_[SLOT_WeaponSide].wpn->getCategory() == storecat_MELEE) {
                    D3DXMATRIX mr1;
                    D3DXMatrixRotationYawPitchRoll(&mr1, 0, R3D_PI/2 + 40, 30);
                    skel->GetBoneWorldTM("Weapon_Side", &world, CharMat);
                    world = mr1 * world;
                }[/COLOR]

                DrawSlot(SLOT_WeaponSide, world, dt, false, first_person, NULL);
            }
        }
That will rotate the model into place.


Hope this is useful for someone :)
 
Last edited:
I am a bit confused. Does this simply show your secondary on the character or does it allow you to put pistols into the primary slot?
 
I am a bit confused. Does this simply show your secondary on the character or does it allow you to put pistols into the primary slot?
It is to show secondary on your character.

If you want to put pistols in primary or melee in primary slot is easy too, I can make a tutorial about that if you need :)
 
I would greatly appreciate that tutorial as I am very new to C++ and only have one live server so I can't really just fiddle with the code as of yet. Great release though as always this is much appreciated.

I have noticed in retail WarZ they have a few custom backpack models too so for example if you have a pistol in your backpack it shows it on the actual backpack. This helps prevent greifers from saying they are unarmed and then equipping the pistol/Rifle from thier pack and blasting you.

+Rep!
 
I would greatly appreciate that tutorial as I am very new to C++ and only have one live server so I can't really just fiddle with the code as of yet. Great release though as always this is much appreciated.
Make a server in VM or localhost, then it is very easy & fun to test new things out without having to distribute :)

I have noticed in retail WarZ they have a few custom backpack models too so for example if you have a pistol in your backpack it shows it on the actual backpack. This helps prevent greifers from saying they are unarmed and then equipping the pistol/Rifle from thier pack and blasting you.
That sounds nice. To add such, you need to add in the skeleton/model a bone (I don't know anything about 3d modelling), then you can add it in code, same place as above ;)
 
Getting this error

3>.\Sources\ObjectsCode\AI\AI_PlayerAnim.cpp(917) : error C2065: 'yaw' : undeclared identifier


heres the function i get the error in

Code:
void CUberEquip::Draw(const r3dSkeleton* skel, const D3DXMATRIX& CharMat, bool draw_weapon, DrawType dt, bool first_person)
{
	//todo: call extern void r3dMeshSetWorldMatrix(const D3DXMATRIX& world)
	// instead of mesh->SetWorldMatrix


    // in first person mode we need to render player and gun into different Z range
	if(dt == DT_AURA)
	{
		float expandConst[ 4 ] = { r_aura_extrude->GetFloat(), 0.f, 0.f, 0.f } ;
		D3D_V(r3dRenderer->pd3ddev->SetVertexShaderConstantF(23, expandConst, 1)) ;
	}


	skel->SetShaderConstants();


	for(int i=0; i<=SLOT_Backpack; i++)
	{
		DrawSlot((ESlot)i, CharMat, dt, true, first_person, NULL);
	}


	if(dt != DT_AURA)
	{
		D3DXMATRIX world = getWeaponBone(skel, CharMat);
		if(!first_person)
		{
			if(slots_[SLOT_WeaponBackRight].wpn)
			{
				skel->GetBoneWorldTM("Weapon_BackRight", &world, CharMat);
				DrawSlot(SLOT_WeaponBackRight, world, dt, false, first_person, NULL);
			}
			if(slots_[SLOT_WeaponSide].wpn)
			{
				skel->GetBoneWorldTM("Weapon_Side", &world, CharMat);
				DrawSlot(SLOT_WeaponSide, world, dt, false, first_person, NULL);


				if(slots_[SLOT_WeaponSide].wpn->getCategory() == storecat_MELEE) {
                    D3DXMATRIX mr1;
                    D3DXMatrixRotationYawPitchRoll(&mr1, yaw, R3D_PI/2 + 40, 30);
                    skel->GetBoneWorldTM("Weapon_Side", &world, CharMat);
                    world = mr1 * world;
                }
			}
		}


		if(draw_weapon)
		{
			world = getWeaponBone(skel, CharMat);
			bool skinned = false;
			r3dSkeleton* wpnSkel = NULL;
			Weapon* wpn = slots_[SLOT_Weapon].wpn;
			if(wpn)
			{
				r3dMesh* msh = wpn->getModel(true, first_person);
				if(msh->IsSkeletal() && wpn->getConfig()->getSkeleton())
				{
					wpn->getAnimation()->Recalc();
					wpn->getAnimation()->pSkeleton->SetShaderConstants();
					wpnSkel = wpn->getAnimation()->pSkeleton;
					skinned = true;
				}
			}
			DrawSlot(SLOT_Weapon, world, dt, skinned, first_person, wpnSkel);
		}
	}
}
 
Getting this error

3>.\Sources\ObjectsCode\AI\AI_PlayerAnim.cpp(917) : error C2065: 'yaw' : undeclared identifier
Sorry! Replace yaw by 0 :)

Is it possible to have it on your back. Same as primary?
Yes! This is what I did at first too.

Here is code to have secondary on back:
Code:
void CUberEquip::Draw(const r3dSkeleton* skel, const D3DXMATRIX& CharMat, bool draw_weapon, DrawType dt, bool first_person)
{
    //todo: call extern void r3dMeshSetWorldMatrix(const D3DXMATRIX& world)
    // instead of mesh->SetWorldMatrix

    // in first person mode we need to render player and gun into different Z range
    if(dt == DT_AURA)
    {
        float expandConst[ 4 ] = { r_aura_extrude->GetFloat(), 0.f, 0.f, 0.f } ;
        D3D_V(r3dRenderer->pd3ddev->SetVertexShaderConstantF(23, expandConst, 1)) ;
    }

    skel->SetShaderConstants();

    for(int i=0; i<=SLOT_Backpack; i++)
    {
        DrawSlot((ESlot)i, CharMat, dt, true, first_person, NULL);
    }

    if(dt != DT_AURA)
    {
        D3DXMATRIX world = getWeaponBone(skel, CharMat);
        if(!first_person)
        {
            if(slots_[SLOT_WeaponBackRight].wpn)
            {
                skel->GetBoneWorldTM("Weapon_BackRight", &world, CharMat);
                DrawSlot(SLOT_WeaponBackRight, world, dt, false, first_person, NULL);
            }
            if(slots_[SLOT_WeaponSide].wpn)
            {
                if(slots_[SLOT_WeaponSide].wpn->getCategory() == storecat_MELEE) {
                    D3DXMATRIX mr1;
                    D3DXMatrixRotationYawPitchRoll(&mr1, 0, R3D_PI/2 + 40, 30);
                    skel->GetBoneWorldTM("[COLOR=#00DD00]Weapon_BackRight[/COLOR]", &world, CharMat);
                    world = mr1 * world;
                }
                else
                {
                    skel->GetBoneWorldTM("[COLOR=#00DD00]Weapon_BackRight[/COLOR]", &world, CharMat);
                }

                DrawSlot(SLOT_WeaponSide, world, dt, false, first_person, NULL);
            }
        }
The only problem is if you have empty hands then it will render both weapons in same slot.. What you can do is transform the matrix of the secondary so it is mirrored or something. See OP for how to transform the matrix.

I have it set to having handguns on the side but other weapons on back, like this:
Code:
            if(slots_[SLOT_WeaponSide].wpn)
            {
                if(slots_[SLOT_WeaponSide].wpn->getCategory() == storecat_HG) // put handguns in side slot
                {
                    skel->GetBoneWorldTM("Weapon_Side", &world, CharMat);
                }
                else if(slots_[SLOT_WeaponSide].wpn->getCategory() == storecat_MELEE) // it is a melee weapon, put it on back but rotate it to look better (for most)
                {
                    D3DXMATRIX mr1;
                    D3DXMatrixRotationYawPitchRoll(&mr1, 0, R3D_PI/2 + 40, 30);
                    skel->GetBoneWorldTM("Weapon_BackRight", &world, CharMat);
                    world = mr1 * world;
                }
                else // it is not handgun or melee, put it on back
                {
                    skel->GetBoneWorldTM("Weapon_BackRight", &world, CharMat);
                }


                DrawSlot(SLOT_WeaponSide, world, dt, false, first_person, NULL);
            }

I just think it looks better with pistols in side slot.
7MwAoBn - [How To] Add weapon side slot - RaGEZONE Forums

RjldsT - [How To] Add weapon side slot - RaGEZONE Forums

OVFF83o - [How To] Add weapon side slot - RaGEZONE Forums
 
Last edited:
excelent tutorial +5
but between the character and handguns have too many distance

can I change this somewhere?
If you know 3D modelling you could change the position of the Weapon_Side bone I guess. I think it's in the character skeleton.

Otherwise, you can change it in code, on-the-fly.
You see this call
Code:
                skel->GetBoneWorldTM("Weapon_Side", &world, CharMat);
retrieves the world position of the Weapon_Side bone into the "world" matrix.
Feel free to transform it as you like.

If you don't know how to do that, it's time to learn some basic Direct3D :)
 
Status
Not open for further replies.
Back