Exemplo n.º 1
0
int CLuaFunctionDefs::AddCommandHandler ( lua_State* luaVM )
{
    //  bool addCommandHandler ( string commandName, function handlerFunction, [bool restricted = false, bool caseSensitive = true] )
    SString strKey; CLuaFunctionRef iLuaFunction; bool bRestricted; bool bCaseSensitive;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strKey );
    argStream.ReadFunction ( iLuaFunction );
    argStream.ReadBool ( bRestricted, false );
    argStream.ReadBool ( bCaseSensitive, true );
    argStream.ReadFunctionComplete ();

    if ( !argStream.HasErrors () )
    {
        // Grab our VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Add them to our list over command handlers
            if ( m_pRegisteredCommands->AddCommand ( pLuaMain, strKey, iLuaFunction, bRestricted, bCaseSensitive ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 2
0
int CLuaFunctionDefs::ShowCursor ( lua_State* luaVM )
{
    bool bShow = false, bToggleControls = true;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadBool ( bShow );
    argStream.ReadBool ( bToggleControls, true );

    if ( !argStream.HasErrors ( ) )
    {
        // Get the VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Grab the resource belonging to this VM
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                // Show/hide it inside that resource
                pResource->ShowCursor ( bShow, bToggleControls );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Fail
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetSoundEffectEnabled ( lua_State* luaVM )
{
    CClientPlayer* pPlayer = NULL;
    CClientSound* pSound = NULL;
    SString strEffectName = "";
    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsUserDataOfType < CClientSound > ( ) )
    {
        argStream.ReadUserData ( pSound );
    }
    else if ( argStream.NextIsUserDataOfType < CClientPlayer > ( ) )
    {
        argStream.ReadUserData ( pPlayer );
    }
    else
    {
        m_pScriptDebugging->LogBadPointer ( luaVM, "sound/player", 1 );
        lua_pushboolean ( luaVM, false );
        return false;
    }
    argStream.ReadString ( strEffectName );

    if ( !argStream.HasErrors() )
    {
        if ( pSound )
        {
            bool bEnable = false;
            if ( argStream.NextIsBool ( ) )
            {
                argStream.ReadBool ( bEnable );
            }
            if ( CStaticFunctionDefinitions::SetSoundEffectEnabled ( *pSound, strEffectName, bEnable ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
        else if ( pPlayer )
        {
            bool bEnable = false;
            if ( argStream.NextIsBool ( ) )
            {
                argStream.ReadBool ( bEnable );
            }
            if ( CStaticFunctionDefinitions::SetSoundEffectEnabled ( *pPlayer, strEffectName, bEnable ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetCameraClip ( lua_State* luaVM )
{
    bool bObjects = true;
    bool bVehicles = true;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadBool ( bObjects, true );
    argStream.ReadBool ( bVehicles, true );

    m_pManager->GetCamera ()->SetCameraClip ( bObjects, bVehicles );

    lua_pushboolean ( luaVM, true );
    return 1;
}
Exemplo n.º 5
0
int CLuaWorldDefs::setHeatHaze ( lua_State* luaVM )
{
    CScriptArgReader argStream ( luaVM );

    // Set the new heat haze settings
    SHeatHazeSettings heatHaze;
    argStream.ReadNumber ( heatHaze.ucIntensity );
    argStream.ReadNumber ( heatHaze.ucRandomShift, 0 );
    argStream.ReadNumber ( heatHaze.usSpeedMin, 12 );
    argStream.ReadNumber ( heatHaze.usSpeedMax, 18 );
    argStream.ReadNumber ( heatHaze.sScanSizeX, 75 );
    argStream.ReadNumber ( heatHaze.sScanSizeY, 80 );
    argStream.ReadNumber ( heatHaze.usRenderSizeX, 80 );
    argStream.ReadNumber ( heatHaze.usRenderSizeY, 85 );
    argStream.ReadBool ( heatHaze.bInsideBuilding, false );

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

    // Return false
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::PlaySFX ( lua_State* luaVM )
{
//  sound playSFX ( string audioContainer, int bankIndex, int audioIndex [, loop = false ] )
    eAudioLookupIndex containerIndex; int iBankIndex; int iAudioIndex; bool bLoop;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadEnumString ( containerIndex );
    argStream.ReadNumber ( iBankIndex );
    argStream.ReadNumber ( iAudioIndex );
    argStream.ReadBool ( bLoop, false );

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                CClientSound* pSound;
                if ( CStaticFunctionDefinitions::PlaySFX ( pResource, containerIndex, iBankIndex, iAudioIndex, bLoop, pSound ) )
                {
                    lua_pushelement ( luaVM, pSound );
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetSoundProperties ( lua_State* luaVM )
{
    CClientSound* pSound = NULL;
    bool bReversed = false;
    float fSampleRate = 0.0f, fTempo = 0.0f, fPitch = 0.0f;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pSound );
    argStream.ReadNumber ( fSampleRate );
    argStream.ReadNumber ( fTempo );
    argStream.ReadNumber ( fPitch );
    argStream.ReadBool ( bReversed, false );

    if ( !argStream.HasErrors () )
    {
        if ( pSound )
        {
            if ( CStaticFunctionDefinitions::SetSoundProperties ( *pSound, fSampleRate, fTempo, fPitch, bReversed ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 8
0
int CLuaFunctionDefs::AddEvent ( lua_State* luaVM )
{
//  bool addEvent ( string eventName [, bool allowRemoteTrigger = false ] )
    SString strName; bool bAllowRemoteTrigger;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strName );
    argStream.ReadBool ( bAllowRemoteTrigger, false );

    if ( !argStream.HasErrors () )
    {
        // Grab our virtual machine
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Do it
            if ( CStaticFunctionDefinitions::AddEvent ( *pLuaMain, strName, bAllowRemoteTrigger ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "addEvent", *argStream.GetErrorMessage () ) );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetWorldSoundEnabled ( lua_State* luaVM )
{
//  setWorldSoundEnabled ( int group, [int index, ], bool enable )
    int group; int index = -1; bool bEnabled;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadNumber ( group );
    if ( !argStream.NextIsBool () )
        argStream.ReadNumber ( index );
    argStream.ReadBool ( bEnabled );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::SetWorldSoundEnabled ( group, index, bEnabled ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 10
0
int CLuaPedDefs::GiveWeapon ( lua_State* luaVM )
{
    // bool giveWeapon ( ped thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] )
    CElement* pElement; eWeaponType weaponType; ushort usAmmo; bool bSetAsCurrent;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pElement );
    argStream.ReadEnumStringOrNumber ( weaponType );
    argStream.ReadNumber ( usAmmo, 30 );
    argStream.ReadBool ( bSetAsCurrent, false );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::GiveWeapon ( pElement, weaponType, usAmmo, bSetAsCurrent ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 11
0
int CLuaPlayerDefs::SetPlayerNametagShowing ( lua_State* luaVM )
{
    //  bool setPlayerNametagShowing ( player thePlayer, bool showing )
    CClientEntity* pPlayer; bool bShowing;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pPlayer );
    argStream.ReadBool ( bShowing );

    if ( !argStream.HasErrors () )
    {
        // Set the new rotation
        if ( CStaticFunctionDefinitions::SetPlayerNametagShowing ( *pPlayer, bShowing ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 12
0
int CLuaEngineDefs::EngineReplaceModel ( lua_State* luaVM )
{
    CClientDFF* pDFF;
    SString strModelName;
    bool bAlphaTransparency;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pDFF );
    argStream.ReadString ( strModelName );
    argStream.ReadBool ( bAlphaTransparency, false );

    if ( !argStream.HasErrors () )
    {
        ushort usModelID = CModelNames::ResolveModelID ( strModelName );
        if ( usModelID != INVALID_MODEL_ID )
        {
            if ( pDFF->ReplaceModel ( usModelID, bAlphaTransparency ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
            else
                argStream.SetCustomError( SString( "Model ID %d replace failed", usModelID ) );
        }
        else
            argStream.SetCustomError( "Expected valid model ID or name at argument 2" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 13
0
int CLuaPedDefs::SetPedRotation ( lua_State* luaVM )
{
    //  setPedRotation ( element ped, float rotation [, bool fixPedRotation = false ] )
    CElement* pElement; float fRotation; bool bNewWay;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pElement );
    argStream.ReadNumber ( fRotation );
    argStream.ReadBool ( bNewWay, false );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::SetPedRotation ( pElement, fRotation, bNewWay ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 14
0
int CLuaFxDefs::fxAddGunshot ( lua_State* luaVM )
{
    // bool fxAddGunshot ( float posX, float posY, float posZ, float dirX, float dirY, float dirZ, [bool includeSparks=true] )

    // Verify types
    CVector vecPosition, vecDirection;
    bool bIncludeSparks = true;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecDirection );
    argStream.ReadBool ( bIncludeSparks, true );

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

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 15
0
int CLuaFunctionDefs::SetSoundPanEnabled ( lua_State* luaVM )
{
    CClientSound* pSound = NULL;
    bool bEnabled = true;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pSound );
    argStream.ReadBool ( bEnabled );

    if ( !argStream.HasErrors () )
    {
        if ( pSound )
        {
            if ( CStaticFunctionDefinitions::SetSoundPanEnabled ( *pSound, bEnabled ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 16
0
int CLuaCameraDefs::fadeCamera ( lua_State* luaVM )
{
//  bool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )
    CElement* pPlayer; bool bFadeIn; float fFadeTime; unsigned char ucRed; unsigned char ucGreen; unsigned char ucBlue;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pPlayer );
    argStream.ReadBool ( bFadeIn );
    argStream.ReadNumber ( fFadeTime, 1.0f );
    argStream.ReadNumber ( ucRed, 0 );
    argStream.ReadNumber ( ucGreen, 0 );
    argStream.ReadNumber ( ucBlue, 0 );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::FadeCamera ( pPlayer, bFadeIn, fFadeTime, ucRed, ucGreen, ucBlue ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::RequestBrowserDomains ( lua_State* luaVM )
{
//  bool requestBrowserDomains ( table domains, bool isURL )
    std::vector<SString> pages; bool bIsURL;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadStringTable ( pages );
    argStream.ReadBool ( bIsURL, false );

    if ( !argStream.HasErrors () )
    {
        // Convert to domains if we got a list of URLs
        if ( bIsURL )
        {
            for ( auto& strURL : pages )
            {
                strURL = g_pCore->GetWebCore ()->GetDomainFromURL ( strURL );
            }
        }

        g_pCore->GetWebCore ()->RequestPages ( pages );
        // Todo: Add a callback or event to check if the pagerequest dialog was successfully done
        lua_pushboolean ( luaVM, true );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::IsBrowserDomainBlocked ( lua_State* luaVM )
{
//  bool isBrowserDomainBlocked ( string domain, bool isURL )
    SString strURL; bool bIsURL;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strURL );
    argStream.ReadBool ( bIsURL, false );

    if ( !argStream.HasErrors () )
    {
        if ( bIsURL )
            strURL = g_pCore->GetWebCore ()->GetDomainFromURL ( strURL );

        if ( !strURL.empty () )
        {
            lua_pushboolean ( luaVM, g_pCore->GetWebCore ()->GetURLState ( strURL ) != eURLState::WEBPAGE_ALLOWED );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushnil ( luaVM );
    return 1;
}
Exemplo n.º 19
0
int CLuaFunctionDefs::ToggleBrowserDevTools ( lua_State* luaVM )
{
//  bool toggleBrowserDevTools ( browser webBrowser, bool visible )
    CClientWebBrowser* pWebBrowser; bool visible;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pWebBrowser );
    argStream.ReadBool ( visible );

    if ( !argStream.HasErrors () )
    {
        if ( g_pCore->GetWebCore ()->IsTestModeEnabled () )
        {
            lua_pushboolean ( luaVM, pWebBrowser->ToggleDevTools ( visible ) );
            return 1;
        }
        else
            m_pScriptDebugging->LogCustom ( luaVM, "toggleBrowserDevtools can only be used in development mode" );
        
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 20
0
int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
{
    // Got a string argument?
    CScriptArgReader argStream ( luaVM );

    if ( !argStream.NextIsNil () )
    {
        bool bCompact = false;
        // Read the argument
        CLuaArguments JSON;
        JSON.ReadArgument ( luaVM, 1 );
        argStream.Skip ( 1 );
        argStream.ReadBool ( bCompact, false );

        if ( !argStream.HasErrors () )
        {
            // Convert it to a JSON string
            std::string strJSON;
            if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
            {
                // Return the JSON string
                lua_pushstring ( luaVM, strJSON.c_str () );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM );

    // Failed
    lua_pushnil ( luaVM );
    return 1;
}
Exemplo n.º 21
0
int CLuaEngineDefs::EngineLoadTXD ( lua_State* luaVM )
{
    SString strFile = "";
    bool bFilteringEnabled = true;
    CScriptArgReader argStream ( luaVM );
    // Grab the TXD filename or data
    argStream.ReadString ( strFile );
    if ( argStream.NextIsBool() )   // Some scripts have a number here (in error)
        argStream.ReadBool ( bFilteringEnabled, true );

    if ( !argStream.HasErrors ( ) )
    {
        // Grab our virtual machine and grab our resource from that.
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Grab this resource
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                bool bIsRawData = CClientTXD::IsTXDData( strFile );
                SString strPath;
                // Is this a legal filepath?
                if ( bIsRawData || CResourceManager::ParseResourcePathInput( strFile, pResource, &strPath ) )
                {
                    // Grab the resource root entity
                    CClientEntity* pRoot = pResource->GetResourceTXDRoot ();

                    // Create a TXD element
                    CClientTXD* pTXD = new CClientTXD ( m_pManager, INVALID_ELEMENT_ID );

                    // Try to load the TXD file
                    if ( pTXD->LoadTXD ( bIsRawData ? strFile : strPath, bFilteringEnabled, bIsRawData ) )
                    {
                        // Success loading the file. Set parent to TXD root
                        pTXD->SetParent ( pRoot );

                        // Return the TXD
                        lua_pushelement ( luaVM, pTXD );
                        return 1;
                    }
                    else
                    {
                        // Delete it again
                        delete pTXD;
                        argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Error loading TXD" );
                    }
                }
                else
                    argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Bad file path" );
            }
        }
    }
    if ( argStream.HasErrors() )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // We failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 22
0
int CLuaPedDefs::KillPed ( lua_State* luaVM )
{
    CElement* pElement, *pKiller;
    unsigned char ucKillerWeapon;
    unsigned char ucBodyPart;
    bool bStealth;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pElement );
    argStream.ReadUserData ( pKiller, NULL );
    argStream.ReadNumber ( ucKillerWeapon, 0xFF );
    argStream.ReadNumber ( ucBodyPart, 0xFF );
    argStream.ReadBool ( bStealth, false );


    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::KillPed ( pElement, pKiller, ucKillerWeapon, ucBodyPart, bStealth ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 23
0
// Call a function on a remote server
int CLuaFunctionDefs::FetchRemote ( lua_State* luaVM )
{
    //  bool fetchRemote ( string URL [, int connectionAttempts = 10, int connectTimeout = 10000 ], callback callbackFunction, [ string postData, bool bPostBinary, arguments... ] )
    CScriptArgReader argStream ( luaVM );
    SString strURL; CLuaFunctionRef iLuaFunction; SString strPostData; bool bPostBinary; CLuaArguments args; uint uiConnectionAttempts; uint uiConnectTimeoutMs;

    argStream.ReadString ( strURL );
    if ( argStream.NextIsNumber () )
        MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_CONNECTION_ATTEMPTS, "'connection attempts' is being used" );
    argStream.ReadIfNextIsNumber ( uiConnectionAttempts, 10 );
    if ( argStream.NextIsNumber () )
        MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_CONNECT_TIMEOUT, "'connect timeout' is being used" );
    argStream.ReadIfNextIsNumber ( uiConnectTimeoutMs, 10000 );
    argStream.ReadFunction ( iLuaFunction );
    argStream.ReadString ( strPostData, "" );
    argStream.ReadBool ( bPostBinary, false );
    argStream.ReadLuaArguments ( args );
    argStream.ReadFunctionComplete ();

    if ( !argStream.HasErrors () )
    {
        CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            g_pGame->GetRemoteCalls ()->Call ( strURL, &args, strPostData, bPostBinary, luaMain, iLuaFunction, uiConnectionAttempts, uiConnectTimeoutMs );
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 24
0
int CLuaFunctionDefs::SaveMapData ( lua_State* luaVM )
{
    CXMLNode* pXML;
    CElement* pParent;
    bool bChildren;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pXML );
    argStream.ReadUserData ( pParent );
    argStream.ReadBool ( bChildren, false );

    if ( !argStream.HasErrors () )
    {
        CXMLNode* pSavedNode = CStaticFunctionDefinitions::SaveMapData ( pParent, pXML, bChildren );
        if ( pSavedNode )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 25
0
int CLuaFunctionDefs::SetDevelopmentMode ( lua_State* luaVM )
{
//  bool setDevelopmentMode ( bool enable )
//  bool setDevelopmentMode ( string command )
    bool bEnable; SString strCommand;

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsString () )
    {
        argStream.ReadString ( strCommand );
        //g_pClientGame->SetDevSetting ( strCommand );
        lua_pushboolean ( luaVM, true );
        return 1;
    }
    argStream.ReadBool ( bEnable );

    if ( !argStream.HasErrors () )
    {
        g_pClientGame->SetDevelopmentMode ( bEnable );
        lua_pushboolean ( luaVM, true );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::FadeCamera ( lua_State* luaVM )
{
    bool bFadeIn = false;
    unsigned char ucRed = 0;
    unsigned char ucGreen = 0;
    unsigned char ucBlue = 0;
    float fFadeTime = 1.0f;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadBool ( bFadeIn );
    argStream.ReadNumber ( fFadeTime, 1.0f );
    argStream.ReadNumber ( ucRed, 0 );
    argStream.ReadNumber ( ucGreen, 0 );
    argStream.ReadNumber ( ucBlue, 0 );

    if ( !argStream.HasErrors ( ) )
    {
        if ( CStaticFunctionDefinitions::FadeCamera ( bFadeIn, fFadeTime, ucRed, ucGreen, ucBlue ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 27
0
int CLuaPedDefs::SetPedAnimation ( lua_State* luaVM )
{
    // bool setPedAnimation ( ped thePed [, string block=nil, string anim=nil, int time=-1, bool loop=true, bool updatePosition=true, bool interruptable=true, bool freezeLastFrame = true] )
    CElement * pPed;
    SString strBlockName, strAnimName;
    int iTime;
    bool bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame;
    bool bDummy;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pPed );
    if ( argStream.NextIsBool () )
        argStream.ReadBool ( bDummy );      // Wiki used setPedAnimation(source,false) as an example
    else
        if ( argStream.NextIsNil () )
            argStream.m_iIndex++;               // Wiki docs said blockName could be nil
        else
            argStream.ReadString ( strBlockName, "" );
    argStream.ReadString ( strAnimName, "" );
    if ( argStream.NextCouldBeNumber () )    // Freeroam skips the time arg sometimes
        argStream.ReadNumber ( iTime, -1 );
    else
        iTime = -1;
    argStream.ReadBool ( bLoop, true );
    argStream.ReadBool ( bUpdatePosition, true );
    argStream.ReadBool ( bInterruptable, true );
    argStream.ReadBool ( bFreezeLastFrame, true );

    if ( !argStream.HasErrors () )
    {
        const char *szBlock, *szAnim;
        szBlock = strBlockName.empty () ? NULL : strBlockName.c_str ();
        szAnim = strAnimName.empty () ? NULL : strAnimName.c_str ();

        if ( CStaticFunctionDefinitions::SetPedAnimation ( pPed, szBlock, szAnim, iTime, bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 28
0
int CLuaEngineDefs::EngineSetAsynchronousLoading ( lua_State* luaVM )
{
    bool bEnabled = false;
    bool bForced = false;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadBool ( bEnabled );
    argStream.ReadBool ( bForced, false );

    if ( !argStream.HasErrors () )
    {
        g_pGame->SetAsyncLoadingFromScript ( bEnabled, bForced );
        lua_pushboolean ( luaVM, true );
        return 1;
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 29
0
int CLuaFunctionDefs::PlaySound3D ( lua_State* luaVM )
{
    SString strSound = "";
    CVector vecPosition;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strSound );
    argStream.ReadNumber ( vecPosition.fX );
    argStream.ReadNumber ( vecPosition.fY );
    argStream.ReadNumber ( vecPosition.fZ );

    if ( !argStream.HasErrors() )
    {
        CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            CResource* pResource = luaMain->GetResource();
            if ( pResource )
            {
                SString strFilename;
                bool bIsURL = false;
                if ( CResourceManager::ParseResourcePathInput( strSound, pResource, strFilename ) )
                    strSound = strFilename;
                else
                    bIsURL = true;

                // ParseResourcePathInput changes pResource in some cases e.g. an invalid resource URL - crun playSound( ":myNotRunningResource/music/track.mp3" )
                // Fixes #6507 - Caz
                if ( pResource )
                {
                    bool bLoop = false;
                    if ( argStream.NextIsBool ( ) )
                    {
                        argStream.ReadBool ( bLoop );
                    }

                    CClientSound* pSound = CStaticFunctionDefinitions::PlaySound3D ( pResource, strSound, bIsURL, vecPosition, bLoop );
                    if ( pSound )
                    {
                        // call onClientSoundStarted
                        CLuaArguments Arguments;
                        Arguments.PushString ( "play" );     // Reason
                        pSound->CallEvent ( "onClientSoundStarted", Arguments, false );

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

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 30
0
int CLuaFunctionDefs::RequestBrowserDomains ( lua_State* luaVM )
{
//  bool requestBrowserDomains ( table domains, bool isURL [, function callback ] )
    std::vector<SString> pages; bool bIsURL; CLuaFunctionRef callbackFunction;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadStringTable ( pages );
    argStream.ReadBool ( bIsURL, false );
    argStream.ReadFunction ( callbackFunction, LUA_REFNIL );
    argStream.ReadFunctionComplete ();

    if ( !argStream.HasErrors () )
    {
        // Convert to domains if we got a list of URLs
        if ( bIsURL )
        {
            for ( auto& strURL : pages )
            {
                strURL = g_pCore->GetWebCore ()->GetDomainFromURL ( strURL );
            }
        }

        WebRequestCallback callback = [=]( bool bAllow, const std::vector<SString>& domains ) {
            // Test if luaVM is still available
            if ( m_pLuaManager->IsLuaVMValid ( luaVM ) && VERIFY_FUNCTION ( callbackFunction ) )
            {
                CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
                if ( !pLuaMain )
                    return;

                CLuaArguments arguments;
                arguments.PushBoolean ( bAllow );
                
                CLuaArguments LuaTable;
                int i = 0;
                for ( const auto& domain : domains )
                {
                    LuaTable.PushNumber ( ++i );
                    LuaTable.PushString ( domain );
                }
                arguments.PushTable ( &LuaTable );
                arguments.Call ( pLuaMain, callbackFunction );
            }
        };

        g_pCore->GetWebCore ()->RequestPages ( pages, VERIFY_FUNCTION ( callbackFunction ) ? &callback : nullptr );
        lua_pushboolean ( luaVM, true );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}