|H|TiTanium Posted August 14, 2013 Share Posted August 14, 2013 (edited) 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 August 14, 2013 by Guest Link to comment
tosfera Posted August 14, 2013 Share Posted August 14, 2013 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
|H|TiTanium Posted August 14, 2013 Author Share Posted August 14, 2013 (edited) I found a bug, if you click repeatedly on the same row, another Ped is created and so on, how do I disable clicking on the same row multiple times ? I tried wiki, but I don't have enough time to keep looking for, gtg soon. Edited August 14, 2013 by Guest Link to comment
tosfera Posted August 14, 2013 Share Posted August 14, 2013 I found a bug, if you click repeatedly on the same row, another Ped is created and so on, how do I disable clicking on the same row multiple times ?[bI tried wiki, but I don't have enough time to keep looking for, gtg soon. yes you can, use the onClientDoubleClick to check the row thats selected, and if its a different one. Link to comment
|H|TiTanium Posted August 14, 2013 Author Share Posted August 14, 2013 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
|H|TiTanium Posted August 14, 2013 Author Share Posted August 14, 2013 Please, anyone here Link to comment
Castillo Posted August 14, 2013 Share Posted August 14, 2013 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
|H|TiTanium Posted August 14, 2013 Author Share Posted August 14, 2013 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
Castillo Posted August 14, 2013 Share Posted August 14, 2013 That's just basic Lua stuff. http://www.lua.org/pil/4.4.html Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now