コード例 #1
0
ファイル: CPedManager.cpp プロジェクト: AdiBoy/mtasa-blue
CPed* CPedManager::CreateFromXML ( CElement* pParent, CXMLNode& Node, CLuaMain* pLuaMain, CEvents* pEvents )
{
    // Create the Ped
    CPed* pPed = new CPed ( this, pParent, &Node, 400 );

    // Verify the Ped id and load the data from xml
    if ( pPed->GetID () == INVALID_ELEMENT_ID ||
         !pPed->LoadFromCustomData ( pLuaMain, pEvents ) )
    {
        delete pPed;
        return NULL;
    }

    // Make sure hes alive (leave to scripts?)
    pPed->SetIsDead ( false );
    pPed->SetSpawned ( true );
    pPed->SetHealth ( 100.0f );

    // Return the created Ped
    return pPed;
}
コード例 #2
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 );
    }
}