DeiwnEdits Posted February 8, 2019 Share Posted February 8, 2019 Hi Guys, I ask question. I have car color change script but I convert headlights color change script How ? I giving code. ------------------------------------------------------------------------------------------------------------------------------------ addEventHandler("onClientClick", root, function(b, s) if gui.window.visible == true then if b == "left" and s == "down" then x, y = guiGetPosition(gui.window, false) if cursorPosition(x + 16, y + 32, 256, 256) then BLANK_1_STATE = true end if cursorPosition(x + 288, y + 32, 32, 256) then BLANK_2_STATE = true end elseif b == "left" and s == "up" then x, y = guiGetPosition(gui.window, false) if cursorPosition(x + 16, y + 32, 256, 256) then BLANK_1_STATE = false else BLANK_1_STATE = false BLANK_2_STATE = false end if cursorPosition(x + 288, y + 32, 32, 256) then BLANK_2_STATE = false else BLANK_1_STATE = false BLANK_2_STATE = false end end end end) ------------------------------------------------------------------------------------------------------------------------------------ addEventHandler("onClientMouseMove", root, function(x, y) if gui.window.visible == true then if gui.tabpanel:getSelectedTab() == gui.tab_Color then y = y - 15 local gx,gy = guiGetPosition(gui.window, false) if BLANK_1_STATE == true then local offsetx, offsety = x - (gx + 16), y - (gy + 32) color.s = offsetx/255 color.v = (255-offsety)/255 if color.s >= 0.98 then color.s = 0.98 end if color.v >= 0.95 then color.v = 0.95 end if color.s <= 0 then color.s = 0 end if color.v <= 0 then color.v = 0 end end if BLANK_2_STATE == true then local offset = y - (gy + 32) color.h = (256-offset)/256 if color.h >= 0.98 then color.h = 0.98 end if color.h <= 0 then color.h = 0 end color.huecurrent = tocolor(hsv2rgb(color.h, 1, 1)) end if not localPlayer.vehicle then return end if gui.checkbox["Headlights"]:getSelected() then color.r, color.g, color.b = hsv2rgb(color.h, color.s, color.v) triggerServerEvent("server.Color", localPlayer, localPlayer, "Vehicle", {color.r, color.g, color.b, color.rr, color.rg, color.rb}) end if gui.checkbox["Headlights"]:getSelected() then triggerServerEvent("server.Color", localPlayer, localPlayer, "All", {color.r, color.g, color.b, color.rr, color.rg, color.rb}) end end end end) ------------------------------------------------------------------------------------------------------------------------------------ function hsv2rgb(h, s, v) local r, g, b local i = math.floor(h * 5) local f = h * 5 - i local p = v * (1 - s) local q = v * (1 - f * s) local t = v * (1 - (1 - f) * s) local switch = i % 5 if switch == 0 then r = v g = t b = p elseif switch == 1 then r = q g = v b = p elseif switch == 2 then r = p g = v b = t elseif switch == 3 then r = p g = q b = v elseif switch == 4 then r = t g = p b = v elseif switch == 5 then r = v g = p b = q end return math.floor(r*255), math.floor(g*255), math.floor(b*255) end function rgb2hsv(r, g, b) r, g, b = r/255, g/255, b/255 local max, min = math.max(r, g, b), math.min(r, g, b) local h, s local v = max local d = max - min s = max == 0 and 0 or d/max if max == min then h = 0 elseif max == r then h = (g - b) / d + (g < b and 6 or 0) elseif max == g then h = (b - r) / d + 2 elseif max == b then h = (r - g) / d + 4 end h = h/6 return h, s, v end 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