Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #501 Setting player model resets their current weapon slot #3510

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

FileEX
Copy link
Contributor

@FileEX FileEX commented Jun 25, 2024

Fixed #501

In the case of non-player peds weapon the slot is set correctly, but in the case of player peds the slot is not set.

This is due to the fact that the slot for the player is taken directly from the GTA memory

if (m_pPlayerPed)
{
return m_pPlayerPed->GetCurrentWeaponSlot();

and when the skin respawns, the slot in the game memory is still the one we had before changing the skin. This causes the condition result is false.

bool CClientPed::SetCurrentWeaponSlot(eWeaponSlot weaponSlot)
{
if (weaponSlot < WEAPONSLOT_MAX)
{
if (weaponSlot != GetCurrentWeaponSlot())

As a result, the weapon slot is not set at all. Therefore, we first set the weapon slot to 0 to make this condition true.

@Proxy-99
Copy link
Contributor

Proxy-99 commented Jun 25, 2024

 // Set it to 0 (Fix #501)
            SetCurrentWeaponSlot(eWeaponSlot::WEAPONSLOT_TYPE_UNARMED);

            if (bRestoreState)
            {
                // Jax: restore all the things we saved
                SetHealth(fHealth);
                SetArmor(fArmor);
                SetCurrentWeaponSlot(weaponSlot);
                SetCurrentRotation(fCurrentRotation);
                m_pPlayerPed->SetTargetRotation(fTargetRotation);
                SetMoveSpeed(vecMoveSpeed);
                SetHasJetPack(m_bHasJetPack);
                SetInterior(ucInterior);
            }

what about this condition after it set the weapon slot should not bRestoreState become true so it loop through the list

@FileEX
Copy link
Contributor Author

FileEX commented Jun 25, 2024

I do not understand what you mean. After changing the skin, the slot changes to 0 anyway, but the MTA does not recognize it, so setting the slot to 0 from the MTA level solves the problem.

@Proxy-99
Copy link
Contributor

Proxy-99 commented Jun 25, 2024

I do not understand what you mean. After changing the skin, the slot changes to 0 anyway, but the MTA does not recognize it, so setting the slot to 0 from the MTA level solves the problem.

you can notice a condtion after your fix
at line 5226
it alredy set the weapon slot
SetCurrentWeaponSlot(weaponSlot);

if (bRestoreState)
{
    // Jax: restore all the things we saved
    SetHealth(fHealth);
    SetArmor(fArmor);
    SetCurrentWeaponSlot(weaponSlot);
    SetCurrentRotation(fCurrentRotation);
    m_pPlayerPed->SetTargetRotation(fTargetRotation);
    SetMoveSpeed(vecMoveSpeed);
    SetHasJetPack(m_bHasJetPack);
    SetInterior(ucInterior);
}

so setting bRestoreState to true should fix the issue if I am not wrong

@FileEX
Copy link
Contributor Author

FileEX commented Jun 25, 2024

You're wrong. I described what the problem is. bRestoreState is true, but still the weapon slot is not set correctly without my fix.

Respawn(NULL, true, false);

Copy link
Contributor

@Proxy-99 Proxy-99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job!
mainly the issue comes from if (weaponSlot != GetCurrentWeaponSlot()) returning false, I was confused at the start

@tederis tederis added the bugfix Solution to a bug of any kind label Jun 27, 2024
@Dutchman101 Dutchman101 merged commit f7ce562 into multitheftauto:master Jun 28, 2024
6 checks passed
MTABot pushed a commit that referenced this pull request Jun 28, 2024
f7ce562 Fix #501 Setting player model resets their current weapon slot (#3510)
@FileEX FileEX deleted the bugfix/weaponslot branch June 28, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Solution to a bug of any kind
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting player model resets their current weapon slot
4 participants