Diesulke Posted February 13, 2013 Share Posted February 13, 2013 (edited) Hello, My script is not working how it should work. My carcolor should change when I press the button, but when i press the button the car of all players is changing to the same color. function changeColor ( ButtonC ) if ButtonC == "left" then for i, car in ipairs( getElementsByType( "vehicle" ) ) do local number4 = guiGetText(TextC) local success = setVehicleColor(car, tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) if not success then outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) end end end end I also tried this, but then i'll get an error: Bad argument @ 'isPedInVehicle'. function changeColor ( ButtonC ) if ButtonC == "left" then local number4 = guiGetText(TextC) if isPedInVehicle( player ) then local success = setVehicleColor(getPedOccupiedVehicle ( player ), tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) if not success then outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) end end end end Any ideas? Edited February 13, 2013 by Guest Link to comment
Anderl Posted February 13, 2013 Share Posted February 13, 2013 The 1st one doesn't work because you're looping through all vehicles in the server and setting their color. The second one doesn't work because there is no "player" parameter in the event. It's just a matter of using the brain, reading the code and thinking. Link to comment
Diesulke Posted February 13, 2013 Author Share Posted February 13, 2013 Even when I add the parameter like this: function changeColor ( player, ButtonC ) if ButtonC == "left" then local number4 = guiGetText(TextC) if isPedInVehicle( player ) then local success = setVehicleColor(getPedOccupiedVehicle ( player ), tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) if not success then outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) end end end end it doesn't work. Link to comment
Guest Guest4401 Posted February 13, 2013 Share Posted February 13, 2013 function changeColor ( ButtonC ) if ButtonC == "left" then local car = getPedOccupiedVehicle(localPlayer) if car then local number4 = guiGetText(TextC) local success = setVehicleColor(car, tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) if not success then outputChatBox( "Invalid input, use numbers only!", 255, 255, 255) end end end end Link to comment
TAPL Posted February 13, 2013 Share Posted February 13, 2013 Other players won't see the color, because you setting it client side, you need to set it server side to make other players see the color too. Link to comment
Diesulke Posted February 13, 2013 Author Share Posted February 13, 2013 Could you tell me how to make it server side? Link to comment
Diesulke Posted February 13, 2013 Author Share Posted February 13, 2013 (edited) Thanks, made it work. Server: addEvent("onColorChangeRequest",true) function changeColor(num) local car = getPedOccupiedVehicle(source) if not car then outputChatBox("You are not in a car!",source,255,255,255,true) return false end setVehicleColor(car,num,num,num,num) end addEventHandler("onColorChangeRequest",getRootElement(),changeColor) Client: function changeColor ( ButtonC ) if ButtonC == "left" then local number4 = guiGetText(TextC) number4 = tonumber(number4) if not number4 then outputChatBox( "Invalid input, use numbers only!", 255, 255, 255) return false end triggerServerEvent("onColorChangeRequest",getLocalPlayer(),number4) end end Edited February 13, 2013 by Guest Link to comment
iPrestege Posted February 13, 2013 Share Posted February 13, 2013 Next Time Use Lua/Lua Tag Same This : function changeColor ( ButtonC ) if ButtonC == "left" then local number4 = guiGetText(TextC) number4 = tonumber(number4) if not number4 then outputChatBox( "Invalid input, use numbers only!", 255, 255, 255) return false end triggerServerEvent("onColorChangeRequest",getLocalPlayer(),number4) end end Link to comment
Diesulke Posted February 13, 2013 Author Share Posted February 13, 2013 Edited, thanks Link to comment
Anderl Posted February 13, 2013 Share Posted February 13, 2013 Even when I add the parameter like this: function changeColor ( player, ButtonC ) if ButtonC == "left" then local number4 = guiGetText(TextC) if isPedInVehicle( player ) then local success = setVehicleColor(getPedOccupiedVehicle ( player ), tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) if not success then outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) end end end end it doesn't work. It doesn't work because you're adding parameters that doesn't exist. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now