Polak0 Posted April 23, 2020 Share Posted April 23, 2020 (edited) Hello. I created emergency light system. Everyone can see lights, but it's bugging when you turn off all of these cuz it's blinking I don't know why. If I turn on "swiatla poscigowe" and turn it off, it's okey. The same thing is "swiatla ostrzegawcze". But if I turn on "swiatla poscigowe" and "swiatla ostrzegawcze" and turn it off it's bugging like that: local screenW, screenH = guiGetScreenSize() local sx, sy = guiGetScreenSize() function isMouseIn(psx,psy,pssx,pssy,abx,aby) if not isCursorShowing() then return end cx,cy=getCursorPosition() cx,cy=cx*sx,cy*sy if cx >= psx and cx <= psx+pssx and cy >= psy and cy <= psy+pssy then return true,cx,cy else return false end end shader = dxCreateShader("i/shader.fx") -- Blinkers local animShads = {} p_swiatla={} p_swiatla1={} timer={} timer1={} timer2={} timer3={} timer4={} timer5={} zapalone_lg = dxCreateTexture("i/swiatla_gora_zapalone_lewa.bmp") zapalone_pg = dxCreateTexture("i/swiatla_gora_zapalone_prawa.bmp") --------------------------------- ---////// GUI local gui = false function gui_swiatla() local veh = getPedOccupiedVehicle( localPlayer ) local id = getElementModel ( veh ) local wariant = getVehicleVariant(veh) if not veh then return end if getElementModel(veh)==582 then-- NEWSVAN dxDrawImage(screenW * 0.8100, screenH * 0.3500, screenW * 0.1500, screenH * 0.2000, "i/tlo.png", 0, 0, 0, tocolor(255, 255, 255), false) if getElementData(veh, "bok_lewy") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła górne\nna lewym boku", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0720, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła górne\nna lewym boku", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0720, tocolor(255, 255, 255, 255), false) end if getElementData(veh, "bok_prawy") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła górne\nna prawym boku", screenW * 0.8200, screenH * 0.4550, screenW * 0.1300, screenH * 0.0720, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła górne\nna prawym boku", screenW * 0.8200, screenH * 0.4550, screenW * 0.1300, screenH * 0.0720, tocolor(255, 255, 255, 255), false) end end if getElementModel(veh)==599 or getElementModel(veh) ==596 then --POLICE RANCHER I LS POLICE dxDrawImage(screenW * 0.8100, screenH * 0.3500, screenW * 0.1500, screenH * 0.1500, "i/tlo.png", 0, 0, 0, tocolor(255, 255, 255), false) if getElementData(veh, "poscigowe") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła pościgowe", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła pościgowe", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end if getElementData(veh, "ostrzegawcze") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end end if getElementModel(veh)==416 then -- AMBULANS dxDrawImage(screenW * 0.8100, screenH * 0.3500, screenW * 0.1500, screenH * 0.1500, "i/tlo.png", 0, 0, 0, tocolor(255, 255, 255), false) if getElementData(veh, "sygnalki1") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end if getElementData(veh, "ostrzegawcze") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end end if getElementModel(veh)==427 then -- Enforcer dxDrawImage(screenW * 0.8100, screenH * 0.3500, screenW * 0.1500, screenH * 0.1500, "i/tlo.png", 0, 0, 0, tocolor(255, 255, 255), false) if getElementData(veh, "sygnalki1") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end if getElementData(veh, "ostrzegawcze") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end end if getElementModel(veh)==426 and getElementData(veh, "veh:sapd", true) then -- Premier dxDrawImage(screenW * 0.8100, screenH * 0.3500, screenW * 0.1500, screenH * 0.1500, "i/tlo.png", 0, 0, 0, tocolor(255, 255, 255), false) if getElementData(veh, "poscigowe") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła", screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end if getElementData(veh, "ostrzegawcze") == true then exports["NS_dxGui"]:createCustomButton("Wyłącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) else exports["NS_dxGui"]:createCustomButton("Włącz światła ostrzegawcze", screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420, tocolor(255, 255, 255, 255), false) end end end --////// ODPALANIE GUI bindKey( "lalt", "down", function() local veh = getPedOccupiedVehicle( localPlayer ) if not veh then return end local id = getElementModel ( veh ) if getElementModel(veh)==426 and getElementData(veh, "veh:sapd", true) or getElementModel(veh)==427 or getElementModel(veh)==416 or getElementModel(veh)==599 or getElementModel(veh)==596 or getElementModel(veh)==582 then if gui then gui = false removeEventHandler("onClientRender", root, gui_swiatla) showCursor(false) else gui = true addEventHandler("onClientRender", root, gui_swiatla) showCursor(true, false) end end end) function updateShaders(veh) local state1 = getElementData(veh,"signal1") --local state2 = getElementData(veh,"signal2") -- LEWY BOK NEWSVAN if state1 == 0 then engineRemoveShaderFromWorldTexture( shader, "swiatla_gora_lewe", veh ) elseif state1 == 1 then engineApplyShaderToWorldTexture( shader,"swiatla_gora_lewe",veh ) dxSetShaderValue (shader, "gTexture", zapalone_lg, veh) elseif state1 == 2 then -- prawy bok newsvan engineRemoveShaderFromWorldTexture( shader, "swiatla_gora_prawe", veh ) elseif state1 == 3 then engineApplyShaderToWorldTexture( shader,"swiatla_gora_prawe",veh ) dxSetShaderValue (shader, "gTexture", zapalone_pg, veh) -- wylacz poscigowe elseif state1==4 then if isTimer(timer[veh]) then killTimer(timer[veh]) end if isTimer(timer2[veh]) then killTimer(timer2[veh]) end engineRemoveShaderFromWorldTexture(shader, "zgaszony_niebieski", veh) engineRemoveShaderFromWorldTexture(shader, "zgaszony_czerwony", veh) setElementData(veh, "poscigowe", false) p_swiatla[veh]=0 elseif state1==5 then -- wlacz poscgiowe setElementData(veh, "poscigowe", true) timer[veh] = setTimer( function() -- Niebieskie if(p_swiatla[veh] == 0) or (p_swiatla[veh] == nil) then p_swiatla[veh] = 1 engineApplyShaderToWorldTexture(shader, "zgaszony_niebieski", veh) dxSetShaderValue (shader, "gTexture", zapalone_pg, veh) else p_swiatla[veh]=0 engineRemoveShaderFromWorldTexture(shader, "zgaszony_niebieski", veh) end end, 150, 0) timer2[veh] = setTimer( function() -- Czerwone if(p_swiatla[veh] == 0) or (p_swiatla[veh] == nil) then p_swiatla[veh] = 1 engineApplyShaderToWorldTexture(shader, "zgaszony_czerwony", veh) dxSetShaderValue (shader, "gTexture", zapalone_pg, veh) else p_swiatla[veh]=0 engineRemoveShaderFromWorldTexture(shader, "zgaszony_czerwony", veh) end end, 150/2, 0) elseif state1==6 then if isTimer(timer3[veh]) then killTimer(timer3[veh]) end if isTimer(timer4[veh]) then killTimer(timer4[veh]) end if isTimer(timer5[veh]) then killTimer(timer5[veh]) end engineRemoveShaderFromWorldTexture(shader, "zgaszony_pomaranczowy", veh) engineRemoveShaderFromWorldTexture(shader, "zgaszony_pomaranczowy1", veh) engineRemoveShaderFromWorldTexture(shader, "zgaszone_bialy", veh) setElementData(veh, "ostrzegawcze", false) p_swiatla1[veh]=0 elseif state1==7 then setElementData(veh, "ostrzegawcze", true) timer3[veh]= setTimer( function() -- pomaranczowe if(p_swiatla1[veh]==0) then p_swiatla1[veh] = 2 engineApplyShaderToWorldTexture(shader, "zgaszony_pomaranczowy", veh) dxSetShaderValue (shader, "gTexture", zapalone_pg, veh) else p_swiatla1[veh]=0 engineRemoveShaderFromWorldTexture(shader, "zgaszony_pomaranczowy", veh) end end, 275, 0) timer4[veh] = setTimer( function() -- biale if(p_swiatla1[veh]==0) then p_swiatla1[veh] = 2 engineApplyShaderToWorldTexture(shader, "zgaszone_bialy", veh) dxSetShaderValue (shader, "gTexture", zapalone_pg, veh) else p_swiatla1[veh]=0 engineRemoveShaderFromWorldTexture(shader, "zgaszone_bialy", veh) end end, 275/2, 0) timer5[veh] = setTimer( function() -- Czerwone if(p_swiatla1[veh] == 0) or (p_swiatla[veh] == nil) then p_swiatla1[veh] = 2 engineApplyShaderToWorldTexture(shader, "zgaszony_pomaranczowy1", veh) dxSetShaderValue (shader, "gTexture", zapalone_pg, veh) else p_swiatla1[veh]=0 engineRemoveShaderFromWorldTexture(shader, "zgaszony_pomaranczowy1", veh) end end, 150/2, 0) end end ------------------------------------------------------------- local last = 0 function updateMultipliers() local cur = getTickCount()-last last = getTickCount() for k,v in pairs(animShads) do v[2] = v[2] + cur/1000 dxSetShaderValue(v[1],"gMultiplier",v[2]) if v[2] >= 1 then destroyElement(v[1]) setVehicleOverrideLights(k, 2 ) setVehicleHeadLightColor(k,0,0,0) animShads[k] = nil --setVehicleHeadLightColor(veh,0,0,0) end end end addEventHandler("onClientRender",root,updateMultipliers) --/////// WŁĄCZANIE ŚWIATEŁ addEventHandler("onClientClick", root, function(b, s) local veh = getPedOccupiedVehicle( localPlayer ) if not veh then return end if b ~= "state" and s ~= "down" then return end local cur = getElementData(veh,"signal1") if gui then if isMouseIn(screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0720) then if getVehicleController(veh) ~= localPlayer then return end if cur == 1 then setElementData(veh,"signal1",0) setElementData(veh, "bok_lewy", false) else setElementData(veh,"signal1",1) setElementData(veh, "bok_lewy", true) end end if isMouseIn(screenW * 0.8200, screenH * 0.4550, screenW * 0.1300, screenH * 0.0720) then if getVehicleController(veh) ~= localPlayer then return end if cur == 3 then setElementData(veh,"signal1",2) setElementData(veh, "bok_prawy", false) else setElementData(veh,"signal1",3) setElementData(veh, "bok_prawy", true) end end -- POLICJA if isMouseIn(screenW * 0.8200, screenH * 0.3750, screenW * 0.1300, screenH * 0.0420) then -- POSCIGOWE if cur == 5 then setElementData(veh,"signal1",4) setElementData(veh, "poscigowe", false) else setElementData(veh,"signal1",5) setElementData(veh, "poscigowe", true) end end if isMouseIn(screenW * 0.8200, screenH * 0.4350, screenW * 0.1300, screenH * 0.0420) then -- OSTRZEGAWCZE if cur == 7 then setElementData(veh,"signal1",6) else setElementData(veh,"signal1",7) end end end end) addEventHandler ( "onClientElementDataChange", getRootElement(), function ( dataName ) if getElementType ( source ) == "vehicle" then if dataName == "signal1" then updateShaders(source) elseif dataName == "lights" then updateLights(source) end end end) I think it's something wrong with "updateShaders", but I don't know what. Edited April 23, 2020 by Polak0 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