Jump to content

Recommended Posts

I made this:

-- All other functions and GUI creation.
-- [...]
-- Created button called "fbumper".

local function setFBumper()
		local theVeh7 = getPedOccupiedVehicle(localPlayer)
		if theVeh7 then
			setVehicleComponentVisible(theVeh7, "bump_front_dummy", false)
		end
	end
	addEventHandler("onClientGUIClick", fbumper, setFBumper, false)

-- Everything else...

It works. Then I wanted to have the button switch between true to false when clicked. Something like:

local function setFBumper()
		local theVeh7 = getPedOccupiedVehicle(localPlayer)
		if theVeh7 then
			setVehicleComponentVisible(theVeh7, "bump_front_dummy", false)
    	elseif getVehicleComponentVisible(theVeh7) == "false" then
    		setVehicleComponentVisible(theVeh7, "bump_front_dummy", true)
		end
	end
	addEventHandler("onClientGUIClick", fbumper, setFBumper, false)
	
	guiSetVisible (vehmod, false)

It doesn't work correctly. It sets it invisible, but it doesn't return the state to visible.

I also thought about using the setVehicleComponentVisible (not setVehicleComponentVisible) to make it a little bit more compact. I'm using a setEngineState script to help myself, but I don't know how to use it with these arguments.
DB 3 throws nothing.

What am I doing wrong?

Link to comment
local function setFBumper()
  local theVeh7 = getPedOccupiedVehicle(localPlayer)
  if theVeh7 then
    local alreadyVisible = getVehicleComponentVisible(theVeh7, "bump_front_dummy")
    setVehicleComponentVisible(theVeh7, "bump_front_dummy", not alreadyVisible)
  end
end
addEventHandler("onClientGUIClick", fbumper, setFBumper, false)

guiSetVisible (vehmod, false)

fixed & optimized.

Explanation:

  • you have to give the component name as second argument to getVehicleComponentVisible for it to work
  • the return value of getVehicleComponent is either true or false, not "true" not "false"
Edited by The_GTA
  • Thanks 1
Link to comment

I didn't know you could assign more than 1 argument when doing a

local whatev = getSomething(argument 1, argument 2...)

I know now. Thanks!

So what you're doing is assigning the function 'getVehicleComponentVisible' to the string 'alreadyVisible'. Additionally, you're also saying that 'alreadyVisible' includes the dummy of the car that the localPlayer is driving. That way, when you say not alreadyVisible, you're inverting the value of the visibility state, correct?
Which is the very first command that tells the system the boolean of the visibility? For example:

If you constantly multiply a number by 1 and -1, alternating between them, you need to have a first number so you know the ending result. Otherwise, you'll never figure if the ending result is positive or negative

x * 1 = x ---> x * -1 = -x ---> x * 1 = x ---> x * -1 = -x

But if I tell you that x = 2, you'll know the ending result.
Taking this concept to this script, how does the system figure out the initial state of the dummy?

 

 

Link to comment
2 minutes ago, Moony said:

So what you're doing is assigning the function 'getVehicleComponentVisible' to the string 'alreadyVisible'. Additionally, you're also saying that 'alreadyVisible' includes the dummy of the car that the localPlayer is driving. That way, when you say not alreadyVisible, you're inverting the value of the visibility state, correct?
Which is the very first command that tells the system the boolean of the visibility?

Yes, yes, yes and yes.

3 minutes ago, Moony said:

Taking this concept to this script, how does the system figure out the initial state of the dummy?

The game provides the starting value, which is always true. But you cannot rely on any value because there are other scripts that may modify the value.

  • Thanks 1
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...