Jump to content

help camera spawn


Jacobob14

Recommended Posts

as I make the camera moves quickly to the next spawn and do not get black

  
local selectedRow = -1;
local selectedGroup = -1;
previousClass = -1;
 
local weaponIcons = { };
local weaponLabels = { };
local weaponAmmoLabels = { };
 
 
function createGroupSelectionWnd( )
    local selectionPos = { gridList:Position( false ) };
    groupsGridList = GridList:Create(
        screenSize[ 1 ] - gridList:Size( false ) - 4,
        screenSize[ 2 ] - 425,
        180, 200,
        false );
    groupsGridList: Alpha( .9 );
    groupsGridList: AddColumn( "Seleccionar Modo Campaña", .8 );
    groupsGridList: SortingEnabled( false );
    for _, group in ipairs( classGroups ) do
        groupsGridList:AddRow( false, group.name );
    end
    groupsGridList:AddOnClick( groupSelected );
    groupsGridList:Visible( false );
end
 
function groupSelected( )
    descrGridList:Visible( false );
    weaponsGrid:Visible( false );
    selectedGroup = groupsGridList:SelectedItem( );
    if selectedGroup ~= -1 then
        populateClassesGrid( classGroups[ selectedGroup + 1 ].classes );
    else
        gridList:Clear( );
    end
    previousClass = -1;
end
 
 
 
function createClassSelectionWnd( )
    gridList = GridList:Create(
        screenSize[ 1 ] - 184,
        screenSize[ 2 ] -225,
        180, 220,
        false );
    gridList:AddColumn( "seleccionar Protagonista:", .85 );
    gridList:Alpha( .9 );
    gridList:SortingEnabled( false );
    gridList:AddOnClick( classSelected );
    gridList:Visible( false );
   
    local gridSize = { gridList:Size( false ) };
    spawnBtn = Button:Create(
        screenSize[ 1 ] - gridList:Size( false ) - 255,
        screenSize[ 2 ] - 45,
        115, 40,
        "SPAWN", false
    );
    spawnBtn:Font( "default-bold-small" );
    spawnBtn:ColorOnHover( "FF0000FF" );
    spawnBtn:AddOnClick( requestSpawn );
    spawnBtn:Visible( false );
end
 
function populateClassesGrid( classes )
    gridList:Clear( );
   
    for classIndex, class in pairs( classes ) do
        gridList:AddRow( true, class.name );
        for skinIndex, skin in ipairs( class.skinMngr:GetSkins( ) ) do
            local row = gridList:AddRow( false, skin.name );
            gridList:ItemData( row, 1, tostring( classIndex ) .."," .. tostring( skinIndex ) );
        end
    end
   
end
 
 
function classSelected ( )
    selectedRow = gridList:SelectedItem( );
    if selectedRow ~= -1 then
         playSound( "Menu.mp3", false )
        local data = split( gridList:ItemData( selectedRow, 1 ), string.byte(',') );
        local classIndex = tonumber( data[ 1 ] );
        local skinIndex = tonumber( data[ 2 ] );
        local class = classGroups[ selectedGroup + 1 ].classes[ classIndex ];
        local skin = classGroups[ selectedGroup + 1 ].classes[ classIndex ].skinMngr.skins[ skinIndex ];
        enableSpawn( false );
        if previousClass ~= classIndex then
            resizeWeaponsWnd( class.weaponMngr );
            fadeCamera( false );
            setTimer( moveCameraTo, 1000, 1, class, skin );
        else
            teleportTempPed( skin );
        end
        previousClass = classIndex;
       
        local classDescr = class.info;
        if classDescr then
            descrLabel:Text( classDescr );
            descrGridList:Visible( true );
        else
            descrGridList:Visible( false );
            weaponsGrid:Visible( false );
        end
    else
        descrGridList:Visible( false );
        weaponsGrid:Visible( false );
    end
end
 
function requestSpawn( )
    selectedRow = gridList:SelectedItem();
    if ( selectedGroup ~= -1 ) and ( selectedRow ~= -1 ) then
         playSound( "Menu.mp3", false )
        local data = split( gridList:ItemData( selectedRow, 1 ), string.byte(',') );
        local classIndex = tonumber( data[ 1 ] );
        local skinIndex = tonumber( data[ 2 ] );
        local class = classGroups[ selectedGroup + 1 ].classes[ classIndex ];
        local skin = classGroups[ selectedGroup + 1 ].classes[ classIndex ].skinMngr.skins[ skinIndex ];
        fadeCamera( false );
        setTimer( triggerServerEvent, 1000, 1, "spawn_clientRequestSpawn", g_root, selectedGroup + 1, classIndex, skinIndex );
    end
end
 
