Jump to content

GUI Click


Recommended Posts

hello guys, I have a panel worked fine, but there is a little problem

I have a button of Get Vehicle to spawn with it a vehicle, but I can spawn vehicle on all the window

if I want to spawn vehicle? I click on whatever place on window, and done

how to fix it only with the Get Vehicle button

Code

addEventHandler ("onClientGUIClick", GUIEditor.button[2],
function (button, state, absoluteX, absoluteYe)
 guiSetVisible(GUIEditor.window[1],false)
 showCursor(false)
end)
function trigger ()
if (guiGridListGetSelectedItem (GUIEditor.gridlist[1])) then
local car = guiGridListGetItemText (GUIEditor.gridlist[1], guiGridListGetSelectedItem (GUIEditor.gridlist[1]), 2)
if car == "" or car == nil then return end
  triggerServerEvent ("getCar", getLocalPlayer(), car)
  guiSetVisible(GUIEditor.window[1],false)
  showCursor(false)
end
end

addEventHandler ("onClientGUIClick", GUIEditor.button[1],
function (button, state, absoluteX, absoluteYe)
trigger(getLocalPlayer())
playSound ("fail.mp3")
end)

addEventHandler ("onClientGUIDoubleClick", GUIEditor.gridlist[1],
function (button, state, absoluteX, absoluteYe)
trigger(getLocalPlayer())
playSound ("fail.mp3")
end)

Help please?

Link to comment
addEventHandler ("onClientGUIClick", GUIEditor.button[1],
function (button, state, absoluteX, absoluteYe)
if source == GUIEditor.button[1] then -- you have to check if the source that got clicked is the button 
trigger(getLocalPlayer())
playSound ("fail.mp3")
end
end)

 

Link to comment
function trigger()
  local row, col = guiGridListGetSelectedItem( GUIEditor.gridlist[1] )
  if ( ( row ~= -1 ) and ( col ~= -1 ) ) then
    local car = guiGridListGetItemText( GUIEditor.gridlist[1], row, col )
    if ( ( car == "" ) or ( car == nil ) ) then return end
    triggerServerEvent( "getCar", getLocalPlayer(), car )
    guiSetVisible( GUIEditor.window[1], false )
    showCursor( false )
  end
end

addEventHandler("onClientGUIClick", GUIEditor.window[1],
  function( button, state )
	if ( source == GUIEditor.button[1] ) then
	  trigger()
	  playSound( "fail.mp3" )
	elseif ( source == GUIEditor.button[2] ) then
	  guiSetVisible( GUIEditor.window[1], false )
	  showCursor( false )
	end
  end
)

addEventHandler("onClientGUIDoubleClick", GUIEditor.window[1],
  function( button, state )
    if ( source == GUIEditor.gridlist[1] ) then
      trigger()
      playSound( "fail.mp3" )
    end
  end
)

 

Edited by Pembo
  • Like 1
Link to comment

@Pembo It's worked, no more free click, but I can not spawn it with the button 

the button won't work

help please

GUIEditor.button[1]

I forget upload this, if it can help you

for i,v in ipairs (cars) do
    local carName = getVehicleNameFromModel (v[1])
    local row = guiGridListAddRow (GUIEditor.gridlist[1])
	guiGridListSetItemText (GUIEditor.gridlist[1], row, 1, i.."", false, true)
    guiGridListSetItemText (GUIEditor.gridlist[1], row, 2, carName, false, true)
	guiGridListSetItemColor(GUIEditor.gridlist[1], row, 1, 255, 255, 255, 255)
end

 

Edited by TorNix~|nR
Link to comment
veh = {}

addEvent ("getCar", true)
addEventHandler ("getCar", getRootElement(),
function(car)
    if veh[source] and isElement( veh[source] ) then destroyElement( veh[source] ) 
	veh[source] = nil 
	end
    local carID = getVehicleModelFromName (car)
    local x,y,z = getElementPosition(source)
    local carName = getVehicleNameFromModel (carID)
    veh[source] = createVehicle(carID, x,y,z)
    setVehicleColor(veh[source], 255, 150, 0)
    warpPedIntoVehicle(source, veh[source])
         
end
)

 

Edited by TorNix~|nR
Link to comment
2 hours ago, TorNix~|nR said:

veh = {}

addEvent ("getCar", true)
addEventHandler ("getCar", getRootElement(),
function(car)
    if veh[source] and isElement( veh[source] ) then destroyElement( veh[source] ) 
	veh[source] = nil 
	end
    local carID = getVehicleModelFromName (car)
    local x,y,z = getElementPosition(source)
    local carName = getVehicleNameFromModel (carID)
    veh[source] = createVehicle(carID, x,y,z)
    setVehicleColor(veh[source], 255, 150, 0)
    warpPedIntoVehicle(source, veh[source])
         
end
)

 

What errors are displayed on the debug output?

  • Like 1
Link to comment
  • 5 years later...
On 08/04/2017 at 21:39, TorNix~|nR said:

same problem :/

Done, thanks I fix it by myself, thank you so much @Pembo

How did you manage to fix the problem? The same thing happens to me with a login panel, every time I click any part of the window it is as if I clicked any of the buttons that I have :/.

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