multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.3k stars 412 forks source link

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

Closed FileEX closed 13 hours ago

FileEX commented 4 days ago

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

https://github.com/multitheftauto/mtasa-blue/blob/97920d83de400e0378f73ea93e87b27cf59dd758/Client/mods/deathmatch/logic/CClientPed.cpp#L2209-L2211

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.

https://github.com/multitheftauto/mtasa-blue/blob/97920d83de400e0378f73ea93e87b27cf59dd758/Client/mods/deathmatch/logic/CClientPed.cpp#L2148-L2152

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 commented 3 days ago
 // 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 bRestoreStatebecome true so it loop through the list

FileEX commented 3 days ago

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 commented 3 days ago

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 commented 3 days ago

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

https://github.com/multitheftauto/mtasa-blue/blob/97920d83de400e0378f73ea93e87b27cf59dd758/Client/mods/deathmatch/logic/CClientPed.cpp#L3907