Jump to content

Fading problem

Dzsozi (h03)

Recommended Posts

Hello! I made a script that adds a little "bullet smoke" effect for the guns, I made it to fade away then remove the rendering. My only problem is that if I keep shooting then sometimes it's not visible, or it's just visible for a little time. How could I fix it? I used @Dealman's (Click) and the wiki's example and mixed it.

local fadingAlpha = 200;                                -- Set this to the value where you want it to start fading from. 
local fadingAlphaFrom = fadingAlpha; 
local fadingDuration = 250;                            -- Set this for how long you want it to go from fully visible to not visible (255 -> 0). Milliseconds. 
local fadingInterval = 50;                              -- Set this for how often it should detract the increments. 50 ms minimum. Less = Smoother 
local timesToRun = (fadingDuration/fadingInterval);     -- This is just to make the code below somewhat auto, so you don't have to change values everywhere. 
local fadeIncremental = (fadingAlphaFrom/timesToRun);   -- This is just to make the code below somewhat auto, so you don't have to change values everywhere. 
function OnPlayerFire(w,a,aC,hX,hY,hZ,hE) 
        local sx,sy,sz = getPedWeaponMuzzlePosition(source)-- get the WeaponMuzzlePosition of the Player who shot 
        Position = {sx,sy,sz,hX,hY,hZ} -- save it in a table so we can use it later in 'onClientRender'function 
        --removeEventHandler("onClientRender", root, onRender) 
        addEventHandler("onClientRender",root,onRender) -- add the onClientRender-Event to the function onRender 
            removeEventHandler("onClientRender", root, onRender) 
        end, fadingDuration, 1); 
    --end, 250, 0); 
function onRender() 
    if Position then -- check if there are Positions available 
        local startX,startY,startZ,endX,endY,endZ = unpack(Position)-- unpack the Position table 
        dxDrawLine3D( startX,startY,startZ,endX,endY,endZ,tocolor(150,150,150,fadingAlpha),0.75) -- draws the 3D line between start-Position and end-Position 
    end -- end of if 
function alphaHandler() 
    fadingAlpha = 200; 
        fadingAlpha = fadingAlpha-fadeIncremental 
    end, fadingInterval, timesToRun); 

Thank you in advance!

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