Jump to content

[HELP] Image opening 100 times


..:D&G:..

Recommended Posts

Posted

Hello guys, I made a speedometer that glows when you turn on the lights, but when I turn on the lights, 1000 images open on top of each other.

  
function drawFuelLights() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if (vehicle) then 
        if ( getVehicleOverrideLights ( vehicle ) == 2 ) then 
            if not (thDiscNight) then theDiscNight = guiCreateStaticImage( discX, discY, imageWidth, imageHeight, "fuelmeter/fueldisc-night.png", false ) end 
        else 
            if (theDiscNight) then 
                guiSetVisible(theDiscNight, false) 
            end 
        end 
    end 
end 
  
function onVehicleEnter(thePlayer, seat) 
    if (thePlayer==getLocalPlayer()) then 
        if (seat<2) then 
            if seat == 0 then 
                addEventHandler("onClientRender", getRootElement(), drawFuelLights) 
            end 
        end 
    end 
end 
addEventHandler("onClientVehicleEnter", getRootElement(), onVehicleEnter) 
  
  
function onVehicleExit(thePlayer, seat) 
    if (thePlayer==getLocalPlayer()) then 
        if (seat<2) then 
            if seat == 0 then 
                removeEventHandler("onClientRender", getRootElement(), drawFuelLights) 
            end 
        end 
    end 
end 
addEventHandler("onClientVehicleExit", getRootElement(), onVehicleExit) 

Any ideas?

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

This is what I've done but it still doesnt' show up.

function drawFuelLights() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if (vehicle) then 
        if ( getVehicleOverrideLights ( vehicle ) == 2 ) then 
            theDiscNight = dxDrawImage( discX, discY, imageWidth, imageHeight, "fuelmeter/fueldisc-night.png" ) 
        else 
            if (theDiscNight) then 
                removeEventHandler("onClientRender", getRootElement(), drawFuelLights) 
            end 
        end 
    end 
end 

I am soo damn angry cuz I been trying to do this thing for 2 hours now, and can't get it to work! When I used guiCreateStatic image, it worked but created lots of images on top of each other, now, they don't work at all!

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted
This is what I've done but it still doesnt' show up.
function drawFuelLights() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if (vehicle) then 
        if ( getVehicleOverrideLights ( vehicle ) == 2 ) then 
            theDiscNight = dxDrawImage( discX, discY, imageWidth, imageHeight, "fuelmeter/fueldisc-night.png" ) 
        else 
            if (theDiscNight) then 
                removeEventHandler("onClientRender", getRootElement(), drawFuelLights) 
            end 
        end 
    end 
end 

I am soo damn angry cuz I been trying to do this thing for 2 hours now, and can't get it to work! When I used guiCreateStatic image, it worked but created lots of images on top of each other, now, they don't work at all!

what is exactly your problem? because it works with the code you just did

Inactivo.

Posted

I fixed it by using this code:

function drawDiscsNight() 
    guiSetVisible(discnight, true) 
    guiSetVisible(theDiscNight, true) 
    guiSetProperty( theDiscNight, "AlwaysOnTop", "True" ) 
end 
  
function notDrawDiscsNight() 
    guiSetVisible(discnight, false) 
    guiSetVisible(theDiscNight, false) 
end 
  
function drawLights() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if (vehicle) then 
        if ( getVehicleOverrideLights ( vehicle ) == 2 ) then 
            addEventHandler("onClientRender", getRootElement(), drawDiscsNight) 
            removeEventHandler("onClientRender", getRootElement(), notDrawDiscsNight) 
        else 
            if ( getVehicleOverrideLights ( vehicle ) == 1 ) then 
                removeEventHandler("onClientRender", getRootElement(), drawDiscsNight) 
                addEventHandler("onClientRender", getRootElement(), notDrawDiscsNight) 
            end 
        end 
    end 
end 

But I keep getting an error saying that the events are already handled in another function, but they ain't (I think...)

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

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