int CLuaFunctionDefs::SetWeaponOwner ( lua_State* luaVM )
{
    CClientWeapon * pWeapon;
    CClientPlayer * pPlayer;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pWeapon );
    if ( argStream.NextIsUserData() )
    {
        argStream.ReadUserData ( pPlayer );
        if ( !argStream.HasErrors () )
        {
            pWeapon->SetOwner( pPlayer );

            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else if ( argStream.NextIsNil() )
    {
        if ( !argStream.HasErrors () )
        {
            pWeapon->SetOwner( NULL );

            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    if ( argStream.HasErrors() )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushnil ( luaVM );
    return 1;
}
Ejemplo n.º 2
0
void CElementRPCs::SetWeaponOwner ( CClientEntity * pSource, NetBitStreamInterface& bitStream )
{
    if ( pSource->GetType() == CCLIENTWEAPON )
    {
        ElementID PlayerID;
        if ( bitStream.Read ( PlayerID ) )
        {
            CClientWeapon * pWeapon = static_cast < CClientWeapon * > ( pSource );
            CClientPlayer * pPlayer = NULL;
            if ( PlayerID != INVALID_ELEMENT_ID )
            {
                pPlayer = DynamicCast < CClientPlayer > ( CElementIDs::GetElement ( PlayerID ) );
            }
            else
                pPlayer = NULL;

            pWeapon->SetOwner ( pPlayer );
        }
    }
}