Example #1
0
int CLuaPickupDefs::setPickupRespawnInterval ( lua_State* luaVM )
{
    int iArgument2 = lua_type ( luaVM, 2 );
    if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA &&
         ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) )
    {
        CElement* pElement = lua_toelement ( luaVM, 1 );
        if ( pElement )
        {
            unsigned long ulInterval = static_cast < unsigned long > ( lua_tonumber ( luaVM, 2 ) );
            if ( CStaticFunctionDefinitions::SetPickupRespawnInterval ( pElement, ulInterval ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "setPickupRespawnInterval", "element", 1 );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "setPickupRespawnInterval" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #2
0
int CLuaPickupDefs::usePickup ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA &&
         lua_type ( luaVM, 2 ) == LUA_TLIGHTUSERDATA )
    {
        CElement* pElement = lua_toelement ( luaVM, 1 );
        if ( pElement )
        {
            CPlayer * pPlayer = lua_toplayer ( luaVM, 2 );
            if ( pPlayer )
            {
                // Do it
                if ( CStaticFunctionDefinitions::UsePickup ( pElement, pPlayer ) )
                {
                    lua_pushboolean ( luaVM, true );
                    return 1;
                }
            }
            else
                m_pScriptDebugging->LogBadPointer ( luaVM, "usePickup", "player", 2 );
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "usePickup", "element", 1 );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "usePickup" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #3
0
int CLuaPickupDefs::setPickupType ( lua_State* luaVM )
{
    // The first 2 are always numeric saying weapon/health/armor
    int iArgument1 = lua_type ( luaVM, 1 );
    int iArgument2 = lua_type ( luaVM, 2 );
    int iArgument3 = lua_type ( luaVM, 3 );
    if ( ( iArgument1 == LUA_TLIGHTUSERDATA ) &&
         ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
         ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) )
    {
        CElement* pElement = lua_toelement ( luaVM, 1 );
        if ( pElement )
        {
            // Do it
            if ( CStaticFunctionDefinitions::SetPickupType ( pElement, static_cast < unsigned char > ( lua_tonumber ( luaVM, 2 ) ), lua_tonumber ( luaVM, 3 ), lua_tonumber ( luaVM, 4 ) ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "setPickupType", "element", 1 );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "setPickupType" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #4
0
CPlayer* lua_toplayer ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_PLAYER ( pElement ) )
        return static_cast < CPlayer* > ( pElement );
    else
        return NULL;
}
Example #5
0
CRadarArea* lua_toradararea ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_RADAR_AREA ( pElement ) )
        return static_cast < CRadarArea* > ( pElement );
    else
        return NULL;
}
Example #6
0
CMarker* lua_tomarker ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_MARKER ( pElement ) )
        return static_cast < CMarker* > ( pElement );
    else
        return NULL;
}
Example #7
0
CColShape* lua_tocolshape ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_COLSHAPE ( pElement ) )
        return static_cast < CColShape* > ( pElement );
    else
        return NULL;
}
Example #8
0
CScriptFile* lua_tofile ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_FILE ( pElement ) )
        return static_cast < CScriptFile* > ( pElement );
    else
        return NULL;
}
Example #9
0
CWater* lua_towater ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_WATER ( pElement ) )
        return static_cast < CWater* > ( pElement );
    else
        return NULL;
}
Example #10
0
CBlip* lua_toblip ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_BLIP ( pElement ) )
        return static_cast < CBlip* > ( pElement );
    else
        return NULL;
}
Example #11
0
CTeam* lua_toteam ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_TEAM ( pElement ) )
        return static_cast < CTeam* > ( pElement );
    else
        return NULL;
}
Example #12
0
CVehicle* lua_tovehicle ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_VEHICLE ( pElement ) )
        return static_cast < CVehicle* > ( pElement );
    else
        return NULL;
}
Example #13
0
CPickup* lua_topickup ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_PICKUP ( pElement ) )
        return static_cast < CPickup* > ( pElement );
    else
        return NULL;
}
Example #14
0
CPed* lua_toped ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_PED ( pElement ) )
        return static_cast < CPed* > ( pElement );
    else
        return NULL;
}
Example #15
0
CObject* lua_toobject ( lua_State* luaVM, int iArgument )
{
    CElement* pElement = lua_toelement ( luaVM, iArgument );
    if ( pElement && IS_OBJECT ( pElement ) )
        return static_cast < CObject* > ( pElement );
    else
        return NULL;
}
Example #16
0
int CLuaClassDefs::NewIndex ( lua_State* luaVM )
{
    CElement* pElement = lua_toelement ( luaVM, 1 );

    if ( pElement )
    {
        lua_pushvalue ( luaVM, lua_upvalueindex ( 1 ) );

        lua_pushstring ( luaVM, "__set" );
        lua_rawget ( luaVM, -2 );

        if ( !lua_istable ( luaVM, -1 ) )
        {
            lua_remove ( luaVM, -2 );
            goto searchparent;
        }

        lua_pushvalue ( luaVM, 2 );
        lua_rawget ( luaVM, -2 );
        lua_remove ( luaVM, -2 );

        if ( lua_isfunction ( luaVM, -1 ) )
        { // Found the property
            lua_pushvalue ( luaVM, 1 );
            lua_pushvalue ( luaVM, 3 );

            lua_call ( luaVM, 2, 0 );
            return 0;
        }

searchparent:
        lua_pushstring ( luaVM, "__parent" );
        lua_rawget ( luaVM, -2 );
        if ( lua_istable ( luaVM, -1 ) )
        {
            lua_pushstring ( luaVM, "__newindex" );
            lua_rawget ( luaVM, -2 );
            if ( lua_isfunction ( luaVM, -1 ) )
            {
                lua_pushvalue ( luaVM, 1 );
                lua_pushvalue ( luaVM, 2 );
                lua_pushvalue ( luaVM, 3 );

                lua_call ( luaVM, 3, 0 );

                lua_pop ( luaVM, 2 );
                return 0;
            }
            lua_pop ( luaVM, 1 );
        }
        lua_pop ( luaVM, 2 );
    }

    return 0;
}
Example #17
0
int CLuaVoiceDefs::setPlayerVoiceIgnoreFrom ( lua_State* luaVM )
{
    // Arg 1, player
    CPlayer* pPlayer = lua_toplayer ( luaVM, 1 );
    if ( !pPlayer )
    {
        m_pScriptDebugging->LogBadPointer ( luaVM, "setPlayerVoiceIgnoreFrom", "player", 1 );
        lua_pushboolean ( luaVM, false );
        return 1;
    }

    // Arg 2, element OR table OR nil
    CElement* pElement = lua_toelement ( luaVM, 2 );
    if ( pElement )
        pPlayer->SetVoiceIgnoredElement ( pElement );
    else if ( lua_type ( luaVM, 2 ) == LUA_TTABLE )
    {
        std::list < CElement* > lstElements;
        for (lua_pushnil(luaVM); lua_next(luaVM, 2); lua_pop(luaVM, 1))
        {
            CElement* pListedElement = lua_toelement ( luaVM, -1 );
            if ( pListedElement )
                lstElements.push_back ( pListedElement );
        }
        pPlayer->SetVoiceIgnoredList ( lstElements );
    }
    else if ( lua_type ( luaVM, 2 ) == LUA_TNIL )
        pPlayer->SetVoiceIgnoredElement ( NULL ); // Remove all ignored
    else
    {
        m_pScriptDebugging->LogBadPointer ( luaVM, "setPlayerVoiceIgnoreFrom", "ignoreFrom", 2 );
        lua_pushboolean ( luaVM, false );
        return 1;
    }

    lua_pushboolean ( luaVM, true );
    return 1;
}
Example #18
0
int CLuaTaskDefs::setPlayerTask ( lua_State* luaVM )
{
    // bool setPlayerTask ( ped thePed, taskinstance task )
    // returns true on success or false on failure

    // Verify types
    if ( argtype ( 1, LUA_TLIGHTUSERDATA ) &&
         argtype ( 2, LUA_TTABLE ) )
    {
        // Grab the player
        // TODO: Support peds too
        CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
        if ( pEntity )
        {
            // Player?
            if ( pEntity->GetType () == CCLIENTPLAYER )
            {
                // Grab the player
                CClientPlayer* pPlayer = static_cast < CClientPlayer* > ( pEntity );

                // Read out the task data
                CClientTask Task ( m_pManager );
                if ( Task.Read ( luaVM, 2, true ) )
                {
                    // Apply it on the player
                    bool bSuccess = Task.ApplyTask ( *pPlayer );

                    // Success
                    lua_pushboolean ( luaVM, bSuccess );
                    return 1;
                }
            }
        }
    }

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #19
0
int CLuaACLDefs::hasObjectPermissionTo ( lua_State* luaVM )
{
    // What object name we're going to check
    CAccessControlListGroupObject::EObjectType eObjectType;
    std::string strObject;

    // Got a pointer argument?
    if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA )
    {
        // Grab it
        CResource* pResource = lua_toresource ( luaVM, 1 );
        CElement* pElement = lua_toelement ( luaVM, 1 );

        // Is it a valid resource?
        if ( pResource )
        {
            // Grab the resource's name
            strObject = pResource->GetName ();
            eObjectType = CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE;
        }

        // Is this a valid element?
        else if ( pElement )
        {
            // Grab the client this player/console/whatever is
            CClient* pClient = pElement->GetClient ();
            if ( pClient )
            {
                // Get his account
                CAccount* pAccount = pClient->GetAccount ();
                if ( pAccount )
                {
                    // Grab the username
                    strObject = pAccount->GetName ();
                    eObjectType = CAccessControlListGroupObject::OBJECT_TYPE_USER;
                }
            }
        }
    }

    // Got a string argument?
    else if ( lua_type ( luaVM, 1 ) == LUA_TSTRING )
    {
        // Change the pointer to point to our argument
        strObject = lua_tostring ( luaVM, 1 );

        // Extract the object name itself including the type
        const char * szName = CAccessControlListManager::ExtractObjectName ( strObject.c_str (), eObjectType );
        strObject = szName ? szName : "";
    }

    // Got a string?
    if ( !strObject.empty () )
    {
        // Got a string with the action to check for permission?
        if ( lua_type ( luaVM, 2 ) == LUA_TSTRING )
        {
            // Grab the right name we should've gotten passed
            const char* szRightName = lua_tostring ( luaVM, 2 );

            // Extract the right name itself including the type
            CAccessControlListRight::ERightType eRightType;
            szRightName = CAccessControlListManager::ExtractRightName ( szRightName, eRightType );

            // Did we get a right name without the prefix?
            if ( szRightName )
            {
                // Third argument to specify what the return defaults to.
                // This is if no ACL could be found.
                bool bDefault = true;
                if ( lua_type ( luaVM, 3 ) == LUA_TBOOLEAN )
                {
                    bDefault = lua_toboolean ( luaVM, 3 ) ? true:false;
                }

                // Check whether he has permissions to do that
                bool bHasPermission = m_pACLManager->CanObjectUseRight ( strObject.c_str (),
                                                                         eObjectType,
                                                                         szRightName,
                                                                         eRightType,
                                                                         bDefault );

                // Return whether we had access or not
                lua_pushboolean ( luaVM, bHasPermission );
                return 1;
            }
            else
                m_pScriptDebugging->LogBadType ( luaVM, "hasObjectPermissionTo" );
        }
        else
            m_pScriptDebugging->LogBadType ( luaVM, "hasObjectPermissionTo" );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "hasObjectPermissionTo" );

    // Failed
    lua_pushnil ( luaVM );
    return 1;
}
Example #20
0
int CLuaFunctionDefs::IsLineOfSightClear ( lua_State * luaVM )
{
    int iArgument1 = lua_type ( luaVM, 1 );
    int iArgument2 = lua_type ( luaVM, 2 );
    int iArgument3 = lua_type ( luaVM, 3 );
    int iArgument4 = lua_type ( luaVM, 4 );
    int iArgument5 = lua_type ( luaVM, 5 );
    int iArgument6 = lua_type ( luaVM, 6 );
    if ( ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING ) &&
        ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
        ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) &&
        ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) &&
        ( iArgument5 == LUA_TNUMBER || iArgument5 == LUA_TSTRING ) &&
        ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING ) )
    {
        CVector vecStart ( static_cast < float > ( lua_tonumber ( luaVM, 1 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 2 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 3 ) ) );
        CVector vecEnd (   static_cast < float > ( lua_tonumber ( luaVM, 4 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 5 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 6 ) ) );

        bool bCheckBuildings = true, bCheckVehicles = true, bCheckPeds = true, bCheckObjects = true, bCheckDummies = true, bSeeThroughStuff = false, bIgnoreSomeObjectsForCamera = false;
        CEntity* pIgnoredEntity = NULL;

        if ( lua_type ( luaVM, 7 ) == LUA_TBOOLEAN )
        {
            bCheckBuildings = ( lua_toboolean ( luaVM, 7 ) ) ? true:false;
            if ( lua_type ( luaVM, 8 ) == LUA_TBOOLEAN )
            {
                bCheckVehicles = ( lua_toboolean ( luaVM, 8 ) ) ? true:false;
                if ( lua_type ( luaVM, 9 ) == LUA_TBOOLEAN )
                {
                    bCheckPeds = ( lua_toboolean ( luaVM, 9 ) ) ? true:false;
                    if ( lua_type ( luaVM, 10 ) == LUA_TBOOLEAN )
                    {
                        bCheckObjects = ( lua_toboolean ( luaVM, 10 ) ) ? true:false;
                        if ( lua_type ( luaVM, 11 ) == LUA_TBOOLEAN )
                        {
                            bCheckDummies = ( lua_toboolean ( luaVM, 11 ) ) ? true:false;
                            if ( lua_type ( luaVM, 12 ) == LUA_TBOOLEAN )
                            {
                                bSeeThroughStuff = ( lua_toboolean ( luaVM, 12 ) ) ? true:false;
                                if ( lua_type ( luaVM, 13 ) == LUA_TBOOLEAN )
                                {
                                    bIgnoreSomeObjectsForCamera = ( lua_toboolean ( luaVM, 13 ) ) ? true:false;
                                    if ( lua_type ( luaVM, 14 ) == LUA_TLIGHTUSERDATA )
                                    {
                                        CClientEntity* pEntity = lua_toelement ( luaVM, 14 );
                                        if ( pEntity )
                                        {
                                            switch ( pEntity->GetType () )
                                            {
                                            case CCLIENTPED:
                                            case CCLIENTPLAYER:
                                                pIgnoredEntity = static_cast < CClientPed* > ( pEntity )->GetGamePlayer ();
                                                break;
                                            case CCLIENTVEHICLE:
                                                pIgnoredEntity = static_cast < CClientVehicle* > ( pEntity )->GetGameVehicle ();
                                                break;
                                            case CCLIENTOBJECT:
                                                pIgnoredEntity = static_cast < CClientObject* > ( pEntity )->GetGameObject ();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        bool bIsClear;
        if ( CStaticFunctionDefinitions::IsLineOfSightClear ( vecStart, vecEnd, bIsClear, bCheckBuildings, bCheckVehicles, bCheckPeds, bCheckObjects, bCheckDummies, bSeeThroughStuff, bIgnoreSomeObjectsForCamera, pIgnoredEntity ) )
        {        
            lua_pushboolean ( luaVM, bIsClear );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "isLineOfSightClear" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #21
0
// Don't whine bout my gotos, lua api is a bitch, i had to!
int CLuaClassDefs::Index ( lua_State* luaVM )
{
    CElement* pElement = lua_toelement ( luaVM, 1 );

    if ( pElement )
    {
        lua_pushvalue ( luaVM, lua_upvalueindex ( 1 ) );

        // First we look for a function
        lua_pushstring ( luaVM, "__class" );
        lua_rawget ( luaVM, -2 );

        if ( !lua_istable ( luaVM, -1 ) )
        {
            lua_remove ( luaVM, -2 );
            goto searchparent;
        }

        lua_pushvalue ( luaVM, 2 );
        lua_rawget ( luaVM, -2 );
        lua_remove ( luaVM, -2 );

        if ( lua_isfunction ( luaVM, -1 ) )
        { // Found the function, clean up and return
            lua_remove ( luaVM, -2 );
            return 1;
        }
        lua_pop ( luaVM, 1 );

        // Function not found, look for property
        lua_pushstring ( luaVM, "__get" );
        lua_rawget ( luaVM, -2 );

        if ( !lua_istable ( luaVM, -1 ) )
        {
            lua_remove ( luaVM, -2 );
            goto searchparent;
        }

        lua_pushvalue ( luaVM, 2 );
        lua_rawget ( luaVM, -2 );
        lua_remove ( luaVM, -2 );

        if ( lua_isfunction ( luaVM, -1 ) )
        { // Found the property,
            lua_remove ( luaVM, -2 );

            lua_pushvalue ( luaVM, 1 );
            lua_call ( luaVM, 1, 1 );

            return 1;
        }
        lua_pop ( luaVM, 1 );

searchparent:
        lua_pushstring ( luaVM, "__parent" );
        lua_rawget ( luaVM, -2 );
        if ( lua_istable ( luaVM, -1 ) )
        {
            lua_pushstring ( luaVM, "__index" );
            lua_rawget ( luaVM, -2 );
            if ( lua_isfunction ( luaVM, -1 ) )
            {
                lua_pushvalue ( luaVM, 1 );
                lua_pushvalue ( luaVM, 2 );

                lua_call ( luaVM, 2, 1 );

                lua_replace ( luaVM, -2 );
                lua_pop ( luaVM, 2 );
                return 1;
            }
            lua_pop ( luaVM, 1 );
        }
        lua_pop ( luaVM, 2 );
    }

    lua_pushnil ( luaVM );
    return 1;
}
int CLuaFunctionDefs::CreateProjectile ( lua_State* luaVM )
{
    if ( ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) ) &&
        ( lua_istype ( luaVM, 2, LUA_TNUMBER ) || lua_istype ( luaVM, 2, LUA_TSTRING ) ) )
    {
        CClientEntity* pCreator = lua_toelement ( luaVM, 1 );
        if ( pCreator )
        {
            unsigned char ucWeaponType = static_cast < unsigned char > ( lua_tonumber ( luaVM, 2 ) );
            CVector vecOrigin;
            pCreator->GetPosition ( vecOrigin );
            float fForce = 1.0f;
            CClientEntity* pTarget = NULL;
            CVector *pvecRotation = NULL, *pvecMoveSpeed = NULL;
            unsigned short usModel = 0;
            if ( ( lua_istype ( luaVM, 3, LUA_TNUMBER ) || lua_istype ( luaVM, 3, LUA_TSTRING ) ) &&
                ( lua_istype ( luaVM, 4, LUA_TNUMBER ) || lua_istype ( luaVM, 4, LUA_TSTRING ) ) &&
                ( lua_istype ( luaVM, 5, LUA_TNUMBER ) || lua_istype ( luaVM, 5, LUA_TSTRING ) ) )
            {
                vecOrigin = CVector ( static_cast < float > ( lua_tonumber ( luaVM, 3 ) ),
                    static_cast < float > ( lua_tonumber ( luaVM, 4 ) ),
                    static_cast < float > ( lua_tonumber ( luaVM, 5 ) ) );

                if ( lua_istype ( luaVM, 6, LUA_TNUMBER ) || lua_istype ( luaVM, 6, LUA_TSTRING ) )
                {
                    fForce = static_cast < float > ( lua_tonumber ( luaVM, 6 ) );

                    if ( lua_istype ( luaVM, 7, LUA_TLIGHTUSERDATA ) )
                    {
                        CClientEntity* pTemp = lua_toelement ( luaVM, 7 );
                        if ( pTemp )
                        {
                            pTarget = pTemp;
                        }
                        else
                            m_pScriptDebugging->LogBadPointer ( luaVM, "createProjectile", "element", 7 );
                    }

                    int iArgument8 = lua_type ( luaVM, 8 );
                    int iArgument9 = lua_type ( luaVM, 9 );
                    int iArgument10 = lua_type ( luaVM, 10 );
                    if ( ( iArgument8 == LUA_TSTRING || iArgument8 == LUA_TNUMBER ) &&
                        ( iArgument9 == LUA_TSTRING || iArgument9 == LUA_TNUMBER ) &&
                        ( iArgument10 == LUA_TSTRING || iArgument10 == LUA_TNUMBER ) )
                    {
                        pvecRotation = new CVector ( static_cast < float > ( lua_tonumber ( luaVM, 8 ) ),
                            static_cast < float > ( lua_tonumber ( luaVM, 9 ) ),
                            static_cast < float > ( lua_tonumber ( luaVM, 10 ) ) );
                    }
                    int iArgument11 = lua_type ( luaVM, 11 );
                    int iArgument12 = lua_type ( luaVM, 12 );
                    int iArgument13 = lua_type ( luaVM, 13 );
                    if ( ( iArgument11 == LUA_TSTRING || iArgument11 == LUA_TNUMBER ) &&
                        ( iArgument12 == LUA_TSTRING || iArgument12 == LUA_TNUMBER ) &&
                        ( iArgument13 == LUA_TSTRING || iArgument13 == LUA_TNUMBER ) )
                    {
                        pvecMoveSpeed = new CVector ( static_cast < float > ( lua_tonumber ( luaVM, 11 ) ),
                            static_cast < float > ( lua_tonumber ( luaVM, 12 ) ),
                            static_cast < float > ( lua_tonumber ( luaVM, 13 ) ) );

                        int iArgument14 = lua_type ( luaVM, 14 );
                        if ( iArgument14 == LUA_TSTRING || iArgument14 == LUA_TNUMBER )
                        {
                            usModel = static_cast < unsigned short > ( lua_tonumber ( luaVM, 14 ) );
                        }
                    }
                }
            }

            CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
            if ( pLuaMain )
            {
                CResource * pResource = pLuaMain->GetResource();
                if ( pResource )
                {
                    CClientProjectile * pProjectile = CStaticFunctionDefinitions::CreateProjectile ( *pResource, *pCreator, ucWeaponType, vecOrigin, fForce, pTarget, pvecRotation, pvecMoveSpeed, usModel );
                    if ( pProjectile )
                    {
                        CElementGroup * pGroup = pResource->GetElementGroup();
                        if ( pGroup )
                        {
                            pGroup->Add ( ( CClientEntity* ) pProjectile );
                        }

                        if ( pvecRotation )
                        {
                            delete pvecRotation;
                            pvecRotation = NULL;
                        }
                        if ( pvecMoveSpeed )
                        {
                            delete pvecMoveSpeed;
                            pvecMoveSpeed = NULL;
                        }

                        lua_pushelement ( luaVM, pProjectile );
                        return 1;
                    }
                }
            }
            if ( pvecRotation )
            {
                delete pvecRotation;
                pvecRotation = NULL;
            }
            if ( pvecMoveSpeed )
            {
                delete pvecMoveSpeed;
                pvecMoveSpeed = NULL;
            }
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "createProjectile", "element", 1 );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "createProjectile" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #23
0
int CLuaFunctionDefs::ProcessLineOfSight ( lua_State * luaVM )
{
    int iArgument1 = lua_type ( luaVM, 1 );
    int iArgument2 = lua_type ( luaVM, 2 );
    int iArgument3 = lua_type ( luaVM, 3 );
    int iArgument4 = lua_type ( luaVM, 4 );
    int iArgument5 = lua_type ( luaVM, 5 );
    int iArgument6 = lua_type ( luaVM, 6 );
    if ( ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING ) &&
        ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
        ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) &&
        ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) &&
        ( iArgument5 == LUA_TNUMBER || iArgument5 == LUA_TSTRING ) &&
        ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING ) )
    {
        CVector vecStart ( static_cast < float > ( lua_tonumber ( luaVM, 1 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 2 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 3 ) ) );
        CVector vecEnd (   static_cast < float > ( lua_tonumber ( luaVM, 4 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 5 ) ),
            static_cast < float > ( lua_tonumber ( luaVM, 6 ) ) );

        CColPoint* pColPoint = NULL;
        CClientEntity* pColEntity = NULL;
        bool bCheckBuildings = true, bCheckVehicles = true, bCheckPeds = true, bCheckObjects = true, bCheckDummies = true, bSeeThroughStuff = false, bIgnoreSomeObjectsForCamera = false, bShootThroughStuff = false;
        CEntity* pIgnoredEntity = NULL;

        if ( lua_type ( luaVM, 7 ) == LUA_TBOOLEAN )
        {
            bCheckBuildings = ( lua_toboolean ( luaVM, 7 ) ) ? true:false;
            if ( lua_type ( luaVM, 8 ) == LUA_TBOOLEAN )
            {
                bCheckVehicles = ( lua_toboolean ( luaVM, 8 ) ) ? true:false;
                if ( lua_type ( luaVM, 9 ) == LUA_TBOOLEAN )
                {
                    bCheckPeds = ( lua_toboolean ( luaVM, 9 ) ) ? true:false;
                    if ( lua_type ( luaVM, 10 ) == LUA_TBOOLEAN )
                    {
                        bCheckObjects = ( lua_toboolean ( luaVM, 10 ) ) ? true:false;
                        if ( lua_type ( luaVM, 11 ) == LUA_TBOOLEAN )
                        {
                            bCheckDummies = ( lua_toboolean ( luaVM, 11 ) ) ? true:false;
                            if ( lua_type ( luaVM, 12 ) == LUA_TBOOLEAN )
                            {
                                bSeeThroughStuff = ( lua_toboolean ( luaVM, 12 ) ) ? true:false;
                                if ( lua_type ( luaVM, 13 ) == LUA_TBOOLEAN )
                                {
                                    bIgnoreSomeObjectsForCamera = ( lua_toboolean ( luaVM, 13 ) ) ? true:false;
                                    if ( lua_type ( luaVM, 14 ) == LUA_TBOOLEAN )
                                    {
                                        bShootThroughStuff = ( lua_toboolean ( luaVM, 14 ) ) ? true:false;

                                        if ( lua_type ( luaVM, 15 ) == LUA_TLIGHTUSERDATA )
                                        {
                                            CClientEntity* pEntity = lua_toelement ( luaVM, 15 );
                                            if ( pEntity )
                                            {
                                                switch ( pEntity->GetType () )
                                                {
                                                case CCLIENTPED:
                                                case CCLIENTPLAYER:
                                                    pIgnoredEntity = static_cast < CClientPed* > ( pEntity )->GetGamePlayer ();
                                                    break;
                                                case CCLIENTVEHICLE:
                                                    pIgnoredEntity = static_cast < CClientVehicle* > ( pEntity )->GetGameVehicle ();
                                                    break;
                                                case CCLIENTOBJECT:
                                                    pIgnoredEntity = static_cast < CClientObject* > ( pEntity )->GetGameObject ();
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        bool bCollision;
        if ( CStaticFunctionDefinitions::ProcessLineOfSight ( vecStart, vecEnd, bCollision, &pColPoint, &pColEntity, bCheckBuildings, bCheckVehicles, bCheckPeds, bCheckObjects, bCheckDummies, bSeeThroughStuff, bIgnoreSomeObjectsForCamera, bShootThroughStuff, pIgnoredEntity ) )
        {    
            // Got a collision?
            CVector vecColPosition;
            if ( pColPoint )
            {
                // Get the collision position
                vecColPosition = *pColPoint->GetPosition ();

                // Delete the colpoint
                pColPoint->Destroy ();
            }

            lua_pushboolean ( luaVM, bCollision );
            if ( bCollision )
            {
                lua_pushnumber ( luaVM, vecColPosition.fX );
                lua_pushnumber ( luaVM, vecColPosition.fY );
                lua_pushnumber ( luaVM, vecColPosition.fZ );
                if ( pColEntity )
                    lua_pushelement ( luaVM, pColEntity );
                else
                    lua_pushnil ( luaVM );
                return 5;
            }
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "processLineOfSight" );

    lua_pushboolean ( luaVM, false );
    return 1;
}