Jump to content

[Solved] Lights [Again]


Absence2

Recommended Posts

For now I only sell MTA scripts, I haven't got the time yet to learn PHP, HTML and so on.

P.S: We should stop doing off-topic.

Hehe,

I just have a small question, if I type something in in edit fields, is it possible to "auto-preview" the vehicle light's color?

Link to comment
You can use this event handler: onClientGUIChanged, it'll detect when the selected GUI edit field or memo text changes.

You can set the head lights color client side, as it would be a preview.

like this? ( This will also end up as a preview? right, just making sure).

redEdit = guiCreateEdit(110,54,142,24,"",false,lights) 
addEventHandler("onClientGUIChanged", redEdit, function(red) 
  

Link to comment
addEventHandler("onClientGUIChanged", root, 
    function () 
        if (source == redEdit or source == greenEdit or source == blueEdit) then 
            local red = guiGetText ( redEdit ) 
            local green = guiGetText ( greenEdit ) 
            local blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue) ) then 
                local veh = getPedOccupiedVehicle ( localPlayer ) 
                if (veh) then 
                    setVehicleHeadLightColor(veh, red, green, blue) 
                end 
            end 
        end 
    end 
) 

Link to comment
addEventHandler("onClientGUIChanged", root, 
    function () 
        if (source == redEdit or source == greenEdit or source == blueEdit) then 
            local red = guiGetText ( redEdit ) 
            local green = guiGetText ( greenEdit ) 
            local blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue) ) then 
                local veh = getPedOccupiedVehicle ( localPlayer ) 
                if (veh) then 
                    setVehicleHeadLightColor(veh, red, green, blue) 
                end 
            end 
        end 
    end 
) 

Well I was way off then, well thanks, I just have a small problem, if you click the cancelPurchaseButton, the event stays and you'll have your "Preview" lights until you /reconnect

How do I cancel the event when you click on "Cancel"?

        elseif ( source == cancelPurchaseButton ) then 
            guiSetVisible ( lights, false ) 
            showCursor ( false ) 

like this

Link to comment

Kenix, it's this:

                    setVehicleHeadLightColor(veh, red, green, blue) 

not the button

they don't cancel / disappear or whatever, they stay when I click "Cancel"

this is the full code:

lights = guiCreateWindow(259,238,290,202,"Vehicle Headlight - $2500",false) 
guiSetVisible(lights, false) 
redEdit = guiCreateEdit(110,54,100,21,"255",false,lights) 
guiEditSetMaxLength ( redEdit, 3 ) 
greenEdit = guiCreateEdit(110,87,100,21,"255",false,lights) 
guiEditSetMaxLength ( greenEdit, 3 ) 
blueEdit = guiCreateEdit(110,125,100,21,"255",false,lights) 
guiEditSetMaxLength ( blueEdit, 3 ) 
redtx = guiCreateLabel(39,58,64,19,"Red, 0-255:",false,lights) 
greentx = guiCreateLabel(24,93,75,19,"Green, 0-255:",false,lights) 
bluetx = guiCreateLabel(32,129,67,17,"Blue, 0-255:",false,lights) 
buyVLightsButton = guiCreateButton(97,176,70,17,"Purchase",false,lights) 
cancelPurchaseButton = guiCreateButton(166,176,74,17,"Cancel",false,lights) 
  
addEventHandler("onClientGUIChanged", root, 
    function () 
        if (source == redEdit or source == greenEdit or source == blueEdit) then 
            local red = guiGetText ( redEdit ) 
            local green = guiGetText ( greenEdit ) 
            local blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue) ) then 
                local veh = getPedOccupiedVehicle ( localPlayer ) 
                if (veh) then 
                    setVehicleHeadLightColor(veh, red, green, blue) 
            end 
        end 
    end 
end 
    ) 
  
addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if (source == bMechanicNine ) then 
            guiSetInputEnabled(true) 
            guiSetVisible(lights, true) 
            guiSetVisible(wMechanic, false) 
        elseif ( source == buyVLightsButton ) then 
            local red = guiGetText ( redEdit ) 
            local green = guiGetText ( greenEdit ) 
            local blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue) ) then 
                if ( isPedInVehicle ( localPlayer ) ) then 
                    local veh = getPedOccupiedVehicle ( localPlayer ) 
                    triggerServerEvent("onHeadLightsChange",localPlayer,veh,red,green,blue) 
                                guiSetInputEnabled(false) 
                        guiSetVisible ( lights, false ) 
                        guiSetVisible(wMechanic, true) 
                else 
                    outputChatBox ( 'You are not in a vehicle!' ) 
                end 
            end           
       elseif ( source == cancelPurchaseButton ) then 
                guiSetInputEnabled(false) 
            guiSetVisible ( lights, false ) 
            showCursor ( false ) 
            guiSetVisible(wMechanic, true) 
        end 
    end 
) 

I have to disable thissomehow when you click on the cancelPurchaseButton:

                    setVehicleHeadLightColor(veh, red, green, blue) 

somehow when you click on the cancelPurchaseButton, but don't know how.

also, this didn't work:

       elseif ( source == cancelPurchaseButton ) then 
            guiSetVisible ( lights, false ) 
            showCursor ( false ) 
            cancelEvent() 

Link to comment

You want to save the original lights and set them when cancel? if so, try this:

local oRed, oGreen, oBlue = 255, 255, 255 
  
lights = guiCreateWindow(259,238,290,202,"Vehicle Headlight - $2500",false) 
guiSetVisible(lights, false) 
redEdit = guiCreateEdit(110,54,100,21,"255",false,lights) 
guiEditSetMaxLength ( redEdit, 3 ) 
greenEdit = guiCreateEdit(110,87,100,21,"255",false,lights) 
guiEditSetMaxLength ( greenEdit, 3 ) 
blueEdit = guiCreateEdit(110,125,100,21,"255",false,lights) 
guiEditSetMaxLength ( blueEdit, 3 ) 
redtx = guiCreateLabel(39,58,64,19,"Red, 0-255:",false,lights) 
greentx = guiCreateLabel(24,93,75,19,"Green, 0-255:",false,lights) 
bluetx = guiCreateLabel(32,129,67,17,"Blue, 0-255:",false,lights) 
buyVLightsButton = guiCreateButton(97,176,70,17,"Purchase",false,lights) 
cancelPurchaseButton = guiCreateButton(166,176,74,17,"Cancel",false,lights) 
  
addEventHandler("onClientGUIChanged", root, 
    function () 
        if (source == redEdit or source == greenEdit or source == blueEdit) then 
            local red = guiGetText ( redEdit ) 
            local green = guiGetText ( greenEdit ) 
            local blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue) ) then 
                local veh = getPedOccupiedVehicle ( localPlayer ) 
                if (veh) then 
                    setVehicleHeadLightColor(veh, red, green, blue) 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if (source == bMechanicNine ) then 
            guiSetInputEnabled(true) 
            guiSetVisible(lights, true) 
            guiSetVisible(wMechanic, false) 
            local veh = getPedOccupiedVehicle ( localPlayer ) 
            if (veh) then 
                oRed, oGreen, oBlue = getVehicleHeadLightColor(veh) 
            end 
        elseif ( source == buyVLightsButton ) then 
            local red = guiGetText ( redEdit ) 
            local green = guiGetText ( greenEdit ) 
            local blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue) ) then 
                if ( isPedInVehicle ( localPlayer ) ) then 
                    local veh = getPedOccupiedVehicle ( localPlayer ) 
                    triggerServerEvent("onHeadLightsChange",localPlayer,veh,red,green,blue) 
                    guiSetInputEnabled(false) 
                    guiSetVisible ( lights, false ) 
                    guiSetVisible(wMechanic, true) 
                else 
                    outputChatBox ( 'You are not in a vehicle!' ) 
                end 
            end           
       elseif ( source == cancelPurchaseButton ) then 
            guiSetInputEnabled(false) 
            guiSetVisible ( lights, false ) 
            showCursor ( false ) 
            guiSetVisible(wMechanic, true) 
            local veh = getPedOccupiedVehicle ( localPlayer ) 
            if (veh) then 
                setVehicleHeadLightColor(veh, oRed, oGreen, oBlue) 
            end          
        end 
    end 
) 

