Esempio n. 1
0
int CLuaColShapeDefs::CreateColPolygon ( lua_State* luaVM )
{
    CVector2D vecPosition;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadVector2D ( vecPosition );

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                // Create it and return it
                CClientColPolygon* pShape = CStaticFunctionDefinitions::CreateColPolygon ( *pResource, vecPosition );
                if ( pShape )
                {
                    // Get the points
                    while ( argStream.NextCouldBeNumber () && argStream.NextCouldBeNumber ( 1 ) )
                    {
                        argStream.ReadVector2D ( vecPosition );
                        pShape->AddPoint ( vecPosition );
                    }

                    CElementGroup * pGroup = pResource->GetElementGroup ();
                    if ( pGroup )
                    {
                        pGroup->Add ( pShape );
                    }
                    lua_pushelement ( luaVM, pShape );
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Esempio n. 2
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;
}
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::GetCTime ( lua_State* luaVM )
{
    // table getRealTime( [int seconds = current], bool localTime = true )
    time_t timer;
    time ( &timer );
    bool bLocalTime = true;
    CScriptArgReader argStream ( luaVM );

    if ( argStream.NextCouldBeNumber () )
    {
        argStream.ReadNumber ( timer );
        if ( timer < 0 )
        {
            argStream.SetCustomError ( "seconds cannot be negative" );
        }
    }

    if ( argStream.NextIsBool () )
        argStream.ReadBool ( bLocalTime );

    tm * time;
    if ( bLocalTime )
        time = localtime ( &timer );
    else
        time = gmtime ( &timer );

    if ( time == NULL )
        argStream.SetCustomError ( "seconds is out of range" );

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

    CLuaArguments ret;
    ret.PushString ( "second" );
    ret.PushNumber ( time->tm_sec );
    ret.PushString ( "minute" );
    ret.PushNumber ( time->tm_min );
    ret.PushString ( "hour" );
    ret.PushNumber ( time->tm_hour );
    ret.PushString ( "monthday" );
    ret.PushNumber ( time->tm_mday );
    ret.PushString ( "month" );
    ret.PushNumber ( time->tm_mon );
    ret.PushString ( "year" );
    ret.PushNumber ( time->tm_year );
    ret.PushString ( "weekday" );
    ret.PushNumber ( time->tm_wday );
    ret.PushString ( "yearday" );
    ret.PushNumber ( time->tm_yday );
    ret.PushString ( "isdst" );
    ret.PushNumber ( time->tm_isdst );
    ret.PushString ( "timestamp" );
    ret.PushNumber ( (double) timer );

    ret.PushAsTable ( luaVM );

    return 1;
}