Jump to content

Headlight Gui Help


jkub

Recommended Posts

Posted

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? :)

Posted

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.

Posted

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

Posted

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 );

Posted (edited)

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.

Edit: damn next time I'll read the last row as well.

Edited by Guest
Posted
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

Posted

it says userdata but I used triggerClientEvent from the server

I used an example from the wiki and altered the data to suit what I was trying to do.

Posted

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

Posted

I used outputChatBox and tostring to show what I had for clientVehicle and the three custom color values

for clientvehicle it said "userdata: 000000F4"

and for all three color values it said "false"

Posted

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)

Posted

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)

Posted

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?

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

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