Jump to content

GUI problem ( GridList and Window )


|H|TiTanium

Recommended Posts

Basically I tried many times and probably I'm doing it wrong, but I didn't know how do I create a if condition inside another one, so I tried and tried and nothing works...

I need elements to get checked using isElement and then they will get destroyed, because I'm getting a debug message.

When you change from a row to another the previous Ped in preview should get destroyed ( it's happening correctly ), but before getting destroyed it should get checked using isElement, but it doesn't work \;

Please can you show at least an example showing how do I add an isElement to check Elements and stop the debugs message ( Bad 'element' pointer blablabla )

function gridClick ( state, absoluteX, absoluteY) 
        if isElement(panteraprev) and isElement(pastorprev) then 
        destroyElement =true 
end 
        local campos = guiGridListGetItemText ( myGridList, guiGridListGetSelectedItem ( myGridList ), 1 ) 
        if campos == "Tiger" then 
        tigreprev = createPed( 40, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Panther" then 
        panteraprev = createPed( 44, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(tigreprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Dog German Shepherd" then 
        pastorprev = createPed( 46, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(tigreprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Dog Rottweiler" then 
        rotprev = createPed( 49, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(tigreprev) 
        destroyElement(loboprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Wolf" then 
        loboprev = createPed( 47, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(tigreprev) 
        destroyElement(foxprev) 
    end 
        if campos == "Fox" then 
        foxprev = createPed( 48, 2144.87671, -1177.68799, 23.82031 ) 
        destroyElement(panteraprev) 
        destroyElement(pastorprev) 
        destroyElement(rotprev) 
        destroyElement(loboprev) 
        destroyElement(tigreprev) 
    end 
end 
addEventHandler ("onClientGUIClick", myGridList, gridClick) 

Edited by Guest
Link to comment

Here's an example while I look through you code;

addEventHandler("onMarkerHit", marker, 
    function ( hitElement ) 
        if ( isElement ( hitPlayer ) ) then 
            setElementHealth ( hitPlayer, 0 ); 
        end 
    end 
); 

edit;

I changed the first part of your code to this; try doing it with the rest!

function gridClick ( state, absoluteX, absoluteY) 
        if isElement(panteraprev) and isElement(pastorprev) then 
            destroyElement(panteraprev); 
            destroyElement(pastorprev); 
        end 
        local campos = guiGridListGetItemText ( myGridList, guiGridListGetSelectedItem ( myGridList ), 1 ) 
        if campos == "Tiger" then 
            tigreprev = createPed( 40, 2144.87671, -1177.68799, 23.82031 ) 
            if ( isElement ( panteraprev ) ) then destroyElement(panteraprev); end 
            if ( isElement ( pastorprev ) ) then destroyElement(pastorprev); end 
            if ( isElement ( rotprev ) ) then destroyElement(rotprev); end 
            if ( isElement ( loboprev ) ) then destroyElement(loboprev); end 
            if ( isElement ( foxprev ) ) then destroyElement(foxprev); end 
        end 

Link to comment

Well, it works if the player clicks twice fastly, but it doesn't work if the player clicks once on the row, wait sometime and then click again on the row, it keeps bugged and the Ped is not deleted.

Also, I don't know why, but if the Player clicks outside the GridList ( any area, except labels ) the Ped is created, instead of getting none return. Example : I'm looking at GUI, then I click on title of myWindow, the Ped keeps being created while I'm clicking on title of the window.

function fechadaGUI ( ) 
        guiGridListSetSelectedItem (myGridList, 0, 0) 
            if ( isElement ( foxprev ) ) then destroyElement(foxprev); end 
            if ( isElement ( panteraprev ) ) then destroyElement(panteraprev); end 
            if ( isElement ( pastorprev ) ) then destroyElement(pastorprev); end 
            if ( isElement ( rotprev ) ) then destroyElement(rotprev); end 
            if ( isElement ( loboprev ) ) then destroyElement(loboprev); end 
            if ( isElement ( tigreprev ) ) then destroyElement(tigreprev); end 
end 
addEventHandler( "onClientGUIDoubleClick", myGridList, fechadaGUI, false ) 

Link to comment

Try this.

local lastRow = nil 
  
function gridClick ( state, absoluteX, absoluteY) 
        if isElement(panteraprev) and isElement(pastorprev) then 
            destroyElement(panteraprev); 
            destroyElement(pastorprev); 
        end 
        local row = guiGridListGetSelectedItem ( myGridList ) 
        if ( lastRow and lastRow == row ) then 
            return 
        end 
  
        local campos = guiGridListGetItemText ( myGridList, row, 1 ) 
        lastRow = row 
        if campos == "Tiger" then 
            tigreprev = createPed( 40, 2144.87671, -1177.68799, 23.82031 ) 
            if ( isElement ( panteraprev ) ) then destroyElement(panteraprev); end 
            if ( isElement ( pastorprev ) ) then destroyElement(pastorprev); end 
            if ( isElement ( rotprev ) ) then destroyElement(rotprev); end 
            if ( isElement ( loboprev ) ) then destroyElement(loboprev); end 
            if ( isElement ( foxprev ) ) then destroyElement(foxprev); end 
        end 

Link to comment

Perfectly !!! Is there any tutorial/wiki for those nil and return?, I've already tried to find return on mta wiki and got none, also mta wiki is limited and it doesn't show all options we do have, like guiGridListGetSelectedItem, I never thought about using it that way, thought I was supposed to use it with guiGridListGetItemText . I'm not that good at these, and I love scripting, so I wish to know more and stop asking for help and start helping someone else. Thank you again

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...