int CLuaFxDefs::fxAddTankFire ( lua_State* luaVM )
{
    // bool fxAddTankFire ( float posX, float posY, float posZ, float dirX, float dirY, float dirZ )

    // Verify types
    CVector vecPosition, vecDirection;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecDirection );

    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::FxAddTankFire ( vecPosition, vecDirection ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFxDefs::fxAddWood ( lua_State* luaVM )
{
    // bool fxAddWood ( float posX, float posY, float posZ, float dirX, float dirY, float dirZ, [int count=1, float fBrightness=1.0] )

    CVector vecPosition, vecDirection;
    int iCount = 1;
    float fBrightness = 1.0f;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecDirection );
    argStream.ReadNumber ( iCount, 1 );
    argStream.ReadNumber ( fBrightness, 1.0f );

    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::FxAddWood ( vecPosition, vecDirection, iCount, fBrightness ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFxDefs::fxAddBulletImpact ( lua_State* luaVM )
{
    // bool fxAddBulletImpact ( float posX, float posY, float posZ, float dirX, float dirY, float dirZ, [int smokeSize=1, int sparkCount=1, float fSmokeIntensity=1.0] )

    // Verify types
    CVector vecPosition, vecDirection;
    int iSmokeSize = 1;
    int iSparkCount = 1;
    float fSmokeIntensity = 1.0f;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecDirection );
    argStream.ReadNumber ( iSmokeSize, 1 );
    argStream.ReadNumber ( iSparkCount, 1 );
    argStream.ReadNumber ( fSmokeIntensity, 1.0f );

    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::FxAddBulletImpact ( vecPosition, vecDirection, iSmokeSize, iSparkCount, fSmokeIntensity ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetCameraMatrix ( lua_State* luaVM )
{
    CVector vecPosition;
    CVector vecLookAt;
    float fRoll = 0.0f;
    float fFOV = 70.0f;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecLookAt, CVector() );
    argStream.ReadNumber ( fRoll, 0.0f );
    argStream.ReadNumber ( fFOV, 70.0f );
    if ( fFOV <= 0.0f || fFOV >= 180.0f )
        fFOV = 70.0f;

    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::SetCameraMatrix ( vecPosition, vecLookAt, fRoll, fFOV ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::CreateObject ( lua_State* luaVM )
{
//  object createObject ( int modelid, float x, float y, float z, [float rx, float ry, float rz, bool lowLOD] )
    ushort usModelID;
    CVector vecPosition;
    CVector vecRotation;
    bool bLowLod;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadNumber ( usModelID );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecRotation, vecRotation );
    argStream.ReadBool ( bLowLod, false );

    if ( !argStream.HasErrors () )
    {
        if ( CClientObjectManager::IsValidModel  ( usModelID ) )
        {
            CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
            if ( pLuaMain )
            {
                CResource* pResource = pLuaMain->GetResource ();
                if ( pResource )
                {
                    CClientObject* pObject = CStaticFunctionDefinitions::CreateObject ( *pResource, usModelID, vecPosition, vecRotation, bLowLod );
                    if ( pObject )
                    {
                        CElementGroup * pGroup = pResource->GetElementGroup();
                        if ( pGroup )
                        {
                            pGroup->Add ( ( CClientEntity* ) pObject );
                        }

                        lua_pushelement ( luaVM, pObject );
                        return 1;
                    }
                }
            }
        }
        else
            argStream.SetCustomError( "Invalid model id" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemple #6
0
int CLuaWorldDefs::RestoreWorldModel ( lua_State* luaVM )
{
    CScriptArgReader argStream ( luaVM );

    unsigned short usModel = 0;
    float fRadius = 0.0f;
    char cInterior = -1;
    CVector vecPosition;
    argStream.ReadNumber ( usModel );
    argStream.ReadNumber ( fRadius );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadNumber ( cInterior, -1 );
    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::RestoreWorldModel ( usModel, fRadius, vecPosition, cInterior ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::CreateFire ( lua_State* luaVM )
{
    CVector vecPosition;
    float fSize;
    CElement* pCreator;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadNumber ( fSize, 1.8f );
    argStream.ReadUserData ( pCreator, NULL );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::CreateFire ( vecPosition, fSize, pCreator ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaMatrixDefs::SetRotation ( lua_State* luaVM )
{
    CLuaMatrix* pMatrix = NULL;
    CVector vecRotation;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pMatrix );
    argStream.ReadVector3D ( vecRotation );

    if ( !argStream.HasErrors () )
    {
        ConvertRadiansToDegreesNoWrap ( vecRotation );
        pMatrix->SetRotation ( vecRotation );

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

    lua_pushboolean ( luaVM, false );
    return 1;    
}
int CLuaFunctionDefs::InterpolateBetween ( lua_State* luaVM )
{
    //  float float float interpolateBetween ( float x1, float y1, float z1, 
    //      float x2, float y2, float z2, 
    //      float fProgress, string strEasingType, 
    //      [ float fEasingPeriod, float fEasingAmplitude, float fEasingOvershoot ] )
    CVector vecPointA; CVector vecPointB;
    float fProgress; CEasingCurve::eType easingType;
    float fEasingPeriod; float fEasingAmplitude; float fEasingOvershoot;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPointA );
    argStream.ReadVector3D ( vecPointB );
    argStream.ReadNumber ( fProgress );
    argStream.ReadEnumString ( easingType );
    argStream.ReadNumber ( fEasingPeriod, 0.3f );
    argStream.ReadNumber ( fEasingAmplitude, 1.0f );
    argStream.ReadNumber ( fEasingOvershoot, 1.70158f );

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

    CVector vecResult = TInterpolation < CVector >::Interpolate ( vecPointA, vecPointB, fProgress, easingType, fEasingPeriod, fEasingAmplitude, fEasingOvershoot );
    lua_pushnumber ( luaVM, vecResult.fX );
    lua_pushnumber ( luaVM, vecResult.fY );
    lua_pushnumber ( luaVM, vecResult.fZ );
    return 3;
}
int CLuaPointLightDefs::CreateLight ( lua_State* luaVM )
{
    //  light createLight ( int lightType, float posX, float posY, float posX, [ float radius = 3, int r = 255, int g = 0, int b = 0, float dirX = 0, float dirY = 0, float dirZ = 0, bool createsShadow = false ] )
    int iMode;
    CVector vecPosition;
    float fRadius;
    SColor color;
    CVector vecDirection;
    bool bCreatesShadow;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadNumber ( iMode );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadNumber ( fRadius, 3.0f );
    argStream.ReadNumber ( color.R, 255 );
    argStream.ReadNumber ( color.G, 0 );
    argStream.ReadNumber ( color.B, 0 );
    argStream.ReadVector3D ( vecDirection, vecDirection );
    argStream.ReadBool ( bCreatesShadow, false );

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        CResource* pResource = pLuaMain ? pLuaMain->GetResource () : NULL;
        if ( pResource )
        {
            // Create it
            CClientPointLights* pLight = CStaticFunctionDefinitions::CreateLight ( *pResource, iMode, vecPosition, fRadius, color, vecDirection );
            if ( pLight )
            {
                CElementGroup * pGroup = pResource->GetElementGroup ();
                if ( pGroup )
                {
                    pGroup->Add ( (CClientEntity*) pLight );
                }
                lua_pushelement ( luaVM, pLight );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), *argStream.GetErrorMessage () ) );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaColShapeDefs::CreateColCuboid ( lua_State* luaVM )
{
    CVector vecPosition, vecSize;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecSize );

    if ( vecSize.fX < 0.0f )
    {
        vecSize.fX = 0.1f;
    }
    if ( vecSize.fY < 0.0f )
    {
        vecSize.fY = 0.1f;
    }

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                // Create it and return it
                CClientColCuboid* pShape = CStaticFunctionDefinitions::CreateColCuboid ( *pResource, vecPosition, vecSize );
                if ( pShape )
                {
                    CElementGroup * pGroup = pResource->GetElementGroup ();
                    if ( pGroup )
                    {
                        pGroup->Add ( (CClientEntity*) pShape );
                    }
                    lua_pushelement ( luaVM, pShape );
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetWeaponProperty ( lua_State* luaVM )
{
    CClientWeapon * pWeapon;
    eWeaponProperty weaponProperty;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pWeapon );
    argStream.ReadEnumString ( weaponProperty );

    if ( !argStream.HasErrors () )
    {
        if ( weaponProperty == WEAPON_DAMAGE )
        {
            short sData = 0;
            argStream.ReadNumber( sData );
            if ( !argStream.HasErrors( ) )
            {
                if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, sData ) )
                {
                    lua_pushboolean ( luaVM, true );
                    return 1;
                }
            }
        }
        else
        if ( weaponProperty == WEAPON_FIRE_ROTATION )
        {
            CVector vecRotation;
            argStream.ReadVector3D ( vecRotation );
            if ( !argStream.HasErrors () )
            {
                if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, vecRotation ) )
                {
                    lua_pushboolean ( luaVM, true );
                    return 1;
                }
            }
        }
        else
        {
            float fData = 0.0f;
            argStream.ReadNumber( fData );
            if ( !argStream.HasErrors( ) )
            {
                if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, fData ) )
                {
                    lua_pushboolean ( luaVM, true );
                    return 1;
                }
            }
        }
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaCameraDefs::setCameraMatrix ( lua_State* luaVM )
{
//  bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = 0, float fov = 70 ] )
    CElement* pPlayer; CVector vecPosition; CVector vecLookAt; float fRoll; float fFOV;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pPlayer );
    
    if ( argStream.NextIsUserDataOfType <CLuaMatrix> () ) {
        CLuaMatrix* pMatrix;
        argStream.ReadUserData( pMatrix );

        vecPosition = pMatrix->GetPosition ();
        vecLookAt = pMatrix->GetRotation ();
    }
    else
    {
        argStream.ReadVector3D ( vecPosition );
        argStream.ReadVector3D ( vecLookAt, CVector () );
    }
    
    argStream.ReadNumber ( fRoll, 0.0f );
    argStream.ReadNumber ( fFOV, 70.0f );

    if ( !argStream.HasErrors () )
    {
        if ( fFOV <= 0.0f || fFOV >= 180.0f )
            fFOV = 70.0f;

        if ( CStaticFunctionDefinitions::SetCameraMatrix ( pPlayer, vecPosition, &vecLookAt, fRoll, fFOV ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetWeaponTarget ( lua_State* luaVM )
{
    CCustomWeapon * pWeapon;
    CElement * pTarget;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pWeapon );
    if ( argStream.NextIsUserData () )
    {
        int targetBone;
        argStream.ReadUserData ( pTarget );
        argStream.ReadNumber ( targetBone, 255 );
        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::SetWeaponTarget ( pWeapon, pTarget, targetBone ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else if ( argStream.NextIsNumber () )
    {
        CVector vecTarget;
        argStream.ReadVector3D ( vecTarget );
        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::SetWeaponTarget ( pWeapon, vecTarget ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else if ( argStream.NextIsNil () )
    {
        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::ClearWeaponTarget ( pWeapon ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        argStream.SetCustomError ( "Expected element, number or nil at argument 2" );

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFxDefs::CreateEffect ( lua_State* luaVM )
{
    // bool createEffect ( string fxName, float posX, float posY, float posZ[, float rotX, float rotY, float rotZ] )

    CVector vecPosition;
    CVector vecRotation;
    SString strFxName;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strFxName );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecRotation, CVector(0, 0, 0) );

    if ( !argStream.HasErrors ( ) )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource();
            if ( pResource )
            {
                // Create it and return it
                CClientEffect * pFx = CStaticFunctionDefinitions::CreateEffect ( *pResource, strFxName, vecPosition );
                if ( pFx != NULL )
                {
                    pFx->SetRotationDegrees ( vecRotation );
                    lua_pushelement ( luaVM, pFx );
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFxDefs::fxAddSparks ( lua_State* luaVM )
{
    // bool fxAddSparks ( float posX, float posY, float posZ, float dirX, float dirY, float dirZ, [float force=1, int count=1, float acrossLineX=0, float acrossLineY=0, float acrossLineZ=0, bool blur=false, float spread=1, float life=1] )

    // Verify types
    CVector vecPosition, vecDirection;
    float fForce = 1.0f;
    int iCount = 1;
    CVector vecAcrossLine;
    bool bBlur = false;
    float fSpread = 1.0f;
    float fLife = 1.0f;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecDirection );
    argStream.ReadNumber ( fForce, 1.0f );
    argStream.ReadNumber ( iCount, 1 );
    argStream.ReadVector3D ( vecAcrossLine, vecAcrossLine );
    argStream.ReadBool ( bBlur, false );
    argStream.ReadNumber ( fSpread, 1.0f );
    argStream.ReadNumber ( fLife, 1.0f );

    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::FxAddSparks ( vecPosition, vecDirection, fForce, iCount, vecAcrossLine, bBlur, fSpread, fLife ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaMatrixDefs::Create ( lua_State* luaVM )
{
    CMatrix matrix;

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsVector3D () )
    {
        CVector vecPosition;
        argStream.ReadVector3D ( vecPosition );
        if ( argStream.NextIsVector3D () )
        {
            CVector vecRotation;
            argStream.ReadVector3D ( vecRotation );
            ConvertDegreesToRadiansNoWrap ( vecRotation );
            matrix = CMatrix ( vecPosition, vecRotation );
        }
        else
        {
            matrix = CMatrix ( vecPosition );
        }
    }
    else if ( argStream.NextIsUserDataOfType<CLuaMatrix> () )
    {
        argStream.ReadMatrix ( matrix );
        matrix = CMatrix ( matrix );
    }
    else if ( !argStream.NextIsNone() ) {
        argStream.SetCustomError ( "Expected vector3, matrix or nothing" );
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
        
        lua_pushboolean ( luaVM, false );
        return 1;
    }

    lua_pushmatrix ( luaVM, matrix );
    return 1;
}
int CLuaColShapeDefs::CreateColTube ( lua_State* luaVM )
{
    CVector vecPosition;
    float fRadius = 0.1f, fHeight = 0.1f;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadNumber ( fRadius );
    argStream.ReadNumber ( fHeight );

    if ( fRadius < 0.0f )
    {
        fRadius = 0.1f;
    }

    if ( fHeight < 0.0f )
    {
        fHeight = 0.1f;
    }

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                // Create it and return it
                CClientColTube* pShape = CStaticFunctionDefinitions::CreateColTube ( *pResource, vecPosition, fRadius, fHeight );
                if ( pShape )
                {
                    CElementGroup * pGroup = pResource->GetElementGroup ();
                    if ( pGroup )
                    {
                        pGroup->Add ( (CClientEntity*) pShape );
                    }
                    lua_pushelement ( luaVM, pShape );
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemple #19
0
int CLuaPedDefs::CreatePed ( lua_State* luaVM )
{
    unsigned short usModel;
    CVector vecPosition;
    float fRotation;
    bool bSynced;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadNumber ( usModel );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadNumber ( fRotation, 0.0f );
    argStream.ReadBool ( bSynced, true );

    if ( !argStream.HasErrors () )
    {
        CLuaMain * pLuaMain = g_pGame->GetLuaManager ()->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResource * pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                // Create the ped and return its handle
                CPed* pPed = CStaticFunctionDefinitions::CreatePed ( pResource, usModel, vecPosition, fRotation, bSynced );
                if ( pPed )
                {
                    CElementGroup * pGroup = pResource->GetElementGroup ();
                    if ( pGroup )
                    {
                        pGroup->Add ( pPed );
                    }
                    lua_pushelement ( luaVM, pPed );
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::GetDistanceBetweenPoints3D ( lua_State* luaVM )
{
    CVector vecA, vecB;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecA );
    argStream.ReadVector3D ( vecB );

    if ( !argStream.HasErrors () )
    {
        lua_pushnumber ( luaVM, DistanceBetweenPoints3D ( vecA, vecB ) );

        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::GetDistanceBetweenPoints3D ( lua_State* luaVM )
{
//  float getDistanceBetweenPoints3D ( float x1, float y1, float z1, float x2, float y2, float z2 )
    CVector vecPointA; CVector vecPointB;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPointA );
    argStream.ReadVector3D ( vecPointB );

    if ( !argStream.HasErrors () )
    {
        // Return the distance
        lua_pushnumber ( luaVM, DistanceBetweenPoints3D ( vecPointA, vecPointB ) );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::PlayMissionAudio ( lua_State* luaVM )
{
    CElement* pElement;
    CVector vecPosition;
    unsigned short usSlot;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pElement );
    argStream.ReadNumber ( usSlot );

    if ( argStream.NextCouldBeNumber () )
    {
        argStream.ReadVector3D ( vecPosition );

        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::PlayMissionAudio ( pElement, &vecPosition, usSlot ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }
    else if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::PlayMissionAudio ( pElement, NULL, usSlot ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );


    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetCameraTarget ( lua_State* luaVM )
{
//  bool setCameraTarget ( element target = nil ) or setCameraTarget ( float x, float y, float z )

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsUserData () )
    {
        CClientEntity* pTarget;
        argStream.ReadUserData ( pTarget );

        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::SetCameraTarget ( pTarget ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
    {
        CVector vecTarget;
        argStream.ReadVector3D ( vecTarget );

        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::SetCameraTarget ( vecTarget ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaMatrixDefs::TransformPosition ( lua_State* luaVM )
{
    CLuaMatrix* pMatrix1 = NULL;
    CVector vector;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pMatrix1 );
    argStream.ReadVector3D ( vector );

    if ( !argStream.HasErrors () )
    {
        lua_pushvector( luaVM, pMatrix1->TransformVector ( vector ) );
        return 1;
    }
    else
    {
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaOOPDefs::SetCameraRotation ( lua_State* luaVM )
{
    CVector vecRotation;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecRotation );

    if ( !argStream.HasErrors () )
    {
        CClientCamera* pCamera = m_pManager->GetCamera ();
        if ( !pCamera->IsInFixedMode () )        
        {
            pCamera->ToggleCameraFixedMode ( true );
        }

        pCamera->SetRotationDegrees ( vecRotation );

        lua_pushboolean ( luaVM, true );
        return 1;
    }
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFxDefs::fxAddGlass ( lua_State* luaVM )
{
    // bool fxAddGlass ( float posX, float posY, float posZ, [int colorR=255, int colorG=0, int colorB=0, int colorA=255, float scale=1.0, int count=1] )

    // Verify types
    CVector vecPosition;
    RwColor rwColor; 
    rwColor.r = 255; 
    rwColor.g = 0; 
    rwColor.b = 0; 
    rwColor.a = 255;
    float fScale = 1.0f;
    int iCount = 1;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadNumber ( rwColor.r, 255 );
    argStream.ReadNumber ( rwColor.g, 0 );
    argStream.ReadNumber ( rwColor.b, 0 );
    argStream.ReadNumber ( rwColor.a, 255 );
    argStream.ReadNumber ( fScale, 1.0f );
    argStream.ReadNumber ( iCount, 1 );

    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::FxAddGlass ( vecPosition, rwColor, fScale, iCount ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaMatrixDefs::SetUp ( lua_State* luaVM )
{
    CLuaMatrix* pMatrix = NULL;
    CVector vecUp;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pMatrix );
    argStream.ReadVector3D ( vecUp );

    if ( !argStream.HasErrors () )
    {
        pMatrix->vUp = vecUp;
        lua_pushboolean( luaVM, true );
        return 1;
    }
    else
    {
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
    }

    lua_pushboolean( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::CreateWeapon ( lua_State* luaVM )
{
    CVector vecPos;
    eWeaponType weaponType;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadEnumStringOrNumber ( weaponType );
    argStream.ReadVector3D ( vecPos );

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                CCustomWeapon * pWeapon = CStaticFunctionDefinitions::CreateWeapon ( pResource, weaponType, vecPos );
                if ( pWeapon )
                {
                    CElementGroup * pGroup = pResource->GetElementGroup ();
                    if ( pGroup )
                    {
                        pGroup->Add ( (CElement*) pWeapon );
                    }

                    lua_pushelement ( luaVM, pWeapon );
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaPointLightDefs::SetLightDirection ( lua_State* luaVM )
{
    //  bool setLightDirection ( light theLight, float x, float y, float z )
    CClientPointLights* pLight;
    CVector vecDirection;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pLight );
    argStream.ReadVector3D ( vecDirection );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::SetLightDirection ( pLight, vecDirection ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), *argStream.GetErrorMessage () ) );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemple #30
0
int CLuaWorldDefs::getZoneName ( lua_State* luaVM )
{
    CVector vecPosition;
    bool bCitiesOnly;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadBool ( bCitiesOnly, false );

    if ( !argStream.HasErrors ( ) )
    {
        SString strZoneName;
        if ( CStaticFunctionDefinitions::GetZoneName ( vecPosition, strZoneName, bCitiesOnly ) )
        {
            lua_pushstring ( luaVM, strZoneName );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}