예제 #1
0
bool CIFPEngine::EngineReplaceAnimation(CClientEntity* pEntity, const SString& strInternalBlockName, const SString& strInternalAnimName,
                                        const SString& strCustomBlockName, const SString& strCustomAnimName)
{
    if (IS_PED(pEntity))
    {
        CClientPed& Ped = static_cast<CClientPed&>(*pEntity);

        const unsigned int          u32BlockNameHash = HashString(strCustomBlockName.ToLower());
        CAnimBlock*                 pInternalBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strInternalBlockName);
        std::shared_ptr<CClientIFP> pCustomIFP = g_pClientGame->GetIFPPointerFromMap(u32BlockNameHash);
        if (pInternalBlock && pCustomIFP)
        {
            // Try to load the block, if it's not loaded already
            pInternalBlock->Request(BLOCKING, true);

            auto                            pInternalAnimHierarchy = g_pGame->GetAnimManager()->GetAnimation(strInternalAnimName, pInternalBlock);
            CAnimBlendHierarchySAInterface* pCustomAnimHierarchyInterface = pCustomIFP->GetAnimationHierarchy(strCustomAnimName);
            if (pInternalAnimHierarchy && pCustomAnimHierarchyInterface)
            {
                Ped.ReplaceAnimation(pInternalAnimHierarchy, pCustomIFP, pCustomAnimHierarchyInterface);
                return true;
            }
        }
    }
    return false;
}
예제 #2
0
파일: LuaCommon.cpp 프로젝트: EagleShen/MTA
CPed* lua_toped ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_PED ( pElement ) )
        return static_cast < CPed* > ( pElement );
    else
        return NULL;
}
예제 #3
0
파일: CPedSync.cpp 프로젝트: EagleShen/MTA
void CPedSync::Update ( unsigned long ulCurrentTime )
{
    // Update all the ped's sync states
    list < CPed* > ::const_iterator iter = m_pPedManager->IterBegin ();
    for ( ; iter != m_pPedManager->IterEnd (); iter++ )
    {
        // It is a ped, yet not a player
        if ( IS_PED ( *iter ) && !IS_PLAYER ( *iter ) )
            UpdatePed ( *iter );
    }
}
예제 #4
0
bool CIFPEngine::EngineRestoreAnimation(CClientEntity* pEntity, const SString& strInternalBlockName, const SString& strInternalAnimName,
                                        const eRestoreAnimation& eRestoreType)
{
    if (IS_PED(pEntity))
    {
        CClientPed& Ped = static_cast<CClientPed&>(*pEntity);

        if (eRestoreType == eRestoreAnimation::ALL)
        {
            Ped.RestoreAllAnimations();
            return true;
        }
        else
        {
            CAnimBlock* pInternalBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strInternalBlockName);
            if (pInternalBlock)
            {
                if (eRestoreType == eRestoreAnimation::BLOCK)
                {
                    Ped.RestoreAnimations(*pInternalBlock);
                    return true;
                }
                else
                {
                    auto pInternalAnimHierarchy = g_pGame->GetAnimManager()->GetAnimation(strInternalAnimName, pInternalBlock);
                    if (pInternalAnimHierarchy)
                    {
                        Ped.RestoreAnimation(pInternalAnimHierarchy);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
예제 #5
0
파일: CPedSync.cpp 프로젝트: EagleShen/MTA
void CPedSync::Packet_PedSync ( CPedSyncPacket& Packet )
{
    // Grab the player
    CPlayer* pPlayer = Packet.GetSourcePlayer ();
    if ( pPlayer && pPlayer->IsJoined () )
    {
        // Apply the data for each ped in the packet
        vector < CPedSyncPacket::SyncData* > ::const_iterator iter = Packet.IterBegin ();
        for ( ; iter != Packet.IterEnd (); iter++ )
        {
            CPedSyncPacket::SyncData* pData = *iter;

            // Grab the ped this packet is for
            CElement* pPedElement = CElementIDs::GetElement ( pData->Model );
            if ( pPedElement && IS_PED ( pPedElement ) )
            {
                // Convert to a CPed
                CPed* pPed = static_cast < CPed* > ( pPedElement );

                // Is the player syncing this ped?
                // this packet if the time context matches.
                if ( pPed->GetSyncer () == pPlayer &&
                     pPed->CanUpdateSync ( pData->ucSyncTimeContext ) )
                {
                    // Apply the data to the ped
                    if ( pData->ucFlags & 0x01 )
                    {
                        pPed->SetPosition ( pData->vecPosition );
                        g_pGame->GetColManager()->DoHitDetection ( pPed->GetLastPosition (), pPed->GetPosition (), 0.0f, pPed );
                    }
                    if ( pData->ucFlags & 0x02 ) pPed->SetRotation ( pData->fRotation );
                    if ( pData->ucFlags & 0x04 ) pPed->SetVelocity ( pData->vecVelocity );

                    if ( pData->ucFlags & 0x08 )
                    {
                        // Less health than last time?
                        float fPreviousHealth = pPed->GetHealth ();
                        pPed->SetHealth ( pData->fHealth );

                        if ( pData->fHealth < fPreviousHealth )
                        {
                            // Grab the delta health
                            float fDeltaHealth = fPreviousHealth - pData->fHealth;

                            if ( fDeltaHealth > 0.0f )
                            {
                                // Call the onPedDamage event
                                CLuaArguments Arguments;
                                Arguments.PushNumber ( fDeltaHealth );
                                pPed->CallEvent ( "onPedDamage", Arguments );
                            }
                        }
                    }

                    if ( pData->ucFlags & 0x10 ) pPed->SetArmor ( pData->fArmor );

                    // Send this sync
                    pData->bSend = true;
                }
            }
        }

        // Tell everyone
        m_pPlayerManager->BroadcastOnlyJoined ( Packet, pPlayer );
    }
}