Jump to content

[Problem] Police light (Rendor villogo)


Aller

Recommended Posts


function toggleLightflash()
    local veh = getPedOccupiedVehicle(localPlayer);
    if (veh) then
    
        if not (getElementData(veh, "lightFlash:color")) then
            setElementData(veh, "lightFlash:color", (0, 0, 255), false);
        end
        
        local isLightFlashing = getElementData(veh, "lightFlash");
        if (isLightFlashing) then
            setVehicleOverrideLights(veh, 0);
            local lightTimer = getElementData(veh, "lightFlash:timer");
            killTimer(lightTimer);
            setElementData(veh, "lightFlash", false, false);
            setVehicleLightState(veh, 0, 0);
            setVehicleLightState(veh, 1, 0);
            setVehicleHeadLightColor(veh, 255, 255, 255);
        else
            setVehicleOverrideLights(veh, 2);
            setElementData(veh, "lightFlash:state", false, false);
            local lightFlashTimer = setTimer(function()
                local flashState = getElementData(veh, "lightFlash:state");
                local lightColor = getElementData(veh, "lightFlash:color");
                if (lightColor[1] == 255) then
                    lightColor[1], lightColor[2], lightColor[3] = 0, 0, 255;
                else
                    lightColor[1], lightColor[2], lightColor[3] = 255, 0, 0;
                end
                
                setVehicleHeadLightColor(veh, lightColor[1], lightColor[2], lightColor[3]);
                
                if (flashState) then
                    setVehicleLightState(veh, 0, 0);
                    setVehicleLightState(veh, 1, 1);
                else
                    setVehicleLightState(veh, 0, 1);
                    setVehicleLightState(veh, 1, 0);
                end
                
                setElementData(veh, "lightFlash:color", lightColor, false);
                setElementData(veh, "lightFlash:state", not flashState, false);
            end, 250, 0);
            setElementData(veh, "lightFlash:timer", lightFlashTimer, false);
            setElementData(veh, "lightFlash", true, false);
        end
    end
end
bindKey("l", "down", toggleLightflash);

Edited by Aller
  • Confused 1
Link to comment
  • Moderators

What is the problem, you don't write it down?

By the way, you are copied this code from a tutorial video. (link: https://youtu.be/tQBY8U3T-es?t=8485)

Then why do you need help if the solution is in that video?

 

[HUN]

Első probléma, hogy nem írtad le mit szeretnél. Honnan találjuk ki?

Második, hogy ezt a kódot nem te írtad, csupán lemásoltad. Akkor miért nem abban a videóban keresed a megoldást, ahonnan másoltad? (link: https://youtu.be/tQBY8U3T-es?t=8485)

Edited by stPatrick
Link to comment
  • 3 weeks later...
  • Moderators
55 minutes ago, Aller said:

Többször is át ellenőriztem de nekem nem jó.
3-szor írtam újra és úgy sem működik.
Nem tudom mi lehet a probléma.

Ez egy client oldali script, ott futtatod?

És a hatodik sorban van egy hiba, amit észrevettem ránézésre. Sima zárójelet raktál kapcsos helyett.

Javítás: setElementData(veh, "lightFlash:color", {0, 0, 255}, false);

Edited by stPatrick
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...