Link to comment
lights = guiCreateWindow(259,238,290,202,"Vehicle Headlight - $2500",false) 
guiSetVisible(lights, false) 
redEdit = guiCreateEdit(110,54,100,21,"255",false,lights) 
guiEditSetMaxLength ( redEdit, 3 ) 
greenEdit = guiCreateEdit(110,87,100,21,"255",false,lights) 
guiEditSetMaxLength ( greenEdit, 3 ) 
blueEdit = guiCreateEdit(110,125,100,21,"255",false,lights) 
guiEditSetMaxLength ( blueEdit, 3 ) 
redtx = guiCreateLabel(39,58,64,19,"Red, 0-255:",false,lights) 
greentx = guiCreateLabel(24,93,75,19,"Green, 0-255:",false,lights) 
bluetx = guiCreateLabel(32,129,67,17,"Blue, 0-255:",false,lights) 
buyVLightsButton = guiCreateButton(97,176,70,17,"Purchase",false,lights) 
cancelPurchaseButton = guiCreateButton(166,176,74,17,"Cancel",false,lights) 
  
  
local veh = getPedOccupiedVehicle ( localPlayer ) 
local r, g, b = getVehicleHeadLightColor(veh) 
local changeColor = true 
addEventHandler("onClientGUIChanged", root, 
    function () 
    local red,green,blue 
        if (source == redEdit or source == greenEdit or source == blueEdit and changeColor == true) then 
            red = guiGetText ( redEdit ) 
            green = guiGetText ( greenEdit ) 
            blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue)) then 
            if (veh and changeColor == true) then 
                    setVehicleHeadLightColor(veh, red, green, blue) 
        end 
    end 
    end 
end 
    ) 
  
addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if (source == bMechanicNine ) then 
        r, g, b = getVehicleHeadLightColor(veh) 
            guiSetVisible(lights, true) 
            guiSetVisible(wMechanic, false) 
            guiSetInputEnabled(true) 
            changeColor = true 
        elseif ( source == buyVLightsButton ) then 
            local red = guiGetText ( redEdit ) 
            local green = guiGetText ( greenEdit ) 
            local blue = guiGetText ( blueEdit ) 
            if ( red ~= "" and green ~= "" and blue ~= "" and tonumber(red) and tonumber(green) and tonumber(blue) ) then 
                if ( isPedInVehicle ( localPlayer ) ) then 
                    local veh = getPedOccupiedVehicle ( localPlayer ) 
                    triggerServerEvent("onHeadLightsChange",localPlayer,veh,red,green,blue) 
                    guiSetInputEnabled(false) 
                        guiSetVisible ( lights, false ) 
                        guiSetVisible(wMechanic, true) 
                else 
                    outputChatBox ( 'You are not in a vehicle!' ) 
                end 
            end           
       elseif ( source == cancelPurchaseButton ) then 
            setVehicleHeadLightColor(veh, r, g, b) 
            changeColor = false 
            guiSetInputEnabled(false) 
            guiSetVisible ( lights, false ) 
            showCursor ( false ) 
            guiSetVisible(wMechanic, true) 
        end 
    end 
) 

I came up with this but had a small error, I'll try ours.

EDIT: It seems to be working :) Everything is fixed by the looks of it, thanks everyone, mostly Solidsnake though :lol:

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