Jump to content

Headlight Gui Help


jkub

Recommended Posts

I am working on a simple Gui menu for editing headlight colors. I think my problem is that im not passing the data from the client to the server correctly.

I got buttons for common colors and I got text fields so you can make your own color.

I use guiGetText to get whatever is in the text fields.

Here is some code im using

Here is a client side method I tried

function selectCustom ()
r = guiGetText ( cstFieldRd )
g = guiGetText ( cstFieldGrn )
b = guiGetText ( cstFieldBlu )
triggerServerEvent ( "clientCustom", getRootElement(), r, g, b )
end

Here is another client method I tried

function selectCustom ()
triggerServerEvent ( "clientCustom", getRootElement(), guiGetText(cstFieldRed), guiGetText(cstFieldGreen), guiGetText(cstFieldBlue) )
end

Here is a server method I tried to recieve the data

addEventHandler ( "clientCustom", getRootElement(),
function ( red, green, blue )
	clientVeh = getPedOccupiedVehicle ( client )
setVehicleHeadLightColor ( clientVeh, red, green, blue )
end
)

I thought that when you pass data from client to server using triggerServerEvent that whatever element or argument you pass will automaticly be one of the arguments inside the function ( )

Can you help me please? :)

Link to comment

Don't you get any errors or warnings? Both of your tries are correct but from what I see, you use string in the setVehicleHeadLightColor. Use tonumber() to convert string to number. Also, make sure that your clientCustom event is added server-side.

Link to comment

Is this what you meanVV

addEventHandler ( "clientCustom", getRootElement(),
function ( red, green, blue )
	clientVeh = getPedOccupiedVehicle ( client )
setVehicleHeadLightColor ( clientVeh, tonumber(red), tonumber(green), tonumber(blue) )
end
)

Ive tried that^^ and does not work...

that way and the way I had before that gives the same error in the debug

saying that my setVehicleHeadLightColor is a bad argument

Link to comment

After you getPedOccupiedVehicle(), use outputChatBox or outputDebugString to see what clientVeh is. If it's "userdata" then it's correct. If not, then you're not in vehicle.

Then outputChatbox or outputDebugString to see what each color variable is, like: outputChatBox( "colors from client: ".. red ..", ".. green ..", ".. blue );

Link to comment
Also you haven't told us what the
that way and the way I had before that gives the same error in the debug
error is.
that way and the way I had before that gives the same error in the debug

saying that my setVehicleHeadLightColor is a bad argument

Link to comment

You need to debug it. outputDebugString or outputChatbox, for everything that may be causing these warnings. If you get "bar argument" for any of these 2 functions, use tostring() function to convert variables to string. As you get "attempt to concatenate number values" it means you try to concatenate number with string, like this: "this is string which wants number: " .. 123 . As I said, debug every variable (output them to chatbox or debug window).

Link to comment

So do you know which arguments are bad now? As I said, "userdata" is OK but the colours are not. Before you send the colour values to the server (triggerServerEvent) make sure the values are numbers (in the client-side script) with the same method (tostring() and outputChatBox)

Link to comment

if we look at the wiki page for guiGetText we can see this for the return values:

Returns a string containing the requested element's text, or false if the gui element passed to the function is invalid.

so this must mean that you are passing an invalid gui element

make sure cstFieldRd, cstFieldGrn and cstFieldBlu all exist (or that you havent just mistyped the variable names)

Link to comment

Everything is wrote down correct no typos. But 50p >> When I made this I did with the help of gui-classes. I used the :AddTextBox custom function made for it. Some odd reason when I replaced that function with the original function guiCreateEdit... It worked. Is there a special way to make it work using gui-classes?

Link to comment
Everything is wrote down correct no typos. But 50p >> When I made this I did with the help of gui-classes. I used the :AddTextBox custom function made for it. Some odd reason when I replaced that function with the original function guiCreateEdit... It worked. Is there a special way to make it work using gui-classes?

You can use shared member functions. That is https://wiki.multitheftauto.com/index.ph ... ll_classes Use :Text() to get the text form the text box, label, window, etc.

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