Jump to content

Double clicking


Ivo1313

Recommended Posts

Hello guys, im scripting a menu for buying car fixes, it's working just well but everytime i hit the buy button, the game registers my click as 2+ clicks, what i can do about it? Here is the function: (this one is triggered by a client event)

function arrumar(player)
  if getPlayerMoney(client) >= 1500 then
    local theVehicle = getPedOccupiedVehicle(client)
    if theVehicle and getVehicleController (theVehicle) == client then
      fixVehicle(theVehicle)
      takePlayerMoney(client, 1500)
      outputChatBox("Um mecanico arrumou seu carro para você!", client, 0,255,0)
    else
      outputChatBox("Você não está em um veículo!!", client, 255,0,0)
    end
  else
    outputChatBox("Você não tem dinheiro suficiente para esse serviço", client, 255,0,0)
  end
end
addEvent("arrumar", true)
addEventHandler("arrumar", root, arrumar)

 

Link to comment

 

16 hours ago, Ivo1313 said:

Hello guys, im scripting a menu for buying car fixes, it's working just well but everytime i hit the buy button, the game registers my click as 2+ clicks, what i can do about it? Here is the function: (this one is triggered by a client event)


function arrumar(player)
  if getPlayerMoney(client) >= 1500 then
    local theVehicle = getPedOccupiedVehicle(client)
    if theVehicle and getVehicleController (theVehicle) == client then
      fixVehicle(theVehicle)
      takePlayerMoney(client, 1500)
      outputChatBox("Um mecanico arrumou seu carro para você!", client, 0,255,0)
    else
      outputChatBox("Você não está em um veículo!!", client, 255,0,0)
    end
  else
    outputChatBox("Você não tem dinheiro suficiente para esse serviço", client, 255,0,0)
  end
end
addEvent("arrumar", true)
addEventHandler("arrumar", root, arrumar)

 

show your client side code

 
Link to comment
  • Moderators

It is possible because the event triggered on button press and release.

Trigger event only on button release.

addEventHandler("onClientClick", root, function(button, state)
    if button == "left" then -- if clicked with left button
        if state == "up" then -- if button released
            -- trigger
        end
    end
end)

 

  • Like 1
Link to comment
  • Moderators
17 hours ago, Ivo1313 said:

what i can do about it?

Not create and attach the eventHandler to a new function.

Use global named functions that can be attached and detached when it is no longer required.

You currently created something you might consider similar to a memory leak.

  • Thanks 1
Link to comment
On 16/01/2020 at 12:26, stPatrick said:

It is possible because the event triggered on button press and release.

Trigger event only on button release.


addEventHandler("onClientClick", root, function(button, state)
    if button == "left" then -- if clicked with left button
        if state == "up" then -- if button released
            -- trigger
        end
    end
end)

 

Hey, thx, this worked for me

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