function moveCameraTo( class, skin )
    local camX, camY, camZ = class.cameraMngr.pos.x, class.cameraMngr.pos.y, class.cameraMngr.pos.z;
    local lookAtX, lookAtY, lookAtZ = class.cameraMngr.lookAt.x, class.cameraMngr.lookAt.y, class.cameraMngr.lookAt.z;
    fadeCamera( true );
    --outputDebugString( "fading camera in" );
    setCameraMatrix( camX, camY, camZ, lookAtX, lookAtY, lookAtZ );
    setTimer( teleportTempPed, 500, 1, skin );
end
 
local losTests = 0; -- line of sight
function teleportTempPed( skin )
    local x, y, z = getWorldFromScreenPosition( screenSize[ 1 ] - gridList:Size(false) -295, ( screenSize[ 2 ]) -250, 5 )
    local cX, cY, cZ;
        cX, cY, cZ = getCameraMatrix();
    if not tempPed then
        createTempPed( skin.modelId );
    else
        setElementPosition( g_ground, x, y, z - 1.02 );
        setElementPosition( tempPed, x, y, z );
        setElementModel( tempPed, skin.modelId );
        x, y, z = getWorldFromScreenPosition( screenSize[ 1 ] - gridList:Size(false) -295, ( screenSize[ 2 ]) -250, 5 )
    end
    if not processLineOfSight( cX, cY, cZ, x, y, z ) then
        losTests = losTests + 1;
        if losTests < 3 then
            setTimer( teleportTempPed, 300, 1, skin );
            return
        else
            destroyElement( g_ground );
            destroyElement( tempPed );
            tempPed = nil;
            createTempPed( skin.modelId );
            enableSpawn( true );
            losTests = 0;
        end
    else
        enableSpawn( true );
    end
end
 
function createClassDescriptionWnd( )
    descrGridList = GridList:Create(
        screenSize[ 1 ] - 305,
        5,
        300, 125,
        false );
    descrTitleLbl = Label:Create( 8, 5, 100, 30, "Descripcion:", false, descrGridList.gui );
    descrTitleLbl:Font( "sans" );
    descrTitleLbl:Color( 255, 0, 0 );
    descrLabel = Memo:Create( 10, 25, 280, 90, "", false, descrGridList.gui );
    descrLabel:ReadOnly( true );
    descrGridList:Alpha( 1 );
    descrGridList:Visible( false );
end
 
 
function createClassWeaponWnd( )
    local descrSize = { descrGridList:Size( false ) };
    weaponsGrid = GridList:Create(
        screenSize[ 1 ] - 1,
        descrSize[ 2 ] + 4,
        1, 1,
        false );
    weaponsGrid:Alpha( .0 );
    weaponsGrid:Visible( false );
end
 
 
function enableSpawn( enable )
    bringSpawnMenuToFront( );
    gridList:Enabled( enable );
    spawnBtn:Enabled( enable );
    descrGridList:Visible( enable );
    if enable == true then
        local data = split( gridList:ItemData( selectedRow, 1 ), string.byte(',') );
        local classIndex = tonumber( data[ 1 ] );
        local skinIndex = tonumber( data[ 2 ] );
        local class = classGroups[ selectedGroup + 1 ].classes[ classIndex ];
        if class.weaponMngr:WeaponCount( ) > 0 then
            weaponsGrid:Visible( enable );
        else
            weaponsGrid:Visible( false );
        end
    end
end
 
function resizeWeaponsWnd( weaponManager )
    local minHeight = 18;
    local weapCount = weaponManager:WeaponCount( );
    local weapons = weaponManager:GetWeapons( );
    weaponsGrid:Size( 115, minHeight + ( weapCount * 40 ), false );
    if weapCount > 0 then
        for i, icon in pairs( weaponIcons ) do
            if icon and icon.gui then
                destroyElement( icon.gui );
            end
        end
        weaponIcons = nil;
        weaponIcons = { };
        for i, lbl in pairs( weaponLabels ) do
            if lbl and lbl.gui then
                destroyElement( lbl.gui );
            end
        end
        weaponLabels = nil
        weaponLabels = { };
       
        for i, weapon in ipairs( weapons ) do
            weaponIcons[ i ] = StaticImage:Create(
                10,
                ( (i-1) * 40 ) + 10,
                iconWidths[ weapon.id ],
                20,
                icons[ weapon.id ],
                false,
                weaponsGrid.gui
            );
            weaponLabels[ i ] = Label:Create( 10, ( (i-1) * 40 ) + 17, 95, 35, "\nAmmo: x" .. tostring( weapon.ammo ), false, weaponsGrid.gui );
            weaponLabels[ i ]:Font( "pricedown" );
            weaponLabels[ i ]:HorizontalAlign( "left" );
        end
        weaponsGrid:Visible( true );
    else
        weaponsGrid:Visible( false );
   
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...