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 Sirens not removed correctly #3475

Open Proxy-99 opened 1 week ago

Proxy-99 commented 1 week ago

attempt to fix #3472

the issue with SetSirenActive() it return true after removing the sirens deactive the sirens when removing them

Dutchman101 commented 1 week ago

attempt to fix #3472

Attempt? It should be straightforward for you to test your changes (against the issue repro), please do so.

Proxy-99 commented 1 week ago

attempt to fix #3472

Attempt? It should be straightforward for you to test your changes (against the issue repro), please do so.

tested issue gone

Proxy-99 commented 1 week ago

attempt to fix #3472

Attempt? It should be straightforward for you to test your changes (against the issue repro), please do so.

the issue with SetSirenActive()it return true after removing the sirens which makes the function return false in the second time you fire the SetVehicleSirensOn with same vehicle

bool CStaticFunctionDefinitions::SetVehicleSirensOn(CElement* pElement, bool bSirensOn)
{
    assert(pElement);
    RUN_CHILDREN(SetVehicleSirensOn(*iter, bSirensOn))

    if (IS_VEHICLE(pElement))
    {
        CVehicle* pVehicle = static_cast<CVehicle*>(pElement);

        // Has Sirens and different state than before?
        if ((CVehicleManager::HasSirens(pVehicle->GetModel()) || pVehicle->DoesVehicleHaveSirens()) && bSirensOn != pVehicle->IsSirenActive())
        {
            // Set the new state
            pVehicle->SetSirenActive(bSirensOn);

            // Tell everyone
            unsigned char ucSirensOn = 0;
            if (bSirensOn)
                ucSirensOn = 1;

            CBitStream BitStream;
            BitStream.pBitStream->Write(ucSirensOn);
            m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, SET_VEHICLE_SIRENE_ON, *BitStream.pBitStream));
            return true;
        }
    }

    return false;
}

bSirensOn != pVehicle->IsSirenActive() will return false in the second time you fire the function with same car